Search in sources :

Example 16 with TestClassloaderWithRewriting

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

the class GroovyTests method staticInitializerReloading5.

/**
	 * Loading a type and not immediately running the clinit.
	 * 
	 * <p>
	 * This is to cover the problem where some type is loaded but not immediately initialized, it is then reloaded
	 * before initialization (i.e. before the clinit has run). If it is a groovy type then we are going to poke at it
	 * during reloading (to clear some caches). This poking may trigger the clinit to run. Now, the helper methods (like
	 * those that setup the callsitecache) will be using the 'new version' but the clinit hasn't been redirected to the
	 * reloaded version and so it indexes into the callsite cache using wrong indices.
	 */
@Ignore
// until I can find time
@Test
public void staticInitializerReloading5() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "clinitg.Four";
    String t2 = "clinitg.FourHelper";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    // ReloadableType rtype2 =
    typeRegistry.addType(t2, loadBytesForClass(t2));
    // load it but do not initialize it
    typeRegistry.getClassLoader().loadClass(t);
    captureOn();
    byte[] renamed = retrieveRename(t, t + "2");
    // reload it, this will trigger initialization
    rtype.loadNewVersion("2", renamed);
    String s = captureOffReturnStdout();
    assertEquals("1a", s);
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1312", result.stdout);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 17 with TestClassloaderWithRewriting

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

the class GroovyTests method fieldsOnInstance.

@Test
public void fieldsOnInstance() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.Front";
    String b = "simple.Back";
    TypeRegistry r = getTypeRegistry(a + "," + b);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    ReloadableType rtypeb = r.addType(b, loadBytesForClass(b));
    Object instance = rtypea.getClazz().newInstance();
    result = runOnInstance(rtypea.getClazz(), instance, "run");
    assertEquals(35, result.returnValue);
    try {
        result = runOnInstance(rtypea.getClazz(), instance, "run2");
        fail();
    } catch (Exception e) {
    // success - var2 doesn't exist yet
    }
    // rtypea.fixupGroovyType();
    rtypeb.loadNewVersion("2", retrieveRename(b, b + "2"));
    result = runOnInstance(rtypea.getClazz(), instance, "run2");
    // The field will not be initialized, so will contain 0
    assertEquals(0, result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) Test(org.junit.Test)

Example 18 with TestClassloaderWithRewriting

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

the class GroovyTests method basic2.

// The method calls another method to get the return string, test
// that when the method we are calling changes, we do call the new
// one (simply checking the callsite cache is reset)
@Test
public void basic2() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicB";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    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 19 with TestClassloaderWithRewriting

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

the class GroovyTests method enums2.

/**
	 * Reloading enums - more complex enum (grails-7776)
	 */
@Test
public void enums2() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String enumtype = "enums.WhatAnEnumB";
    String intface = "enums.ExtensibleEnumB";
    String runner = "enums.RunnerB";
    String closure = "enums.WhatAnEnumB$__clinit__closure1";
    TypeRegistry typeRegistry = getTypeRegistry(enumtype + "," + intface + "," + runner + "," + closure);
    //		ReloadableType rtypeIntface =
    typeRegistry.addType(intface, loadBytesForClass(intface));
    ReloadableType rtypeClosure = typeRegistry.addType(closure, loadBytesForClass(closure));
    ReloadableType rtypeEnum = typeRegistry.addType(enumtype, loadBytesForClass(enumtype));
    ReloadableType rtypeRunner = typeRegistry.addType(runner, loadBytesForClass(runner));
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    assertContains("[PETS_AT_THE_DISCO 1 JUMPING_INTO_A_HOOP 2 HAVING_A_NICE_TIME 3 LIVING_ON_A_LOG 4 WHAT_DID_YOU_DO 5 UNKNOWN 0]", result.stdout);
    byte[] cs = retrieveRename(closure, "enums.WhatAnEnumB2$__clinit__closure1", "enums.WhatAnEnumB2:enums.WhatAnEnumB");
    rtypeClosure.loadNewVersion(cs);
    byte[] bs = retrieveRename(enumtype, enumtype + "2", "enums.WhatAnEnumB2$__clinit__closure1:enums.WhatAnEnumB$__clinit__closure1", "[Lenums/WhatAnEnumB2;:[Lenums/WhatAnEnumB;", "enums/WhatAnEnumB2:enums/WhatAnEnumB");
    rtypeEnum.loadNewVersion(bs);
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    System.out.println(result);
    assertContains("[PETS_AT_THE_DISCO 1 JUMPING_INTO_A_HOOP 2 HAVING_A_NICE_TIME 3 LIVING_ON_A_LOG 4 WHAT_DID_YOU_DO 5 WOBBLE 6 UNKNOWN 0]", result.stdout);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 20 with TestClassloaderWithRewriting

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

the class GroovyTests method reflection.

// test is too sensitive to changes between groovy compiler versions
@Ignore
@Test
public void reflection() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.SelfReflector";
    TypeRegistry r = getTypeRegistry(a);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    result = runUnguarded(rtypea.getClazz(), "run");
    assertEquals("14 $callSiteArray $class$java$lang$String $class$java$lang$StringBuilder $class$java$lang$reflect$Field $class$java$util$ArrayList $class$java$util$Collections $class$java$util$Iterator $class$java$util$List $class$simple$SelfReflector $staticClassInfo __$stMC array$$class$java$lang$reflect$Field i metaClass", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Ignore(org.junit.Ignore) 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