use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.
the class URLClassPathHelperURLHelperCompatibilityTest method executeTest.
private boolean executeTest(String classPath, String[] classesToLoad, String[] urls, String[][] classesToFind, String[][] results) {
URLClassPathCreator creator = new URLClassPathCreator(classPath);
URL[] urlPath;
urlPath = creator.createURLClassPath();
CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
String classToLoad = classesToLoad[classIndex];
if (classToLoad != null) {
try {
cl.loadClass(classToLoad);
} catch (Exception e) {
e.printStackTrace();
}
}
}
String urlsString = urls[0];
for (int index = 1; index < urls.length; index++) {
urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
}
System.out.println("\n** urlsString: " + urlsString);
URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
URL[] urlPath2;
urlPath2 = creator2.createURLClassPath();
CustomURLLoader urlcl = new CustomURLLoader(urlPath2, this.getClass().getClassLoader());
boolean result = true;
for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
for (int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++) {
String classToFind = classesToFind[urlIndex][classIndex];
String expectedResult = results[urlIndex][classIndex];
if (classToFind != null) {
String testResult = String.valueOf(urlcl.isClassInSharedCache(urlIndex, classToFind));
if (!(expectedResult.equals(testResult))) {
System.out.println("\nFailure finding class: " + classToFind + " on path: " + urls[urlIndex] + " which is index: " + urlIndex + " result: " + testResult + " expecting: " + expectedResult);
result = false;
}
}
}
}
return result;
}
use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.
the class TokenIncompatibilityTest method run.
public void run() {
boolean passed = true;
URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;./Sports;");
CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());
String[] classesToLoad = new String[] { "Dog", "SpeedSkating" };
String tok = "FindStore";
loader.setToken(tok);
for (int index = 0; index < classesToLoad.length; index++) {
try {
loader.loadClass(classesToLoad[index]);
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
for (int index = 0; index < classesToLoad.length; index++) {
if (true != loader.isClassInSharedCache(tok, classesToLoad[index])) {
System.out.println("\nClass: " + classesToLoad[index] + " not in cache");
passed = false;
}
}
pathCreator = new URLClassPathCreator("./Pets;");
CustomURLClassLoader urlCl = new CustomURLClassLoader(pathCreator.createURLClassPath());
if (true == urlCl.isClassInSharedCache("Dog")) {
passed = false;
System.out.println("\nURLClassLoader succesfully loaded class stored with token.");
}
pathCreator = new URLClassPathCreator("./Sports;");
CustomURLLoader urlL = new CustomURLLoader(pathCreator.createURLClassPath());
if (true == urlL.isClassInSharedCache(0, "Dog")) {
passed = false;
System.out.println("\nURLLoader succesfully loaded class stored with token.");
}
// Load with URLCP
try {
urlCl.loadClass("Cat");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
// Load with URLL
urlL.loadClassFrom("Cricket", 0);
// Find with Token
if (true == loader.isClassInSharedCache(tok, "Cat")) {
passed = false;
System.out.println("\nTokenLoader found class loaded by URLClassLoader");
}
if (true == loader.isClassInSharedCache(tok, "Cricket")) {
passed = false;
System.out.println("\nTokenLoader found class loaded by URLLoader");
}
// Find with token == url
pathCreator = new URLClassPathCreator("./Pets;");
URL[] urlarray = pathCreator.createURLClassPath();
String urlToken = urlarray[0].toString();
if (true == loader.isClassInSharedCache(urlToken, "Cricket")) {
passed = false;
System.out.println("\nTokenLoader found class loaded by URLLoader using a token that looked like a url");
}
if (passed) {
System.out.println("\nTEST PASSED");
} else {
System.out.println("\nTEST FAILED");
}
}
use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.
the class URLClassPathHelperURLHelperStaleEntryCompatibilityTest method executeTest.
private boolean executeTest(String classPath, String[] classesToLoad, String[] urls, String[][] classesToFind, String[][] results, String batchFile, String javacpath) {
URLClassPathCreator creator = new URLClassPathCreator(classPath);
URL[] urlPath;
urlPath = creator.createURLClassPath();
CustomURLClassLoader cl = new CustomURLClassLoader(urlPath, this.getClass().getClassLoader());
for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
String classToLoad = classesToLoad[classIndex];
if (classToLoad != null) {
try {
cl.loadClass(classToLoad);
} catch (Exception e) {
e.printStackTrace();
}
}
}
runBatchFile(batchFile, javacpath);
String urlsString = urls[0];
for (int index = 1; index < urls.length; index++) {
urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).toString();
}
System.out.println("\n** urlsString: " + urlsString);
URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
URL[] urlPath2;
urlPath2 = creator2.createURLClassPath();
CustomURLLoader urlcl = new CustomURLLoader(urlPath2, this.getClass().getClassLoader());
boolean result = true;
for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
for (int classIndex = 0; classIndex < classesToFind[urlIndex].length; classIndex++) {
String classToFind = classesToFind[urlIndex][classIndex];
String expectedResult = results[urlIndex][classIndex];
if (classToFind != null) {
String testResult = String.valueOf(urlcl.isClassInSharedCache(urlIndex, classToFind));
if (!(expectedResult.equals(testResult))) {
System.out.println("\nFailure finding class: " + classToFind + " on path: " + urls[urlIndex] + " which is index: " + urlIndex + " result: " + testResult + " expecting: " + expectedResult);
result = false;
}
}
}
}
return result;
}
use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.
the class FilterTester_1 method test1.
public boolean test1() {
System.out.println("\nTest " + ++counter + ": Store Filter = A_Main");
String testClassName = "sharedclasses.storefilter.resources.A_Main";
URLClassPathCreator pathCreator = new URLClassPathCreator("./Resources/resources.jar");
CustomURLClassLoader customURLCL = new CustomURLClassLoader(pathCreator.createURLClassPath());
SharedClassHelperFactory schFactory = Shared.getSharedClassHelperFactory();
SharedClassURLClasspathHelper newHelper;
try {
newHelper = schFactory.getURLClasspathHelper(customURLCL, pathCreator.createURLClassPath(), new StoreFilter("A_Main"));
if (null == newHelper) {
System.out.println("\t->newHelper is null.");
return false;
}
} catch (HelperAlreadyDefinedException e) {
System.out.println("\t->HelperAlreadyDefinedException is thrown.");
return false;
}
try {
Class c = Class.forName(testClassName, true, customURLCL);
Method meth = c.getDeclaredMethod("run", new Class[0]);
invokeMethod(c.newInstance(), "run", new Class[0]);
/* Set the filter to null,
* so there will be no filter to prevent someclass names to be looked in shared cache.
* See SharedClassFilter#acceptFind */
newHelper.setSharingFilter(null);
if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.A_Main")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.A_Main is in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.B_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.B_Dummy is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.C_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.C_Dummy is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.D_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.D_Dummy is not in shared cache.");
return false;
}
} catch (Exception e2) {
e2.printStackTrace();
return false;
}
return true;
}
use of CustomCLs.CustomURLClassLoader in project openj9 by eclipse.
the class FilterTester_3 method test3.
public boolean test3() {
System.out.println("\nTest " + ++counter + ": Store Filter = C_Dummy$Data. Verify shared classpath helper methods.");
String testClassName = "sharedclasses.storefilter.resources.A_Main";
URLClassPathCreator pathCreator = new URLClassPathCreator("./Resources/resources.jar");
CustomURLClassLoader customURLCL = new CustomURLClassLoader(pathCreator.createURLClassPath());
SharedClassHelperFactory schFactory = Shared.getSharedClassHelperFactory();
SharedClassURLClasspathHelper newHelper;
try {
newHelper = schFactory.getURLClasspathHelper(customURLCL, pathCreator.createURLClassPath(), new StoreFilter("C_Dummy$Data"));
if (null == newHelper) {
System.out.println("\t->newHelper is null.");
return false;
}
} catch (HelperAlreadyDefinedException e) {
System.out.println("\t->HelperAlreadyDefinedException is thrown.");
return false;
}
try {
Class c = Class.forName(testClassName, true, customURLCL);
Method meth = c.getDeclaredMethod("run", new Class[0]);
invokeMethod(c.newInstance(), "run", new Class[0]);
/* Set the filter to null,
* so there will be no filter to prevent some class names to be looked in shared cache.
* See SharedClassFilter#acceptFind
*/
newHelper.setSharingFilter(null);
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.A_Main$Data")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.A_Main$Data is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.B_Dummy$Data")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.B_Dummy$Data is not in shared cache.");
return false;
}
if (customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.C_Dummy$Data")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.C_Dummy$Data is in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.D_Dummy$Data")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.D_Dummy$Data is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.A_Main")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.A_Main is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.B_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.B_Dummy is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.C_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.C_Dummy is not in shared cache.");
return false;
}
if (!customURLCL.isClassInSharedCache("sharedclasses.storefilter.resources.D_Dummy")) {
System.out.println("\nTEST FAILED - sharedclasses.storefilter.resources.D_Dummy is not in shared cache.");
return false;
}
newHelper.setSharingFilter(new StoreFilter("C_Dummy"));
invokeMethod(c.newInstance(), "run", new Class[0]);
/* Set the filter to null,
* so there will be no filter to prevent some class names to be looked in shared cache.
* See SharedClassFilter#acceptFind
*/
newHelper.setSharingFilter(null);
if (null != newHelper.getSharingFilter()) {
System.out.println("\nTEST FAILED - Shared Filter is not null");
return false;
}
if (newHelper.getClassLoader() != customURLCL) {
System.out.println("\nTEST FAILED - Wrong classloader in shared classpath helper");
return false;
}
newHelper.confirmAllEntries();
try {
newHelper.setClasspath(new URL[0]);
System.out.println("\nTEST FAILED - Shared classpath helper can set new classpath after confirming all entries. ");
return false;
} catch (CannotSetClasspathException e) {
/* Expected */
}
} catch (Exception e2) {
e2.printStackTrace();
return false;
}
return true;
}
Aggregations