use of org.springsource.loaded.ReloadableType 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.ReloadableType in project spring-loaded by spring-projects.
the class CrossLoaderTests method loadTypesAcrossLoaders.
/**
* Check the basics - does the SubLoader/SuperLoader mechanism work.
*/
@Test
public void loadTypesAcrossLoaders() throws Exception {
ReloadableType rtypeA = subLoader.loadAsReloadableType("superpkg.Top");
result = runUnguarded(rtypeA.getClazz(), "m");
assertEquals("Top.m() running", result.stdout);
ReloadableType rtypeB = subLoader.loadAsReloadableType("subpkg.Bottom");
result = runUnguarded(rtypeB.getClazz(), "m");
assertEquals("Bottom.m() running", result.stdout);
assertNotSame(rtypeA.getTypeRegistry(), rtypeB.getTypeRegistry());
}
use of org.springsource.loaded.ReloadableType 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);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class DispatcherBuilderTests method staticMethod.
@Test
public void staticMethod() throws Exception {
String tclass = "dispatcher.Staticmethod";
TypeRegistry typeRegistry = getTypeRegistry(tclass);
ReloadableType rtype = typeRegistry.addType(tclass, loadBytesForClass(tclass));
// Simply reloads itself to trigger new version handling code paths in both infrastructure and generated code
rtype.loadNewVersion("2", rtype.bytesInitial);
// ClassPrinter.print(rtype.interfaceBytes);
// ClassPrinter.print(rtype.getLatestExecutorBytes());
byte[] callerbytes = loadBytesForClass("dispatcher.StaticmethodCaller");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("dispatcher.StaticmethodCaller", rewrittenBytes);
result = runUnguarded(callerClazz, "run");
Assert.assertTrue(result.stdout.indexOf("abc") != -1);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class EnumTests method testEnums1.
/**
* Test new values are visible on reload
*/
@Test
public void testEnums1() throws Exception {
String t = "enumtests.Colours";
String runner = "enumtests.RunnerA";
// Class<?> enumClazz =
binLoader.loadClass(t);
Class<?> runnerClazz = binLoader.loadClass(runner);
assertNotNull(runnerClazz);
// Check we loaded it as reloadable
ReloadableType rtype = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(t), false);
assertNotNull(rtype);
String output = runMethodAndCollectOutput(runnerClazz, "run1");
assertContains("Red", output);
assertContains("Green", output);
assertContains("Blue", output);
assertContains("[Red Green Blue]", output);
assertContains("value count = 3", output);
rtype.loadNewVersion(retrieveRename(t, t + "2"));
output = runMethodAndCollectOutput(runnerClazz, "run1");
assertContains("Red", output);
assertContains("Green", output);
assertContains("Blue", output);
assertContains("[Red Green Blue Yellow]", output);
assertContains("value count = 4", output);
}
Aggregations