Search in sources :

Example 1 with CustomTokenClassLoader

use of CustomCLs.CustomTokenClassLoader in project openj9 by eclipse.

the class StaleMarkingTest method executeTest.

public boolean executeTest(String[] loaderPaths, String[][] classesToLoad, String findPath, String[] classesToFind, String[] results, String[] foundAt) {
    for (int index = 0; index < loaderPaths.length; index++) {
        URLClassPathCreator creator = new URLClassPathCreator(loaderPaths[index]);
        URL[] urlPath;
        urlPath = creator.createURLClassPath();
        CustomTokenClassLoader cl = new CustomTokenClassLoader(urlPath, this.getClass().getClassLoader());
        cl.setToken("StaleMarking");
        for (int classIndex = 0; classIndex < classesToLoad[index].length; classIndex++) {
            String classToLoad = classesToLoad[index][classIndex];
            if (classToLoad != null) {
                try {
                    cl.loadClassNoCache(classToLoad);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    boolean result = true;
    URLClassPathCreator creator = new URLClassPathCreator(findPath);
    URL[] findPathURLS;
    findPathURLS = creator.createURLClassPath();
    CustomTokenClassLoader vf = new CustomTokenClassLoader(findPathURLS, this.getClass().getClassLoader());
    vf.setToken("StaleMarking");
    for (int classIndex = 0; classIndex < classesToFind.length; classIndex++) {
        String classToFind = classesToFind[classIndex];
        String expectedResult = results[classIndex];
        if (classToFind != null) {
            String testResult = String.valueOf(vf.isClassInSharedCache("StaleMarking", 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], vf);
                }
            }
        }
    }
    return result;
}
Also used : CustomTokenClassLoader(CustomCLs.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator) URL(java.net.URL)

Example 2 with CustomTokenClassLoader

use of CustomCLs.CustomTokenClassLoader 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)

Example 3 with CustomTokenClassLoader

use of CustomCLs.CustomTokenClassLoader in project openj9 by eclipse.

the class TokenMultipleGetHelperCallTest method run.

public void run() {
    boolean result = false;
    URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;");
    CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());
    result = loader.getHelper();
    if (result == true) {
        System.out.println("\nTEST PASSED");
    } else {
        System.out.println("\nTEST FAILED");
    }
}
Also used : CustomTokenClassLoader(CustomCLs.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator)

Example 4 with CustomTokenClassLoader

use of CustomCLs.CustomTokenClassLoader in project openj9 by eclipse.

the class TokenGetDifferentHelperTest method run.

public void run() {
    boolean resultURL = false;
    boolean resultURLCP = false;
    URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;");
    CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());
    try {
        loader.getURLClasspathHelper();
    } catch (HelperAlreadyDefinedException e) {
        resultURLCP = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        loader.getURLHelper();
    } catch (HelperAlreadyDefinedException e) {
        resultURL = true;
    } catch (Exception e) {
        e.printStackTrace();
    }
    if ((resultURLCP == true) && (resultURL == true)) {
        System.out.println("\nTEST PASSED");
    } else {
        System.out.println("\nTEST FAILED");
    }
}
Also used : CustomTokenClassLoader(CustomCLs.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException) HelperAlreadyDefinedException(com.ibm.oti.shared.HelperAlreadyDefinedException)

Example 5 with CustomTokenClassLoader

use of CustomCLs.CustomTokenClassLoader in project openj9 by eclipse.

the class TokenStoreFindTest method run.

public void run() {
    boolean result = false;
    URLClassPathCreator pathCreator = new URLClassPathCreator("./Pets;");
    CustomTokenClassLoader loader = new CustomTokenClassLoader(pathCreator.createURLClassPath());
    String tok = "FindStore";
    String name = "Dog";
    loader.setToken(tok);
    try {
        loader.loadClass(name);
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
    result = loader.isClassInSharedCache(tok, name);
    if (result == true) {
        System.out.println("\nTEST PASSED");
    } else {
        System.out.println("\nTEST FAILED");
    }
}
Also used : CustomTokenClassLoader(CustomCLs.CustomTokenClassLoader) URLClassPathCreator(Utilities.URLClassPathCreator)

Aggregations

CustomTokenClassLoader (CustomCLs.CustomTokenClassLoader)6 URLClassPathCreator (Utilities.URLClassPathCreator)6 URL (java.net.URL)3 CustomURLClassLoader (CustomCLs.CustomURLClassLoader)1 CustomURLLoader (CustomCLs.CustomURLLoader)1 HelperAlreadyDefinedException (com.ibm.oti.shared.HelperAlreadyDefinedException)1