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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations