Search in sources :

Example 1 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class URLHelperURLClassPathHelperCompatabilityTest method executeTest.

private boolean executeTest(String[] urls, String[][] classesToLoad, String classPath, String[] classesToFind, String[] results, String[] foundAt) {
    String urlsString = urls[0];
    for (int index = 1; index < urls.length; index++) {
        urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).append(File.pathSeparatorChar).toString();
    }
    URLClassPathCreator creator = new URLClassPathCreator(urlsString);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLLoader[] loaderArray = new CustomURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            loaderArray[urlIndex] = new CustomURLLoader(urlPath, this.getClass().getClassLoader());
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath2, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(cl.isClassInSharedCache(classToFind));
            if (!(expectedResult.equals(testResult))) {
                System.out.println("\nFailure finding class: " + classToFind + " result: " + testResult + " expecting: " + expectedResult);
                result = false;
            } else {
                if (testResult.equals("true")) {
                    result = validateReturnedClass(classToFind, foundAt[classIndex], cl);
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomClassloaders.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomClassloaders.CustomURLClassLoader) URL(java.net.URL)

Example 2 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class PartitioningURLClassPathHelperURLHelperStaleEntryCompatibilityTest method executeTest.

private boolean executeTest(String classPath, String partition, String[] classesToLoad, String[] urls, String[] partitionStrings, String[][] classesToFind, String[][] results, String batchFile, String javacpath) {
    URLClassPathCreator creator = new URLClassPathCreator(classPath);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomPartitioningURLCL cl = new CustomPartitioningURLCL(urlPath, this.getClass().getClassLoader());
    cl.setPartition(partition);
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToLoad = classesToLoad[classIndex];
        if (classToLoad != null) {
            try {
                cl.loadClass(classToLoad);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    if (0 != batchFile.length()) {
        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();
    }
    URLClassPathCreator creator2 = new URLClassPathCreator(urlsString);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomPartitioningURLLoader urlcl = new CustomPartitioningURLLoader(urlPath2, this.getClass().getClassLoader());
    boolean result = true;
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        urlcl.setPartition(partitionStrings[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;
}
Also used : URLClassPathCreator(Utilities.URLClassPathCreator) CustomPartitioningURLCL(CustomCLs.CustomPartitioningURLCL) CustomPartitioningURLLoader(CustomCLs.CustomPartitioningURLLoader) URL(java.net.URL)

Example 3 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class URLHelperURLClassPathHelperStaleEntryCompatibilityTest method executeTest.

private boolean executeTest(String[] urls, String[][] classesToLoad, String classPath, String[] classesToFind, String[] results, String batchFile, String[] foundAt, String 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]).append(File.pathSeparatorChar).toString();
    }
    System.out.println("\n** urlsString: " + urlsString);
    URLClassPathCreator creator = new URLClassPathCreator(urlsString);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLLoader[] loaderArray = new CustomURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            loaderArray[urlIndex] = new CustomURLLoader(urlPath, this.getClass().getClassLoader());
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    runBatchFile(batchFile, javacpath);
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath2, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(cl.isClassInSharedCache(classToFind));
            if (!(expectedResult.equals(testResult))) {
                System.out.println("\nFailure finding class: " + classToFind + " result: " + testResult + " expecting: " + expectedResult);
                result = false;
            } else {
                if (testResult.equals("true")) {
                    result = validateReturnedClass(classToFind, foundAt[classIndex], cl);
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Example 4 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class URLHelperURLClassPathHelperCompatibilityTest method executeTest.

private boolean executeTest(String[] urls, String[][] classesToLoad, String classPath, String[] classesToFind, String[] results, String[] foundAt) {
    String urlsString = urls[0];
    for (int index = 1; index < urls.length; index++) {
        urlsString = new StringBuffer(urls[index].length() + 1).append(urlsString).append(urls[index]).append(File.pathSeparatorChar).toString();
    }
    URLClassPathCreator creator = new URLClassPathCreator(urlsString);
    URL[] urlPath;
    urlPath = creator.createURLClassPath();
    CustomURLLoader[] loaderArray = new CustomURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            loaderArray[urlIndex] = new CustomURLLoader(urlPath, this.getClass().getClassLoader());
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomURLClassLoader cl = new CustomURLClassLoader(urlPath2, this.getClass().getClassLoader());
    for (int classIndex = 0; classIndex < classesToLoad.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(cl.isClassInSharedCache(classToFind));
            if (!(expectedResult.equals(testResult))) {
                System.out.println("\nFailure finding class: " + classToFind + " result: " + testResult + " expecting: " + expectedResult);
                result = false;
            } else {
                if (testResult.equals("true")) {
                    result = validateReturnedClass(classToFind, foundAt[classIndex], cl);
                }
            }
        }
    }
    return result;
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

Example 5 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class FilterTester_2 method test2.

public boolean test2() {
    System.out.println("\nTest " + ++counter + ": Store Filter = Data");
    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("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 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 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 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;
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        return false;
    }
    return true;
}
Also used : URLClassPathCreator(Utilities.URLClassPathCreator) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException) SharedClassHelperFactory(com.ibm.oti.shared.SharedClassHelperFactory) SharedClassURLClasspathHelper(com.ibm.oti.shared.SharedClassURLClasspathHelper) Method(java.lang.reflect.Method) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException)

Aggregations

URLClassPathCreator (Utilities.URLClassPathCreator)32 URL (java.net.URL)24 CustomURLLoader (CustomCLs.CustomURLLoader)13 CustomURLClassLoader (CustomCLs.CustomURLClassLoader)9 CustomTokenClassLoader (CustomCLs.CustomTokenClassLoader)6 CustomURLClassLoader (CustomClassloaders.CustomURLClassLoader)5 CustomURLLoader (CustomClassloaders.CustomURLLoader)5 HelperAlreadyDefinedException (com.ibm.oti.shared.HelperAlreadyDefinedException)5 CustomPartitioningURLLoader (CustomCLs.CustomPartitioningURLLoader)3 SharedClassHelperFactory (com.ibm.oti.shared.SharedClassHelperFactory)3 SharedClassURLClasspathHelper (com.ibm.oti.shared.SharedClassURLClasspathHelper)3 Method (java.lang.reflect.Method)3 CustomPartitioningURLCL (CustomCLs.CustomPartitioningURLCL)2 CustomPartitioningURLClassLoader (CustomClassloaders.CustomPartitioningURLClassLoader)2 CustomPartitioningURLLoader (CustomClassloaders.CustomPartitioningURLLoader)2 CustomTokenClassLoader (CustomClassloaders.CustomTokenClassLoader)1 CannotSetClasspathException (com.ibm.oti.shared.CannotSetClasspathException)1