Skip to content

Commit

Permalink
Only destroy test specific caches at setup and teardown of tests
Browse files Browse the repository at this point in the history
Signed-off-by: Mesbah_Alam@ca.ibm.com <Mesbah_Alam@ca.ibm.com>
  • Loading branch information
Mesbah-Alam committed Jan 16, 2019
1 parent a0aa8ed commit b83913c
Show file tree
Hide file tree
Showing 8 changed files with 103 additions and 94 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp.
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution
Expand Down Expand Up @@ -126,15 +126,15 @@ public String[] resolveSharedClassesOptions(String scOptions, String cacheName,
* @throws StfException if anything goes wrong.
*/
public void doDestroySpecificCache(String comment, String scOptions, String cacheName, String cacheDir) throws StfException {
String cacheOperation = ",destroyAll";
String cacheOperation = ",destroy";

generator.startNewCommand(comment, "java", "Destroy specific shared classes cache",
"Options:", scOptions,
"CacheName:", cacheName,
"CacheDir:", cacheDir,
"CacheOperation:", cacheOperation);

String[] expectedMessages = {"shared cache \"" + cacheName + "\" has been destroyed", "cache \"" + cacheName + "\" is destroyed"};
String[] expectedMessages = {"shared cache \"" + cacheName + "\" has been destroyed", "cache \"" + cacheName + "\" is destroyed", "No shared class caches available", "Cache does not exist"};

runSharedClassesCacheCommand(comment, StfDuration.ofMinutes(1), expectedMessages, resolveSharedClassesOptions(scOptions, cacheName, cacheDir, cacheOperation));
}
Expand All @@ -153,15 +153,15 @@ public void doDestroySpecificCache(String comment, String scOptions, String cach
* @throws StfException if anything goes wrong.
*/
public void doDestroySpecificNonPersistentCache(String comment, String scOptions, String cacheName, String cacheDir) throws StfException {
String cacheOperation = ",destroyAll,nonpersistent";
String cacheOperation = ",destroy,nonpersistent";

generator.startNewCommand(comment, "java", "Destroy specific non-persistent shared classes cache",
"Options:", scOptions,
"CacheName:", cacheName,
"CacheDir:", cacheDir,
"CacheOperation:", cacheOperation);

String[] expectedMessages = {"shared cache \"" + cacheName + "\" has been destroyed", "cache \"" + cacheName + "\" is destroyed"};
String[] expectedMessages = {"shared cache \"" + cacheName + "\" has been destroyed", "cache \"" + cacheName + "\" is destroyed", "No shared class caches available", "Cache does not exist"};

runSharedClassesCacheCommand(comment, StfDuration.ofMinutes(1), expectedMessages, resolveSharedClassesOptions(scOptions, cacheName, cacheDir, cacheOperation));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp.
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution
Expand Down Expand Up @@ -37,6 +37,7 @@
import net.adoptopenjdk.stf.runner.modes.HelpTextGenerator;
import net.openj9.stf.sharedClasses.SharedClassesPluginInterface;
import net.openj9.stf.sharedClasses.StfSharedClassesExtension;
import net.openj9.test.sc.SCSoftmxTestUtil;

/**
* This test plugin is aimed at stress testing the IBM Shared Classes API which allows querying the status of shared
Expand Down Expand Up @@ -114,10 +115,14 @@ public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses
test.doMkdir("Create the cache directory", cacheDirLocation);
test.doMkdir("Create the config directory", configDirLocation);

// To ensure we run from a clean state, attempt to destroy all persistent/non-persistent caches
// from the default cache location which may have been left behind by a previous failed test.
sharedClasses.doDestroyAllPersistentCaches("Destroy Persistent Shared Classes Caches");
sharedClasses.doDestroyAllNonPersistentCaches("Destroy Non-Persistent Shared Classes Caches");
//We are running 5 Workloads namely WL1,..WL4. Each creates its own cache, so we should clean up each one of them
for (Tests apiTest : Tests.values()) {
for (int i = 1 ; i < 5 ; i++) {
String cacheName = apiTest.name() + "WL1" + i;
sharedClasses.doDestroySpecificCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDirLocation.getSpec() + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDirLocation.getSpec() + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
}
}
}


Expand All @@ -130,7 +135,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass

String cacheDir = "";
if (!apiTest.usesDefaultLocation) {
cacheDir= "cacheDir=" + cacheDirLocation;
cacheDir= "cacheDir=" + cacheDirLocation.toString();
}

String sharedClassesOption = "-Xshareclasses";
Expand Down Expand Up @@ -161,10 +166,10 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
}

// Start a workload process for each cache.
StfProcess wl1 = startWorkload(test, apiTest, "WL1", cacheDir, "persistent");
StfProcess wl2 = startWorkload(test, apiTest, "WL2", cacheDir, "persistent");
StfProcess wl3 = startWorkload(test, apiTest, "WL3", cacheDir, "nonpersistent");
StfProcess wl4 = startWorkload(test, apiTest, "WL4", cacheDir, "nonpersistent");
StfProcess wl1 = startWorkload(test, apiTest, "WL1", cacheDir, "persistent", sharedClasses);
StfProcess wl2 = startWorkload(test, apiTest, "WL2", cacheDir, "persistent", sharedClasses);
StfProcess wl3 = startWorkload(test, apiTest, "WL3", cacheDir, "nonpersistent", sharedClasses);
StfProcess wl4 = startWorkload(test, apiTest, "WL4", cacheDir, "nonpersistent", sharedClasses);

// Monitor the workload processes to completion.
test.doMonitorProcesses(commentPrefix + "Monitor workload processes", wl1, wl2, wl3, wl4);
Expand Down Expand Up @@ -227,11 +232,18 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
}

// This method starts a workload for a specific cache
private StfProcess startWorkload(StfCoreExtension test, Tests apiTest, String workloadName, String cacheDir, String persistantStatus) throws Exception {
private StfProcess startWorkload(StfCoreExtension test, Tests apiTest, String workloadName, String cacheDir, String persistantStatus, StfSharedClassesExtension sharedClasses) throws Exception {
String groupAccess = (apiTest.usesGroupAccess ? ",groupAccess" : "");

String cacheName = apiTest.name() + workloadName;

// Make sure we start from a clean slate by first deleting any existing test specific cache
if (persistantStatus.equals("persistent")) {
sharedClasses.doDestroySpecificCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDir + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
} else {
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDir + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
}

String inventoryFile = "/openjdk.test.load/config/inventories/mix/mini-mix.xml";
int totalTests = InventoryData.getNumberOfTests(test, inventoryFile);
if (!cacheDir.isEmpty()) {
Expand Down Expand Up @@ -277,10 +289,16 @@ private FileRef createConfigFile(StfCoreExtension test, Tests apiTest, String wo


public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Destroy all persistent/non-persistent caches from the default cache location which may
// Destroy all test specific persistent/non-persistent caches from the default cache location which may
// have been left behind by a failure. We don't care about caches left behind in results
// as those will get deleted together with results.
sharedClasses.doDestroyAllPersistentCaches("Destroy Persistent Shared Classes Caches");
sharedClasses.doDestroyAllNonPersistentCaches("Destroy Non-Persistent Shared Classes Caches");
// We are running 5 Workloads namely WL1,..WL4. Each creates its own cache, so we should clean up each one of them
for (Tests apiTest : Tests.values()) {
for (int i = 1 ; i < 5 ; i++) {
String cacheName = apiTest.name() + "WL1" + i;
sharedClasses.doDestroySpecificCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDirLocation.getSpec() + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + cacheName + ",cacheDir=" + cacheDirLocation.getSpec() + "${cacheOperation}", cacheName, cacheDirLocation.getSpec());
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017, 2018 IBM Corp.
* Copyright (c) 2016, 2019 IBM Corp. and others
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which accompanies this distribution
Expand Down Expand Up @@ -39,6 +39,7 @@
import net.openj9.test.sc.LoaderSlaveMultiJar;
import net.openj9.test.sc.LoaderSlaveMultiThread;
import net.openj9.test.sc.LoaderSlaveMultiThreadMultiCL;
import net.openj9.test.sc.SCSoftmxTestUtil;


/**
Expand Down Expand Up @@ -135,7 +136,6 @@ private Modes(String sharedClassesModeStr) {
private String scOptions;
private String[] defaultScOptions;

private String cacheName;
private String cacheDir;

private String localSharedClassesResources;
Expand Down Expand Up @@ -170,16 +170,14 @@ public void pluginInit(StfCoreExtension test, StfSharedClassesExtension sharedCl
scTest = testArgs.decodeEnum("sharedClassTest", Tests.class);
mode = testArgs.decodeEnum("sharedClassMode", Modes.class);

// Define the cache name and location.
cacheName = "sc_java6";
cacheDir = test.env().getResultsDir().childDirectory("caches").toString();
String cacheOperation = "";

// Get the shared classes JVM options from the mode.
scOptions = mode.sharedClassesModeStr;

// And the (default) shared classes JVM options without the cache operation.
defaultScOptions = sharedClasses.resolveSharedClassesOptions(scOptions, cacheName, cacheDir, cacheOperation);
defaultScOptions = sharedClasses.resolveSharedClassesOptions(scOptions, SCSoftmxTestUtil.CACHE_NAME, cacheDir, cacheOperation);
}


Expand Down Expand Up @@ -228,10 +226,10 @@ public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses
localSharedClassesResources = localSharedClassesJar.getSpec();
}

// To ensure we run from a clean state, attempt to destroy all persistent/non-persistent caches
// To ensure we run from a clean state, attempt to destroy all test related persistent/non-persistent caches
// from the default cache location which may have been left behind by a previous failed test.
sharedClasses.doDestroyAllPersistentCaches("Destroy Persistent Shared Classes Caches");
sharedClasses.doDestroyAllNonPersistentCaches("Destroy Non-Persistent Shared Classes Caches");
sharedClasses.doDestroySpecificCache("Destroy cache", defaultScOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", defaultScOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}


Expand All @@ -240,7 +238,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
test.env().verifyUsingIBMJava();

// Reset/create test-specific cache.
sharedClasses.doResetSharedClassesCache("Reset Shared Classes Cache", scOptions, cacheName, cacheDir);
sharedClasses.doResetSharedClassesCache("Reset Shared Classes Cache", scOptions, SCSoftmxTestUtil.CACHE_NAME, cacheDir);

// Launch 5 Java processes concurrently to populate the Shared Classes cache.
String comment = "Start java processes using " + scTest.testClass.getSimpleName();
Expand All @@ -264,18 +262,17 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
// Ensure no cache is found if the noSC (no shared classes) mode is used
// else print the cache and check the output to ensure the cache has been created/populated.
if (mode == Modes.noSC) {
sharedClasses.doVerifySharedClassesCache("Ensure no cache is found", "-Xshareclasses" + "${cacheOperation}", cacheName, cacheDir, "", 0);
sharedClasses.doVerifySharedClassesCache("Ensure no cache is found", "-Xshareclasses" + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir, "", 0);
} else {
String[] expectedMessages = {"Cache is (100%|[1-9][0-9]%|[1-9]%) (soft )*full"}; // Ensure the cache is 1-100% 'full' or 'soft full' (in case of Java 10 and up)
sharedClasses.doPrintAndVerifyCache("Print Shared Classes Cache Stats", scOptions, cacheName, cacheDir, expectedMessages);
sharedClasses.doPrintAndVerifyCache("Print Shared Classes Cache Stats", scOptions, SCSoftmxTestUtil.CACHE_NAME, cacheDir, expectedMessages);
}
}


public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Destroy the (persistent) cache created by the test if the noSC mode is not used.
if (mode != Modes.noSC) {
sharedClasses.doDestroySpecificCache("Destroy Persistent cache created by the test", scOptions, cacheName, cacheDir);
}
// Destroy all caches created by the test
sharedClasses.doDestroySpecificCache("Destroy cache", defaultScOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", defaultScOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
}
Loading

0 comments on commit b83913c

Please sign in to comment.