use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeStatic3.
/**
* Reloading target with a new static method that takes no parameters.
*/
@Test
public void rewriteInvokeStatic3() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("tgt.SimpleClass");
ReloadableType callee = typeRegistry.addType("tgt.SimpleClass", loadBytesForClass("tgt.SimpleClass"));
byte[] callerbytes = loadBytesForClass("tgt.StaticCaller");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("tgt.StaticCaller", rewrittenBytes);
// run the original
Result result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
callerbytes = loadBytesForClass("tgt.StaticCaller003");
callerbytes = ClassRenamer.rename("tgt.StaticCaller003", callerbytes, "tgt.SimpleClass003:tgt.SimpleClass");
rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz002 = loadit("tgt.StaticCaller003", rewrittenBytes);
callee.loadNewVersion("3", retrieveRename("tgt.SimpleClass", "tgt.SimpleClass003"));
result = runUnguarded(callerClazz002, "run3");
assertEquals("42", result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method basicRewriteSingleNonStaticMethodCallNoArgumentsNoReturn2.
// Exercising the rewritten code
@Test
public void basicRewriteSingleNonStaticMethodCallNoArgumentsNoReturn2() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.Apple");
ReloadableType target = typeRegistry.addType("data.Apple", loadBytesForClass("data.Apple"));
byte[] callerbytes = loadBytesForClass("data.Orange");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("data.Orange", rewrittenBytes);
// run the original
result = runUnguarded(callerClazz, "one");
assertEquals("Apple.run() is running", result.stdout);
target.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
result = runUnguarded(callerClazz, "one");
assertEquals("Apple002.run() is running", result.stdout);
// run a modified version
// remove the target method - should fail
// replace the target method - should recover
// run(orangeClazz,"oneCodeBefore");
// run(orangeClazz,"oneCodeAfter");
// run(orangeClazz,"oneCodeBeforeAndAfter");
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method callingMethodIntroducedLaterReturningPrimitiveBoolean.
@Test
public void callingMethodIntroducedLaterReturningPrimitiveBoolean() throws Exception {
TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
// Configure it directly such that data.Apple is considered reloadable
configureForTesting(typeRegistry, "data.Apple");
ReloadableType apple = typeRegistry.addType("data.Apple", loadBytesForClass("data.Apple"));
byte[] callerbytes = loadBytesForClass("data.Orange002");
callerbytes = ClassRenamer.rename("data.Orange", callerbytes, "data.Apple002:data.Apple");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("data.Orange", rewrittenBytes);
runExpectNoSuchMethodException(callerClazz, "callAppleRetBoolean", new Object[] { true });
// Load a version of Apple that does define that method
apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
Result result = runUnguarded(callerClazz, "callAppleRetBoolean", new Object[] { true });
assertEquals(false, result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeInterface2.
/**
* Variant of the above where there is a parameter.
*/
@Test
public void rewriteInvokeInterface2() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("tgt.SimpleIClassTwo,tgt.SimpleITwo");
ReloadableType intface = typeRegistry.addType("tgt.SimpleITwo", loadBytesForClass("tgt.SimpleITwo"));
// ReloadableType impl =
typeRegistry.addType("tgt.SimpleIClassTwo", loadBytesForClass("tgt.SimpleIClassTwo"));
byte[] callerbytes = loadBytesForClass("tgt.StaticICallerTwo");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("tgt.StaticICallerTwo", rewrittenBytes);
// run the original
Result result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
intface.loadNewVersion("2", retrieveRename("tgt.SimpleITwo", "tgt.SimpleITwo002"));
result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
callerbytes = loadBytesForClass("tgt.StaticICallerTwo002");
callerbytes = ClassRenamer.rename("tgt.StaticICallerTwo002", callerbytes, "tgt.SimpleITwo002:tgt.SimpleITwo");
rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz002 = loadit("tgt.StaticICallerTwo002", rewrittenBytes);
// ClassPrinter.print(rewrittenBytes);
// callee.loadNewVersion("2", retrieveRename("tgt.SimpleClass", "tgt.SimpleClass002"));
result = runUnguarded(callerClazz002, "run");
assertEquals("27", result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method callingMethodIntroducedLaterReturningPrimitiveByte.
@Test
public void callingMethodIntroducedLaterReturningPrimitiveByte() throws Exception {
TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
// Configure it directly such that data.Apple is considered reloadable
configureForTesting(typeRegistry, "data.Apple");
ReloadableType apple = typeRegistry.addType("data.Apple", loadBytesForClass("data.Apple"));
byte[] callerbytes = loadBytesForClass("data.Orange002");
callerbytes = ClassRenamer.rename("data.Orange", callerbytes, "data.Apple002:data.Apple");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("data.Orange", rewrittenBytes);
runExpectNoSuchMethodException(callerClazz, "callAppleRetByte", new Object[] { (byte) 54 });
// Load a version of Apple that does define that method
apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
Result result = runUnguarded(callerClazz, "callAppleRetByte", new Object[] { (byte) 32 });
assertEquals((byte) 64, result.returnValue);
}
Aggregations