Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openj9
Path: blob/master/test/functional/CacheManagement/src/tests/sharedclasses/options/TestDestroyCache.java
6005 views
1
/*******************************************************************************
2
* Copyright (c) 2010, 2019 IBM Corp. and others
3
*
4
* This program and the accompanying materials are made available under
5
* the terms of the Eclipse Public License 2.0 which accompanies this
6
* distribution and is available at https://www.eclipse.org/legal/epl-2.0/
7
* or the Apache License, Version 2.0 which accompanies this distribution and
8
* is available at https://www.apache.org/licenses/LICENSE-2.0.
9
*
10
* This Source Code may also be made available under the following
11
* Secondary Licenses when the conditions for such availability set
12
* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU
13
* General Public License, version 2 with the GNU Classpath
14
* Exception [1] and GNU General Public License, version 2 with the
15
* OpenJDK Assembly Exception [2].
16
*
17
* [1] https://www.gnu.org/software/classpath/license.html
18
* [2] http://openjdk.java.net/legal/assembly-exception.html
19
*
20
* SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 OR LicenseRef-GPL-2.0 WITH Assembly-exception
21
*******************************************************************************/
22
23
package tests.sharedclasses.options;
24
25
import tests.sharedclasses.*;
26
import java.io.*;
27
28
/*
29
* Check various scenarios handled in j9shr_destroy_cache()
30
* with respect to deleting old and current generation cache.
31
* For details see JAZZ design 37044.
32
*/
33
public class TestDestroyCache extends TestUtils {
34
String cacheName = "testcache";
35
String destroyPersistentCache, destroyNonPersistentCache;
36
String infiniteLoopOutput = "Running infinite loop";
37
38
public static void main(String args[]) {
39
TestDestroyCache tdc = new TestDestroyCache();
40
tdc.destroyPersistentCache = getCommand(DestroyPersistentCacheCommand, tdc.cacheName);
41
tdc.destroyNonPersistentCache = getCommand(DestroyNonPersistentCacheCommand, tdc.cacheName);
42
tdc.testCase1();
43
tdc.testCase2();
44
tdc.testCase3();
45
tdc.testCase4();
46
tdc.testCase5();
47
tdc.testCase6();
48
}
49
50
private void testCase1() {
51
String expectedErrorMessages[] = new String[] {
52
"JVMSHRC428I" /* Removed older generation of shared class cache "<cache name>" */
53
};
54
55
runDestroyAllCaches();
56
57
/* When only older generation cache exists and is not in use */
58
if (isMVS() == false) {
59
runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");
60
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
61
}
62
63
if (realtimeTestsSelected() == false) {
64
runSimpleJavaProgramWithNonPersistentCache(cacheName, "createOldGen");
65
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
66
}
67
68
runDestroyAllCaches();
69
}
70
71
private void testCase2() {
72
Process p1 = null;
73
String expectedErrorMessages[];
74
75
runDestroyAllCaches();
76
77
/* When only current generation cache exists and is in use */
78
if (isMVS() == false) {
79
try {
80
if (isWindows()) {
81
expectedErrorMessages = new String[] {
82
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
83
};
84
} else {
85
/* Linux, AIX allow to destroy an active persistent cache */
86
expectedErrorMessages = new String[] {
87
"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */
88
};
89
}
90
if (realtimeTestsSelected()) {
91
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
92
runSimpleJavaProgramWithPersistentCache(cacheName);
93
}
94
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);
95
p1 = RunCommand.getLastProcess();
96
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
97
} finally {
98
if (null == p1) {
99
p1 = RunCommand.getLastProcess();
100
}
101
if (null != p1) {
102
p1.destroy();
103
try {
104
p1.waitFor();
105
} catch (java.lang.InterruptedException e) {
106
e.printStackTrace();
107
}
108
}
109
if (realtimeTestsSelected()) {
110
destroyPersistentCache(cacheName);
111
}
112
}
113
}
114
115
if (realtimeTestsSelected() == false) {
116
try {
117
expectedErrorMessages = new String[] {
118
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
119
};
120
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);
121
p1 = RunCommand.getLastProcess();
122
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
123
} finally {
124
if (null == p1) {
125
p1 = RunCommand.getLastProcess();
126
}
127
if (null != p1) {
128
p1.destroy();
129
try {
130
p1.waitFor();
131
} catch (java.lang.InterruptedException e) {
132
e.printStackTrace();
133
}
134
}
135
}
136
}
137
138
runDestroyAllCaches();
139
}
140
141
private void testCase3() {
142
Process p1 = null;
143
String expectedErrorMessages[];
144
145
runDestroyAllCaches();
146
147
/* When only older generation cache exists and is in use */
148
if (isMVS() == false) {
149
try {
150
if (isWindows()) {
151
expectedErrorMessages = new String[] {
152
"JVMSHRC429I" /* Failed to remove older generation of shared class cache "<cache name>" */
153
};
154
} else {
155
/* Linux, AIX allow to destroy an active persistent cache */
156
expectedErrorMessages = new String[] {
157
"JVMSHRC428I" /* Removed older generation of shared class cache "<cache name>" */
158
};
159
}
160
if (realtimeTestsSelected()) {
161
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
162
runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");
163
}
164
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
165
p1 = RunCommand.getLastProcess();
166
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
167
} finally {
168
if (null == p1) {
169
p1 = RunCommand.getLastProcess();
170
}
171
if (null != p1) {
172
p1.destroy();
173
try {
174
p1.waitFor();
175
} catch (java.lang.InterruptedException e) {
176
e.printStackTrace();
177
}
178
}
179
if (realtimeTestsSelected()) {
180
destroyPersistentCache(cacheName);
181
}
182
}
183
}
184
185
if (realtimeTestsSelected() == false) {
186
try {
187
expectedErrorMessages = new String[] {
188
"JVMSHRC429I" /* Failed to remove older generation of shared class cache "<cache name>" */
189
};
190
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
191
p1 = RunCommand.getLastProcess();
192
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
193
} finally {
194
if (null == p1) {
195
p1 = RunCommand.getLastProcess();
196
}
197
if (null != p1) {
198
p1.destroy();
199
try {
200
p1.waitFor();
201
} catch (java.lang.InterruptedException e) {
202
e.printStackTrace();
203
}
204
}
205
}
206
}
207
208
runDestroyAllCaches();
209
}
210
211
private void testCase4() {
212
Process p1 = null;
213
String expectedErrorMessages[];
214
215
runDestroyAllCaches();
216
217
/* When older generation cache is not in use but current generation cache is in use */
218
if (isMVS() == false) {
219
try {
220
if (isWindows()) {
221
expectedErrorMessages = new String[] {
222
"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */
223
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
224
};
225
} else {
226
/* Linux, AIX allow to destroy an active persistent cache */
227
expectedErrorMessages = new String[] {
228
"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */
229
"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */
230
};
231
}
232
runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");
233
if (realtimeTestsSelected()) {
234
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
235
runSimpleJavaProgramWithPersistentCache(cacheName);
236
}
237
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);
238
p1 = RunCommand.getLastProcess();
239
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
240
} finally {
241
if (null == p1) {
242
p1 = RunCommand.getLastProcess();
243
}
244
if (null != p1) {
245
p1.destroy();
246
try {
247
p1.waitFor();
248
} catch (java.lang.InterruptedException e) {
249
e.printStackTrace();
250
}
251
}
252
if (realtimeTestsSelected()) {
253
destroyPersistentCache(cacheName);
254
}
255
}
256
}
257
258
if (realtimeTestsSelected() == false) {
259
try {
260
expectedErrorMessages = new String[] {
261
"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */
262
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
263
};
264
runSimpleJavaProgramWithNonPersistentCache(cacheName, "createOldGen");
265
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);
266
p1 = RunCommand.getLastProcess();
267
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
268
} finally {
269
if (null == p1) {
270
p1 = RunCommand.getLastProcess();
271
}
272
if (null != p1) {
273
p1.destroy();
274
try {
275
p1.waitFor();
276
} catch (java.lang.InterruptedException e) {
277
e.printStackTrace();
278
}
279
}
280
}
281
}
282
283
runDestroyAllCaches();
284
}
285
286
private void testCase5() {
287
Process p1 = null;
288
String expectedErrorMessages[];
289
290
runDestroyAllCaches();
291
292
/* When older generation is in use and current generation cache is not in use */
293
if (isMVS() == false) {
294
try {
295
if (isWindows()) {
296
expectedErrorMessages = new String[] {
297
"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */
298
"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */
299
};
300
} else {
301
/* Linux, AIX allow to destroy an active persistent cache */
302
expectedErrorMessages = new String[] {
303
"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */
304
"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */
305
};
306
}
307
if (realtimeTestsSelected()) {
308
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
309
runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");
310
}
311
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
312
p1 = RunCommand.getLastProcess();
313
runSimpleJavaProgramWithPersistentCache(cacheName);
314
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
315
} finally {
316
if (null == p1) {
317
p1 = RunCommand.getLastProcess();
318
}
319
if (null != p1) {
320
p1.destroy();
321
try {
322
p1.waitFor();
323
} catch (java.lang.InterruptedException e) {
324
e.printStackTrace();
325
}
326
}
327
if (realtimeTestsSelected()) {
328
destroyPersistentCache(cacheName);
329
}
330
}
331
}
332
333
if (realtimeTestsSelected() == false) {
334
try {
335
expectedErrorMessages = new String[] {
336
"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */
337
"is destroyed" /* Shared cache "<cache name>" is destroyed */
338
};
339
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
340
p1 = RunCommand.getLastProcess();
341
runSimpleJavaProgramWithNonPersistentCache(cacheName);
342
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
343
} finally {
344
if (null == p1) {
345
p1 = RunCommand.getLastProcess();
346
}
347
if (null != p1) {
348
p1.destroy();
349
try {
350
p1.waitFor();
351
} catch (java.lang.InterruptedException e) {
352
e.printStackTrace();
353
}
354
}
355
}
356
}
357
358
runDestroyAllCaches();
359
}
360
361
private void testCase6() {
362
Process p1 = null;
363
Process p2 = null;
364
String expectedErrorMessages[];
365
366
runDestroyAllCaches();
367
368
/* When both older generation cache and current generation cache are in use */
369
if (isMVS() == false) {
370
try {
371
if (isWindows()) {
372
expectedErrorMessages = new String[] {
373
"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */
374
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
375
};
376
} else {
377
/* Linux, AIX allow to destroy an active persistent cache */
378
expectedErrorMessages = new String[] {
379
"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */
380
"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */
381
};
382
}
383
if (realtimeTestsSelected()) {
384
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
385
runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");
386
}
387
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
388
p1 = RunCommand.getLastProcess();
389
if (realtimeTestsSelected()) {
390
/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */
391
runSimpleJavaProgramWithPersistentCache(cacheName);
392
}
393
runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);
394
p2 = RunCommand.getLastProcess();
395
RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);
396
} finally {
397
if (null == p1) {
398
p1 = RunCommand.getLastProcess();
399
}
400
if (null != p1) {
401
p1.destroy();
402
try {
403
p1.waitFor();
404
} catch (java.lang.InterruptedException e) {
405
e.printStackTrace();
406
}
407
}
408
if (null == p2) {
409
p2 = RunCommand.getLastProcess();
410
}
411
if (null != p2) {
412
p2.destroy();
413
try {
414
p2.waitFor();
415
} catch (java.lang.InterruptedException e) {
416
e.printStackTrace();
417
}
418
}
419
if (realtimeTestsSelected()) {
420
destroyPersistentCache(cacheName);
421
}
422
}
423
}
424
425
if (realtimeTestsSelected() == false) {
426
try {
427
expectedErrorMessages = new String[] {
428
"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */
429
"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */
430
};
431
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);
432
p1 = RunCommand.getLastProcess();
433
runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);
434
p2 = RunCommand.getLastProcess();
435
RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);
436
} finally {
437
if (null == p1) {
438
p1 = RunCommand.getLastProcess();
439
}
440
if (null != p1) {
441
p1.destroy();
442
try {
443
p1.waitFor();
444
} catch (java.lang.InterruptedException e) {
445
e.printStackTrace();
446
}
447
}
448
if (null == p2) {
449
p2 = RunCommand.getLastProcess();
450
}
451
if (null != p2) {
452
p2.destroy();
453
try {
454
p2.waitFor();
455
} catch (java.lang.InterruptedException e) {
456
e.printStackTrace();
457
}
458
}
459
}
460
}
461
462
runDestroyAllCaches();
463
}
464
}
465
466