Skip to content

Commit

Permalink
Manage workload caches
Browse files Browse the repository at this point in the history
  • Loading branch information
Mesbah-Alam committed Jan 24, 2019
1 parent 6cf9420 commit 50449ee
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -70,7 +71,7 @@ public class SharedClassesCacheChecker {

private static final String CONFIG_FILE_PROP = "configFile";

private static final String CACHE_NAME_PROP = "cacheName";
private static final String WORKLOAD_CACHE_LIST_PROP = "wlCacheList";

private static final String EXPECTED_CACHE_COUNT_PROP = "expectedCacheCount";

Expand Down Expand Up @@ -101,11 +102,11 @@ public class SharedClassesCacheChecker {
ArrayList<String> alreadySuccesfullyDeletedCaches;

// Name of the Shared Classes Cache
private String cacheName;
private List<String> workloadCacheList;

public SharedClassesCacheChecker(Properties config, String cacheName) {
public SharedClassesCacheChecker(Properties config, List<String> wlCacheList) {
this.config = config;
this.cacheName = cacheName;
this.workloadCacheList = wlCacheList;
cacheDir = config.getProperty(CACHE_DIR_PROP);
if (cacheDir == null || cacheDir.equals("default")) {
logger.info("Using default cache directory");
Expand Down Expand Up @@ -153,14 +154,16 @@ boolean delete() {
boolean rv = true;

for (SharedClassCacheInfo info: this.caches) {
// We are running SharedClassesCacheChecker once per each cache, with the cache's name
// being sent into this utility via CACHE_NAME_PROP command line (this is to ensure we
// only attempt to verify and delete the test-related caches, and leave alone other possible
// caches that might exist on the machine where the test is running). So, we should attempt
// to destroy only the test-related cache we are given.
if (info.getCacheName() == null) {
// We want to only delete the worklaod caches here.
// Any cache that might be listed in the default location - created
// or owned by other processes should be ignored.
// Cache created and used by the SharedClassesCacheCheceker process
// can not be deleted by itself either, so must be ignored here.
// Those are deleted in SharedClassesAPI tearDown() method
String cacheName = info.getCacheName();
if (cacheName == null) {
continue;
} else if (!info.getCacheName().equals(cacheName)) {
} else if (!workloadCacheList.contains(cacheName)) {
continue;
} else if (this.alreadySuccesfullyDeletedCaches.contains(cacheName)) {
continue;
Expand Down Expand Up @@ -195,7 +198,7 @@ boolean delete() {
rv = false;
break;
}
this.alreadySuccesfullyDeletedCaches.add(cacheName);
this.alreadySuccesfullyDeletedCaches.add(info.getCacheName());
break;
}

Expand Down Expand Up @@ -233,10 +236,12 @@ public String verify() {
int i = 0;
for (SharedClassCacheInfo info: caches) {

// We only want to verify the cache we are sent to verify and ignore the rest
// We only want to verify the workload caches
// Any cache that might be listed in the default location - created
// or owned by other processes should be ignored.
if (info.getCacheName() == null) {
continue;
} else if (!info.getCacheName().equals(cacheName)) {
} else if (!workloadCacheList.contains(info.getCacheName())) {
continue;
}

Expand Down Expand Up @@ -383,10 +388,13 @@ public static void main(String[] args) {
System.exit(1);
}

String cacheName = System.getProperty(CACHE_NAME_PROP);
if (cacheName == null) {
System.out.println("No cacheName supplied via system property 'cacheName'");
List<String> wlCacheList = new ArrayList<String>();
String listAsString = System.getProperty(WORKLOAD_CACHE_LIST_PROP);
if (listAsString == null) {
System.out.println("No workload cache list supplied via system property '"+ WORKLOAD_CACHE_LIST_PROP +"'");
System.exit(1);
} else {
wlCacheList = Arrays.asList(listAsString.split("--"));
}

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


SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config, cacheName);
SharedClassesCacheChecker checker = new SharedClassesCacheChecker(config, wlCacheList);
try {
checker.loadExpectedCacheData();
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ private Tests(int expectedCacheCount, String api, boolean usesDefaultLocation, b
private DirectoryRef configDirLocation;

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

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

public void help(HelpTextGenerator help) {
help.outputSection("Shared Classes API test");
Expand Down Expand Up @@ -205,7 +205,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
test.createJavaProcessDefinition()
.addJvmOption(sharedClassesOption)
.addJvmOption("-DconfigFile=" + configFile.getSpec())
.addJvmOption("-DcacheName=" + cacheName)
.addJvmOption("-DwlCacheList=" + wlCacheListToString())
.addProjectToClasspath("openj9.test.sharedClasses.jvmti")
.runClass(SharedClassesCacheChecker.class));
} else {
Expand Down Expand Up @@ -239,6 +239,7 @@ public void execute(StfCoreExtension test, StfSharedClassesExtension sharedClass
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;
this.wlCacheNameRegistry.add(cacheName);
String inventoryFile = "/openjdk.test.load/config/inventories/mix/mini-mix.xml";
int totalTests = InventoryData.getNumberOfTests(test, inventoryFile);
if (!cacheDir.isEmpty()) {
Expand Down Expand Up @@ -281,6 +282,24 @@ private FileRef createConfigFile(StfCoreExtension test, Tests apiTest, String wo

return configCacheFile;
}

// Creates a delimited list of workload cache names
// to be passed to SharedClassesCacheChecker
private String wlCacheListToString() {
String strList = "";
Iterator<String> i = this.wlCacheNameRegistry.iterator();
while(i.hasNext()) {
String aCacheName = i.next();
if (strList.length() == 0) {
strList = aCacheName;
} else {
strList = strList + "--" + aCacheName;
}
}
// clean up for next iteration
this.wlCacheNameRegistry.clear();
return strList;
}


public void tearDown(StfCoreExtension test, StfSharedClassesExtension sharedClasses) throws Exception {
Expand Down

0 comments on commit 50449ee

Please sign in to comment.