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

Update SharedClassesCacheChecker to only delete test-specific cache #74

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
Expand Up @@ -207,6 +207,46 @@ public void doDestroyAllNonPersistentCaches(String comment) throws StfException
}


/**
* Destroys all the persistent shared classes caches from the given shared classes
* cache location, and checks the output for "No shared class caches available"
* or "shared cache (.*) has been destroyed" if the return code is not 0.
* It does this validation because it is unknown if a cache exists and the destroy
* shared classes command always returns code 1.
*
* @param comment is a comment from the test summarising why it's running a child process.
* @throws StfException if anything goes wrong.
*/
public void doDestroyAllPersistentCachesInCacheDir(String comment, String cacheDir) throws StfException {
generator.startNewCommand(comment, "java", "Destroy all persistent caches");

String defaultJavaOptions = "-Xshareclasses:destroyAll,cacheDir=" + cacheDir;
String[] expectedMessages = {"No shared class caches available", "Cache does not exist", "shared cache (.*) has been destroyed", "cache (.*) is destroyed"};

runSharedClassesCacheCommand(comment, StfDuration.ofMinutes(1), expectedMessages, defaultJavaOptions);
}


/**
* Destroys all the non-persistent shared classes caches from the given shared classes
* cache location, and checks the output for "No shared class caches available"
* or "shared cache (.*) has been destroyed" if the return code is not 0.
* It does this validation because it is unknown if a cache exists and the destroy
* shared classes command always returns code 1.
*
* @param comment is a comment from the test summarising why it's running a child process.
* @throws StfException if anything goes wrong.
*/
public void doDestroyAllNonPersistentCachesInCacheDir(String comment, String cacheDir) throws StfException {
generator.startNewCommand(comment, "java", "Destroy all non-persistent caches");

String defaultJavaOptions = "-Xshareclasses:destroyAll,nonpersistent,cacheDir=" + cacheDir;
String[] expectedMessages = {"No shared class caches available", "Cache does not exist", "shared cache (.*) has been destroyed", "cache (.*) is destroyed"};

runSharedClassesCacheCommand(comment, StfDuration.ofMinutes(1), expectedMessages, defaultJavaOptions);
}


