Path: blob/master/test/functional/CacheManagement/src/tests/sharedclasses/options/TestDestroyCache.java
6005 views
/*******************************************************************************1* Copyright (c) 2010, 2019 IBM Corp. and others2*3* This program and the accompanying materials are made available under4* the terms of the Eclipse Public License 2.0 which accompanies this5* distribution and is available at https://www.eclipse.org/legal/epl-2.0/6* or the Apache License, Version 2.0 which accompanies this distribution and7* is available at https://www.apache.org/licenses/LICENSE-2.0.8*9* This Source Code may also be made available under the following10* Secondary Licenses when the conditions for such availability set11* forth in the Eclipse Public License, v. 2.0 are satisfied: GNU12* General Public License, version 2 with the GNU Classpath13* Exception [1] and GNU General Public License, version 2 with the14* OpenJDK Assembly Exception [2].15*16* [1] https://www.gnu.org/software/classpath/license.html17* [2] http://openjdk.java.net/legal/assembly-exception.html18*19* 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-exception20*******************************************************************************/2122package tests.sharedclasses.options;2324import tests.sharedclasses.*;25import java.io.*;2627/*28* Check various scenarios handled in j9shr_destroy_cache()29* with respect to deleting old and current generation cache.30* For details see JAZZ design 37044.31*/32public class TestDestroyCache extends TestUtils {33String cacheName = "testcache";34String destroyPersistentCache, destroyNonPersistentCache;35String infiniteLoopOutput = "Running infinite loop";3637public static void main(String args[]) {38TestDestroyCache tdc = new TestDestroyCache();39tdc.destroyPersistentCache = getCommand(DestroyPersistentCacheCommand, tdc.cacheName);40tdc.destroyNonPersistentCache = getCommand(DestroyNonPersistentCacheCommand, tdc.cacheName);41tdc.testCase1();42tdc.testCase2();43tdc.testCase3();44tdc.testCase4();45tdc.testCase5();46tdc.testCase6();47}4849private void testCase1() {50String expectedErrorMessages[] = new String[] {51"JVMSHRC428I" /* Removed older generation of shared class cache "<cache name>" */52};5354runDestroyAllCaches();5556/* When only older generation cache exists and is not in use */57if (isMVS() == false) {58runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");59RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);60}6162if (realtimeTestsSelected() == false) {63runSimpleJavaProgramWithNonPersistentCache(cacheName, "createOldGen");64RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);65}6667runDestroyAllCaches();68}6970private void testCase2() {71Process p1 = null;72String expectedErrorMessages[];7374runDestroyAllCaches();7576/* When only current generation cache exists and is in use */77if (isMVS() == false) {78try {79if (isWindows()) {80expectedErrorMessages = new String[] {81"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */82};83} else {84/* Linux, AIX allow to destroy an active persistent cache */85expectedErrorMessages = new String[] {86"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */87};88}89if (realtimeTestsSelected()) {90/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */91runSimpleJavaProgramWithPersistentCache(cacheName);92}93runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);94p1 = RunCommand.getLastProcess();95RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);96} finally {97if (null == p1) {98p1 = RunCommand.getLastProcess();99}100if (null != p1) {101p1.destroy();102try {103p1.waitFor();104} catch (java.lang.InterruptedException e) {105e.printStackTrace();106}107}108if (realtimeTestsSelected()) {109destroyPersistentCache(cacheName);110}111}112}113114if (realtimeTestsSelected() == false) {115try {116expectedErrorMessages = new String[] {117"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */118};119runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);120p1 = RunCommand.getLastProcess();121RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);122} finally {123if (null == p1) {124p1 = RunCommand.getLastProcess();125}126if (null != p1) {127p1.destroy();128try {129p1.waitFor();130} catch (java.lang.InterruptedException e) {131e.printStackTrace();132}133}134}135}136137runDestroyAllCaches();138}139140private void testCase3() {141Process p1 = null;142String expectedErrorMessages[];143144runDestroyAllCaches();145146/* When only older generation cache exists and is in use */147if (isMVS() == false) {148try {149if (isWindows()) {150expectedErrorMessages = new String[] {151"JVMSHRC429I" /* Failed to remove older generation of shared class cache "<cache name>" */152};153} else {154/* Linux, AIX allow to destroy an active persistent cache */155expectedErrorMessages = new String[] {156"JVMSHRC428I" /* Removed older generation of shared class cache "<cache name>" */157};158}159if (realtimeTestsSelected()) {160/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */161runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");162}163runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);164p1 = RunCommand.getLastProcess();165RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);166} finally {167if (null == p1) {168p1 = RunCommand.getLastProcess();169}170if (null != p1) {171p1.destroy();172try {173p1.waitFor();174} catch (java.lang.InterruptedException e) {175e.printStackTrace();176}177}178if (realtimeTestsSelected()) {179destroyPersistentCache(cacheName);180}181}182}183184if (realtimeTestsSelected() == false) {185try {186expectedErrorMessages = new String[] {187"JVMSHRC429I" /* Failed to remove older generation of shared class cache "<cache name>" */188};189runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);190p1 = RunCommand.getLastProcess();191RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);192} finally {193if (null == p1) {194p1 = RunCommand.getLastProcess();195}196if (null != p1) {197p1.destroy();198try {199p1.waitFor();200} catch (java.lang.InterruptedException e) {201e.printStackTrace();202}203}204}205}206207runDestroyAllCaches();208}209210private void testCase4() {211Process p1 = null;212String expectedErrorMessages[];213214runDestroyAllCaches();215216/* When older generation cache is not in use but current generation cache is in use */217if (isMVS() == false) {218try {219if (isWindows()) {220expectedErrorMessages = new String[] {221"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */222"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */223};224} else {225/* Linux, AIX allow to destroy an active persistent cache */226expectedErrorMessages = new String[] {227"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */228"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */229};230}231runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");232if (realtimeTestsSelected()) {233/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */234runSimpleJavaProgramWithPersistentCache(cacheName);235}236runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);237p1 = RunCommand.getLastProcess();238RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);239} finally {240if (null == p1) {241p1 = RunCommand.getLastProcess();242}243if (null != p1) {244p1.destroy();245try {246p1.waitFor();247} catch (java.lang.InterruptedException e) {248e.printStackTrace();249}250}251if (realtimeTestsSelected()) {252destroyPersistentCache(cacheName);253}254}255}256257if (realtimeTestsSelected() == false) {258try {259expectedErrorMessages = new String[] {260"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */261"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */262};263runSimpleJavaProgramWithNonPersistentCache(cacheName, "createOldGen");264runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);265p1 = RunCommand.getLastProcess();266RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);267} finally {268if (null == p1) {269p1 = RunCommand.getLastProcess();270}271if (null != p1) {272p1.destroy();273try {274p1.waitFor();275} catch (java.lang.InterruptedException e) {276e.printStackTrace();277}278}279}280}281282runDestroyAllCaches();283}284285private void testCase5() {286Process p1 = null;287String expectedErrorMessages[];288289runDestroyAllCaches();290291/* When older generation is in use and current generation cache is not in use */292if (isMVS() == false) {293try {294if (isWindows()) {295expectedErrorMessages = new String[] {296"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */297"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */298};299} else {300/* Linux, AIX allow to destroy an active persistent cache */301expectedErrorMessages = new String[] {302"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */303"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */304};305}306if (realtimeTestsSelected()) {307/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */308runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");309}310runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);311p1 = RunCommand.getLastProcess();312runSimpleJavaProgramWithPersistentCache(cacheName);313RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);314} finally {315if (null == p1) {316p1 = RunCommand.getLastProcess();317}318if (null != p1) {319p1.destroy();320try {321p1.waitFor();322} catch (java.lang.InterruptedException e) {323e.printStackTrace();324}325}326if (realtimeTestsSelected()) {327destroyPersistentCache(cacheName);328}329}330}331332if (realtimeTestsSelected() == false) {333try {334expectedErrorMessages = new String[] {335"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */336"is destroyed" /* Shared cache "<cache name>" is destroyed */337};338runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);339p1 = RunCommand.getLastProcess();340runSimpleJavaProgramWithNonPersistentCache(cacheName);341RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);342} finally {343if (null == p1) {344p1 = RunCommand.getLastProcess();345}346if (null != p1) {347p1.destroy();348try {349p1.waitFor();350} catch (java.lang.InterruptedException e) {351e.printStackTrace();352}353}354}355}356357runDestroyAllCaches();358}359360private void testCase6() {361Process p1 = null;362Process p2 = null;363String expectedErrorMessages[];364365runDestroyAllCaches();366367/* When both older generation cache and current generation cache are in use */368if (isMVS() == false) {369try {370if (isWindows()) {371expectedErrorMessages = new String[] {372"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */373"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */374};375} else {376/* Linux, AIX allow to destroy an active persistent cache */377expectedErrorMessages = new String[] {378"JVMSHRC428I",/* Removed older generation of shared class cache "<cache name>" */379"has been destroyed" /* Persistent shared cache "<cache name>" has been destroyed */380};381}382if (realtimeTestsSelected()) {383/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */384runSimpleJavaProgramWithPersistentCache(cacheName, "createOldGen");385}386runInfiniteLoopJavaProgramWithPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);387p1 = RunCommand.getLastProcess();388if (realtimeTestsSelected()) {389/* Need to create realtime cache before it is used by InfiniteLoop. Otherwise, it won't be written to disk */390runSimpleJavaProgramWithPersistentCache(cacheName);391}392runInfiniteLoopJavaProgramWithPersistentCache(cacheName, infiniteLoopOutput);393p2 = RunCommand.getLastProcess();394RunCommand.execute(destroyPersistentCache, null, expectedErrorMessages, false, false, null);395} finally {396if (null == p1) {397p1 = RunCommand.getLastProcess();398}399if (null != p1) {400p1.destroy();401try {402p1.waitFor();403} catch (java.lang.InterruptedException e) {404e.printStackTrace();405}406}407if (null == p2) {408p2 = RunCommand.getLastProcess();409}410if (null != p2) {411p2.destroy();412try {413p2.waitFor();414} catch (java.lang.InterruptedException e) {415e.printStackTrace();416}417}418if (realtimeTestsSelected()) {419destroyPersistentCache(cacheName);420}421}422}423424if (realtimeTestsSelected() == false) {425try {426expectedErrorMessages = new String[] {427"JVMSHRC429I",/* Failed to remove older generation of shared class cache "<cache name>" */428"JVMSHRC430I" /* Failed to remove current generation of shared class cache "<cache name>" */429};430runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, "createOldGen", infiniteLoopOutput);431p1 = RunCommand.getLastProcess();432runInfiniteLoopJavaProgramWithNonPersistentCache(cacheName, infiniteLoopOutput);433p2 = RunCommand.getLastProcess();434RunCommand.execute(destroyNonPersistentCache, null, expectedErrorMessages, false, false, null);435} finally {436if (null == p1) {437p1 = RunCommand.getLastProcess();438}439if (null != p1) {440p1.destroy();441try {442p1.waitFor();443} catch (java.lang.InterruptedException e) {444e.printStackTrace();445}446}447if (null == p2) {448p2 = RunCommand.getLastProcess();449}450if (null != p2) {451p2.destroy();452try {453p2.waitFor();454} catch (java.lang.InterruptedException e) {455e.printStackTrace();456}457}458}459}460461runDestroyAllCaches();462}463}464465466