use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method basicExternals.
/**
* Check properties of the newly created executor.
*/
@Test
public void basicExternals() throws Exception {
String t = "executor.TestOne";
TypeRegistry typeRegistry = getTypeRegistry(t);
ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
reload(rtype, "37");
Class<?> clazz = rtype.getLatestExecutorClass();
Assert.assertEquals(Utils.getExecutorName(t, "37"), clazz.getName());
Assert.assertEquals(3, clazz.getDeclaredMethods().length);
Assert.assertEquals(1, clazz.getDeclaredFields().length);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method staticInitializerReloading4.
/**
* Type that doesn't really have a clinit
*/
@Test
public void staticInitializerReloading4() throws Exception {
String t = "clinit.Three";
TypeRegistry typeRegistry = getTypeRegistry(t);
ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("1", result.returnValue);
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
rtype.runStaticInitializer();
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("1", result.returnValue);
rtype.loadNewVersion("3", retrieveRename(t, t + "3"));
rtype.runStaticInitializer();
result = runUnguarded(rtype.getClazz(), "run");
ClassPrinter.print(rtype.getLatestExecutorBytes());
assertEquals("4", result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method methodLevelAnnotations.
@Test
public void methodLevelAnnotations() throws Exception {
String t = "executor.B";
TypeRegistry typeRegistry = getTypeRegistry(t);
ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
reload(rtype, "37");
checkAnnotations(rtype.bytesLoaded, "m()V", "@common.Marker()");
checkAnnotations(rtype.bytesLoaded, "m2()V");
checkAnnotations(rtype.getLatestExecutorBytes(), "m(Lexecutor/B;)V", "@common.Marker()");
checkAnnotations(rtype.getLatestExecutorBytes(), "m2(Lexecutor/B;)V");
rtype.loadNewVersion("39", retrieveRename("executor.B", "executor.B2"));
checkAnnotations(rtype.getLatestExecutorBytes(), "m(Lexecutor/B;)V");
checkAnnotations(rtype.getLatestExecutorBytes(), "m2(Lexecutor/B;)V", "@common.Marker()", "@common.Anno(id=abc)");
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class CrossLoaderTests method reloadTargetInSuperloader.
/**
* In a class loaded by the subloader, calling a new method in a class loaded by the superloader. (ivicheck)
*/
@Test
public void reloadTargetInSuperloader() throws Exception {
String target = "superpkg.Target";
String invoker = "subpkg.Invoker";
ReloadableType targetR = subLoader.loadAsReloadableType(target);
ReloadableType invokerR = subLoader.loadAsReloadableType(invoker);
targetR.loadNewVersion("2", retrieveRename(target, target + "002"));
invokerR.loadNewVersion("2", retrieveRename(invoker, invoker + "002", target + "002:" + target));
// Check the registry looks right for target
int targetId = NameRegistry.getIdFor(toSlash(target));
assertEquals(0, targetId);
TypeRegistry trtarget = TypeRegistry.getTypeRegistryFor(subLoader.getParent());
assertEquals(target, trtarget.getReloadableType(targetId).getName());
assertEquals(target, trtarget.getReloadableType(toSlash(target)).getName());
int invokerId = NameRegistry.getIdFor(toSlash(invoker));
TypeRegistry trinvokerR = TypeRegistry.getTypeRegistryFor(subLoader);
assertEquals(1, invokerId);
assertEquals(invoker, trinvokerR.getReloadableType(invokerId).getName());
assertEquals(invoker, trinvokerR.getReloadableType(toSlash(invoker)).getName());
// Now call the run() in the Invoker type, which calls 'Target.m()' where Target is in a different loader
// and has been reloaded
result = runUnguarded(invokerR.getClazz(), "run");
assertEquals("Target002.m() running", result.stdout);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class DebuggingTests method rewrite.
@Test
public void rewrite() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorld");
ReloadableType rtype = typeRegistry.addType("data.HelloWorld", loadBytesForClass("data.HelloWorld"));
runUnguarded(rtype.getClazz(), "greet");
// Just transform the existing version into a dispatcher/executor
rtype.loadNewVersion("000", rtype.bytesInitial);
Assert.assertEquals("Greet from HelloWorld", runUnguarded(rtype.getClazz(), "greet").stdout);
// Load a real new version
rtype.loadNewVersion("002", retrieveRename("data.HelloWorld", "data.HelloWorld002"));
Assert.assertEquals("Greet from HelloWorld 2", runUnguarded(rtype.getClazz(), "greet").stdout);
// ClassPrinter.print(rtype.getLatestExecutorBytes());
// ClassPrinter.print(rtype.bytesInitial);
}
Aggregations