Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only destroy test specific caches at setup and teardown of SCC tests #71

Merged
merged 1 commit into from
Jan 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally the number of iterations and the cache name should be shared with the test and not hard coded separately. That way if the tests changes, the cleanup continues to be correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I'll fix this in a separate PR.

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,9 @@ 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;

String cacheName = apiTest.name() + workloadName;
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 +280,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", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${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", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", "-Xshareclasses:name=" + SCSoftmxTestUtil.CACHE_NAME + ",cacheDir=" + cacheDir + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
}
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 @@ -31,6 +31,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;

/**
*
Expand All @@ -48,7 +49,6 @@
*/
public class SharedClassesWorkload implements SharedClassesPluginInterface {
private DirectoryRef cacheDirLocation;
private String cacheName;
private String cacheDir;
private String jvmOptions;

Expand All @@ -72,21 +72,18 @@ public void pluginInit(StfCoreExtension test, StfSharedClassesExtension sharedCl
// Define the location for cache.
cacheDirLocation = test.env().getResultsDir().childDirectory("cache");
cacheDir = cacheDirLocation.toString();

// Specify the cache specific variables.
cacheName = "workload_cache";
jvmOptions = "-Xshareclasses:" + "name=" + cacheName + "," + "cacheDir=" + cacheDirLocation;
jvmOptions = "-Xshareclasses:" + "name=" + SCSoftmxTestUtil.CACHE_NAME + "," + "cacheDir=" + cacheDirLocation;
}


public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Create the directories for the cache.
test.doMkdir("Create the cache directory", cacheDirLocation);

// 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", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}


Expand Down Expand Up @@ -120,7 +117,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
loadTestSpecification);

// Check that the expected cache was created and no other caches exist.
verifyAndPrintCache(sharedClasses, cacheName, cacheDir, cacheName, 1);
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1);

// Access the existing cache using another workload process.
test.doRunForegroundProcess("Access cache using another workload process",
Expand All @@ -131,13 +128,13 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass

// Confirm that only the expected cache exists and no other caches were
// created by the "SCL2" workload process.
verifyAndPrintCache(sharedClasses, cacheName, cacheDir, cacheName, 1);
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1);

// Destroy the existing cache.
sharedClasses.doDestroySpecificCache("Destroy cache", jvmOptions + "${cacheOperation}", cacheName, cacheDir);
sharedClasses.doDestroySpecificCache("Destroy cache", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);

// Confirm that the deletion was successful.
sharedClasses.doVerifySharedClassesCache("Verify caches", jvmOptions + "${cacheOperation}", cacheName, cacheDir, "", 0);
sharedClasses.doVerifySharedClassesCache("Verify caches", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir, "", 0);

// Create a new cache using multiple workload processes.
test.doRunForegroundProcesses("Run multiple workload processes",
Expand All @@ -148,7 +145,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
loadTestSpecification);

// Check that the expected cache was created and no other caches exist
verifyAndPrintCache(sharedClasses, cacheName, cacheDir, cacheName, 1);
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1);

// Access the existing cache using more workload processes
test.doRunForegroundProcesses("Access cache using more workload processes",
Expand All @@ -160,13 +157,13 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass

// Confirm that only the expected cache exists and no other caches were
// created by the last run of "SCL" workload processes.
verifyAndPrintCache(sharedClasses, cacheName, cacheDir, cacheName, 1);
verifyAndPrintCache(sharedClasses, SCSoftmxTestUtil.CACHE_NAME, cacheDir, SCSoftmxTestUtil.CACHE_NAME, 1);

// Destroy the existing cache.
sharedClasses.doDestroySpecificCache("Destroy cache", jvmOptions + "${cacheOperation}", cacheName, cacheDir);
sharedClasses.doDestroySpecificCache("Destroy cache", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);

// Confirm that the deletion was successful
sharedClasses.doVerifySharedClassesCache("List all caches", jvmOptions + "${cacheOperation}", cacheName, cacheDir, "", 0);
sharedClasses.doVerifySharedClassesCache("List all caches", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir, "", 0);
}

private void verifyAndPrintCache(StfSharedClassesExtension sharedClasses, String cacheName, String cacheDir, String expectedCacheName, int expectedCaches) throws Exception {
Expand All @@ -180,10 +177,10 @@ private void verifyAndPrintCache(StfSharedClassesExtension sharedClasses, String


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 related 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");
sharedClasses.doDestroySpecificCache("Destroy cache", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
sharedClasses.doDestroySpecificNonPersistentCache("Destroy cache", jvmOptions + "${cacheOperation}", SCSoftmxTestUtil.CACHE_NAME, cacheDir);
}
}
Loading