Search in sources :

Example 6 with TestClassloaderWithRewriting

use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.

the class GroovyTests method basic5.

// Calling from one type to another, now the methods are non-static
@Test
public void basic5() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicE";
    String target = "simple.BasicETarget";
    TypeRegistry r = getTypeRegistry(t + "," + target);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    ReloadableType rtypeTarget = r.addType(target, loadBytesForClass(target));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    rtypeTarget.loadNewVersion("2", retrieveRename(target, target + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("foobar", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 7 with TestClassloaderWithRewriting

use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.

the class PluginTests method testSimplePlugin.

// Test a simple plugin that processes reload events
@Test
public void testSimplePlugin() throws Exception {
    binLoader = new TestClassloaderWithRewriting("meta1", true);
    String t = "simple.Basic";
    captureOn();
    TypeRegistry r = getTypeRegistry(t);
    String output = captureOff();
    assertContains("Instantiated ReloadEventProcessorPlugin1", output);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    captureOn();
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    output = captureOff();
    assertContains("Reloading: Loading new version of simple.Basic [2]", output);
    assertContains("ReloadEventProcessorPlugin1: reloadEvent(simple.Basic,simple.Basic,2)", output);
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("goodbye", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 8 with TestClassloaderWithRewriting

use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.

the class PluginTests method testPluginRerunStaticInitializerRequest2.

@Test
public void testPluginRerunStaticInitializerRequest2() throws Exception {
    binLoader = new TestClassloaderWithRewriting("metaNotExist", true);
    String t = "clinit.One";
    ReloadEventProcessorPlugin repp = new ReloadEventProcessorPlugin() {

        public void reloadEvent(String typename, Class<?> clazz, String encodedTimestamp) {
            System.out.println("Plugin: reloadEvent(" + typename + "," + clazz.getName() + "," + encodedTimestamp + ")");
        }

        public boolean shouldRerunStaticInitializer(String typename, Class<?> clazz, String encodedTimestamp) {
            System.out.println("Plugin: rerun request for " + typename);
            // if this were false, the result below would be 5!
            return true;
        }
    };
    try {
        Plugins.registerGlobalPlugin(repp);
        TypeRegistry r = getTypeRegistry(t);
        ReloadableType rtype = r.addType(t, loadBytesForClass(t));
        captureOn();
        rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
        String output = captureOff();
        System.out.println(output);
        assertContains("Reloading: Loading new version of clinit.One [2]", output);
        assertUniqueContains("Plugin: reloadEvent(clinit.One,clinit.One,2)", output);
        assertContains("Reloading: Loading new version of clinit.One [2]", output);
        assertUniqueContains("Plugin: rerun request for clinit.One", output);
        result = runUnguarded(rtype.getClazz(), "run");
        assertEquals("7", result.returnValue);
    } finally {
        Plugins.unregisterGlobalPlugin(repp);
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) ReloadEventProcessorPlugin(org.springsource.loaded.ReloadEventProcessorPlugin) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 9 with TestClassloaderWithRewriting

use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.

the class CglibProxyTests method setUp.

@Before
public void setUp() throws Exception {
    super.setup();
    GlobalConfiguration.reloadMessages = true;
    binLoader = new TestClassloaderWithRewriting(true, true, true);
//cglibLoader = new URLClassLoader(new URL[]{new File("../testdata/lib/cglib-nodep-2.2.jar").toURI().toURL()});
}
Also used : TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) Before(org.junit.Before)

Example 10 with TestClassloaderWithRewriting

use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.

the class PluginTests method testServicesFileWithPluginAndNoNewline.

@SuppressWarnings("unused")
@Test
public void testServicesFileWithPluginAndNoNewline() throws Exception {
    binLoader = new TestClassloaderWithRewriting("meta3", true);
    String t = "simple.Basic";
    captureOn();
    TypeRegistry r = getTypeRegistry(t);
    String output = captureOff();
    assertContains("Instantiated ReloadEventProcessorPlugin1", output);
}
Also used : TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Aggregations

TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)26 Test (org.junit.Test)24 TypeRegistry (org.springsource.loaded.TypeRegistry)24 ReloadableType (org.springsource.loaded.ReloadableType)22 InvocationTargetException (java.lang.reflect.InvocationTargetException)4 Ignore (org.junit.Ignore)3 ReloadEventProcessorPlugin (org.springsource.loaded.ReloadEventProcessorPlugin)3 Before (org.junit.Before)2