Search in sources :

Example 16 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class PartitioningURLHelperURLClassPathHelperStaleEntryCompatabilityTest method executeTest.

private boolean executeTest(String[] urls, String[] partitionStrings, String[][] classesToLoad, String classPath, String partition, 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();
    CustomPartitioningURLLoader[] loaderArray = new CustomPartitioningURLLoader[urls.length];
    for (int urlIndex = 0; urlIndex < urls.length; urlIndex++) {
        loaderArray[urlIndex] = new CustomPartitioningURLLoader(urlPath, this.getClass().getClassLoader());
        loaderArray[urlIndex].setPartition(partitionStrings[urlIndex]);
        for (int classIndex = 0; classIndex < classesToLoad[urlIndex].length; classIndex++) {
            String classToLoad = classesToLoad[urlIndex][classIndex];
            if (classToLoad != null) {
                loaderArray[urlIndex].loadClassFrom(classToLoad, urlIndex);
            }
        }
    }
    if (0 != batchFile.length()) {
        runBatchFile(batchFile, javacpath);
    }
    boolean result = true;
    URLClassPathCreator creator2 = new URLClassPathCreator(classPath);
    URL[] urlPath2;
    urlPath2 = creator2.createURLClassPath();
    CustomPartitioningURLClassLoader cl = new CustomPartitioningURLClassLoader(urlPath2, this.getClass().getClassLoader());
    cl.setPartition(partition);
    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 : CustomPartitioningURLClassLoader(CustomClassloaders.CustomPartitioningURLClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomPartitioningURLLoader(CustomClassloaders.CustomPartitioningURLLoader) URL(java.net.URL)

Example 17 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class TokenIncompatabilityTest 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");
    }
}
Also used : CustomURLLoader(CustomClassloaders.CustomURLLoader) CustomTokenClassLoader(CustomClassloaders.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomClassloaders.CustomURLClassLoader) URL(java.net.URL)

Example 18 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class URLClassPathHelperURLHelperCompatabilityTest 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;
}
Also used : CustomURLLoader(CustomClassloaders.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomClassloaders.CustomURLClassLoader) URL(java.net.URL)

Example 19 with URLClassPathCreator

use of Utilities.URLClassPathCreator in project openj9 by eclipse.

the class URLClassPathHelperURLHelperStaleEntryCompatabilityTest 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;
}
Also used : CustomURLLoader(CustomClassloaders.CustomURLLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomClassloaders.CustomURLClassLoader) URL(java.net.URL)

Example 20 with URLClassPathCreator

use of Utilities.URLClassPathCreator 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");
    }
}
Also used : CustomURLLoader(CustomCLs.CustomURLLoader) CustomTokenClassLoader(CustomCLs.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator) CustomURLClassLoader(CustomCLs.CustomURLClassLoader) URL(java.net.URL)

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