/**
* Prints the Shared Classes cache status and checks the output for "Cache is 100% full"
* if the return code is not 0.
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 @@ -68,6 +68,8 @@ public class SharedClassesCacheChecker {
private static final String CACHE_DIR_PROP = "cacheDir";

private static final String CONFIG_FILE_PROP = "configFile";

private static final String CACHE_NAME_PROP = "cacheName";

private static final String EXPECTED_CACHE_COUNT_PROP = "expectedCacheCount";

Expand All @@ -93,8 +95,12 @@ public class SharedClassesCacheChecker {
// The retrieved list of shared classes caches
List<SharedClassCacheInfo> caches;

public SharedClassesCacheChecker(Properties config) {
// Name of the Shared Classes Cache
private String cacheName;

public SharedClassesCacheChecker(Properties config, String cacheName) {
this.config = config;
this.cacheName = cacheName;
cacheDir = config.getProperty(CACHE_DIR_PROP);
if (cacheDir == null || cacheDir.equals("default")) {
logger.info("Using default cache directory");
Expand Down Expand Up @@ -146,8 +152,8 @@ boolean delete() {
persistence = SharedClassUtilities.PERSISTENT;
}
int answer = SharedClassUtilities.destroySharedCache(this.cacheDir,
persistence, info.getCacheName(), false);
logger.info("Attempting to delete cache: " + info.getCacheName()
persistence, cacheName, false);
logger.info("Attempting to delete cache: " + cacheName
+ " and return value from delete call was: " + answer);

switch (answer) {
Expand Down Expand Up @@ -347,6 +353,12 @@ public static void main(String[] args) {
System.out.println("No config file name supplied via system property 'configFile'");
System.exit(1);
}

String cacheName = System.getProperty(CACHE_NAME_PROP);
if (cacheName == null) {
System.out.println("No cacheName supplied via system property 'cacheName'");
System.exit(1);
}

Properties config = new Properties();
try {
Expand All @@ -358,7 +370,7 @@ public static void main(String[] args) {
}


SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config);
SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config, cacheName);
try {
checker.loadExpectedCacheData();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import static net.adoptopenjdk.stf.extensions.core.StfCoreExtension.Echo.ECHO_OFF;
import static net.adoptopenjdk.stf.extensions.core.StfCoreExtension.Echo.ECHO_ON;

import java.util.ArrayList;
import java.util.Iterator;

import net.adoptopenjdk.loadTest.InventoryData;
import net.openj9.sc.api.SharedClassesCacheChecker;
import net.adoptopenjdk.stf.environment.DirectoryRef;
Expand Down Expand Up @@ -88,6 +91,8 @@ private Tests(int expectedCacheCount, String api, boolean usesDefaultLocation, b
private DirectoryRef cacheDirLocation;
private DirectoryRef configDirLocation;

private ArrayList<String> testCachesCreatedInDefaultLocation = new ArrayList<String>();


public void help(HelpTextGenerator help) {
help.outputSection("Shared Classes API test");
Expand Down Expand Up @@ -115,14 +120,9 @@ public void setUp(StfCoreExtension test, StfSharedClassesExtension sharedClasses
test.doMkdir("Create the cache directory", cacheDirLocation);
test.doMkdir("Create the config directory", configDirLocation);

//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());
}
}
// Destroy all test specific caches from the test specific cacheDir to begin with a clean slate
sharedClasses.doDestroyAllPersistentCachesInCacheDir("Destroy all persistent caches in test cacheDir", cacheDirLocation.getSpec());
sharedClasses.doDestroyAllNonPersistentCachesInCacheDir("Destroy all nonpersistent caches in test cacheDir", cacheDirLocation.getSpec());
}


Expand All @@ -132,10 +132,13 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass

for (Tests apiTest : Tests.values()) {
String commentPrefix = apiTest.name() + ": ";
String cacheName = apiTest.name() + "Iterator";

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

String sharedClassesOption = "-Xshareclasses";
Expand All @@ -144,21 +147,22 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
// When usesIteratorCache is true, an additional cache is created when the JVM runs during the
// verification stage. In addition, the expected cache location for all caches is provided in the
// command line to the class, rather than going by the cacheDir parameter in the configuration file.
configCacheLocation = "cacheDir="; // This ensures the SharedClassesCacheChecker class is working as expected.
configCacheLocation = "cacheDir=" + cacheDir; // This ensures the SharedClassesCacheChecker class is working as expected.
sharedClassesOption += ":";
sharedClassesOption += (apiTest.usesGroupAccess ? "groupAccess," : "");
sharedClassesOption += (cacheDir.isEmpty()? "" : (cacheDir + ","));
sharedClassesOption += "name=" + apiTest.name() + "Iterator";
sharedClassesOption += "name=" + cacheName;
} else {
cacheName = apiTest.name() + "NoIterator";
if (apiTest.usesGroupAccess) {
if (apiTest.usesUtilities) {
sharedClassesOption = "-Xshareclasses:groupAccess,utilities";
sharedClassesOption = "-Xshareclasses:name=" + cacheName + "groupAccess,utilities";
} else {
sharedClassesOption = "-Xshareclasses:groupAccess";
sharedClassesOption = "-Xshareclasses:name=" + cacheName + "groupAccess";
}
} else {
if (apiTest.usesUtilities) {
sharedClassesOption = "-Xshareclasses:utilities";
sharedClassesOption = "-Xshareclasses:name=" + cacheName + "utilities";
} else {
/* do nothing, sharedClassesOption is -Xshareclasses */
}
Expand Down Expand Up @@ -202,6 +206,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
test.createJavaProcessDefinition()
.addJvmOption(sharedClassesOption)
.addJvmOption("-DconfigFile=" + configFile.getSpec())
.addJvmOption("-DcacheName=" + cacheName)
.addProjectToClasspath("openj9.test.sharedClasses.jvmti")
.runClass(SharedClassesCacheChecker.class));
} else {
Expand Down Expand Up @@ -280,16 +285,17 @@ private FileRef createConfigFile(StfCoreExtension test, Tests apiTest, String wo


public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
// Destroy all test specific persistent/non-persistent caches from the default cache location which may
// Destroy all test specific persistent/non-persistent caches from the test cacheDir 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.
// 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());
}
sharedClasses.doDestroyAllPersistentCachesInCacheDir("Destroy all persistent caches in test cacheDir", cacheDirLocation.getSpec());
sharedClasses.doDestroyAllNonPersistentCachesInCacheDir("Destroy all nonpersistent caches in test cacheDir", cacheDirLocation.getSpec());

// Destroy all test specific caches that may have been left in the default location
Iterator<String> i = testCachesCreatedInDefaultLocation.iterator();
while (i.hasNext()) {
String cacheName = i.next();
sharedClasses.doDestroySpecificCache("Destroy test specific persistent cache from default location", "-Xshareclasses:name=" + cacheName + "${cacheOperation}", cacheName, "");
sharedClasses.doDestroySpecificNonPersistentCache("Destroy test specific non-persistent cache from default location", "-Xshareclasses:name=" + cacheName + "${cacheOperation}", cacheName, "");
}
}
}