use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class ReflectiveReflectionTests method testJLRCGetAnnotation.
@Test
public void testJLRCGetAnnotation() throws Exception {
String t = "iri.JLRCGetAnnotation";
TypeRegistry r = getTypeRegistry(t);
ReloadableType rtype = r.addType(t, loadBytesForClass(t));
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("@reflection.AnnoT() null", result.returnValue);
rtype.loadNewVersion(retrieveRenameRetarget(t));
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("null @java.lang.Deprecated()", result.returnValue);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method invokevirtual.
@Test
public void invokevirtual() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("virtual.CalleeOne");
// The first target does not define toString()
ReloadableType target = typeRegistry.addType("virtual.CalleeOne", loadBytesForClass("virtual.CalleeOne"));
Class<?> callerClazz = loadit("virtual.CallerOne", loadBytesForClass("virtual.CallerOne"));
// Run the initial version which does not define toString()
Result result = runUnguarded(callerClazz, "run");
// something like virtual.CalleeOne@4cee32
assertTrue(((String) result.returnValue).startsWith("virtual.CalleeOne@"));
// Load a version that does define toString()
target.loadNewVersion("002", retrieveRename("virtual.CalleeOne", "virtual.CalleeOne002"));
result = runUnguarded(callerClazz, "run");
assertEquals("abcd", result.returnValue);
// Load a version that does not define toString()
target.loadNewVersion("003", retrieveRename("virtual.CalleeOne", "virtual.CalleeOne003"));
result = runUnguarded(callerClazz, "run");
// something like virtual.CalleeOne@4cee32
assertTrue(((String) result.returnValue).startsWith("virtual.CalleeOne@"));
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeInterface1.
/**
* Here an interface is changed (reloaded) to include a new method, the implementing class already provides an
* implementation.
*/
@Test
public void rewriteInvokeInterface1() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("tgt.SimpleIClass,tgt.SimpleI");
ReloadableType intface = typeRegistry.addType("tgt.SimpleI", loadBytesForClass("tgt.SimpleI"));
// ReloadableType impl =
typeRegistry.addType("tgt.SimpleIClass", loadBytesForClass("tgt.SimpleIClass"));
byte[] callerbytes = loadBytesForClass("tgt.StaticICaller");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("tgt.StaticICaller", rewrittenBytes);
// run the original
Result result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
intface.loadNewVersion("2", retrieveRename("tgt.SimpleI", "tgt.SimpleI002"));
// run the original working thing post-reload - check it is still ok
result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
callerbytes = loadBytesForClass("tgt.StaticICaller002");
callerbytes = ClassRenamer.rename("tgt.StaticICaller002", callerbytes, "tgt.SimpleI002:tgt.SimpleI");
rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz002 = loadit("tgt.StaticICaller002", rewrittenBytes);
result = runUnguarded(callerClazz002, "run");
assertEquals("42", result.returnValue);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method callingMethodIntroducedLaterReturningPrimitiveDouble.
@Test
public void callingMethodIntroducedLaterReturningPrimitiveDouble() 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, "callAppleRetDouble", new Object[] { 5.0d });
// Load a version of Apple that does define that method
apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
Result result = runUnguarded(callerClazz, "callAppleRetDouble", new Object[] { 3.0d });
assertEquals(6.0d, result.returnValue);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method privateMethodCallsAndInvokeSpecial2.
/**
* Rewriting invokespecial when used for private method access. Similar to the previous test but now we are deleting
* some of the methods on reload.
*/
@Test
public void privateMethodCallsAndInvokeSpecial2() throws Exception {
registry = getTypeRegistry("invokespecial..*");
ReloadableType t = loadType(registry, "invokespecial.ContainsPrivateCalls");
Class<?> clazz = t.getClazz();
Object o = clazz.newInstance();
Method m = clazz.getDeclaredMethod("callMyPrivates");
// Straightforward call, no reloading:
assertEquals("12123abctruez", m.invoke(o));
// Reload a version where a private method has been deleted
t.loadNewVersion("002", retrieveRename("invokespecial.ContainsPrivateCalls", "invokespecial.ContainsPrivateCalls002"));
// With the removal of the private method the code won't even compile without the call to it being removed,
// so it just works...
assertEquals("123abctruez", m.invoke(o));
}
Aggregations