use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeInterface3.
/**
* Here an interface and the implementation are changed (to add a new method to both).
*/
@Test
public void rewriteInvokeInterface3() 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);
Result result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
// new interface on method and new implementation in the implementing class
intface.loadNewVersion("2", retrieveRename("tgt.SimpleI", "tgt.SimpleI003"));
impl.loadNewVersion("2", retrieveRename("tgt.SimpleIClass", "tgt.SimpleIClass003", "tgt.SimpleI003:tgt.SimpleI"));
// run the original working thing post-reload - check it is still ok
result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
callerbytes = loadBytesForClass("tgt.StaticICaller003");
callerbytes = ClassRenamer.rename("tgt.StaticICaller003", callerbytes, "tgt.SimpleI003:tgt.SimpleI", "tgt.SimpleIClass003:tgt.SimpleIClass");
rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz003 = loadit("tgt.StaticICaller003", rewrittenBytes);
result = runUnguarded(callerClazz003, "run");
assertEquals("2.01232768false", result.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeInterface4_methodDeletion.
/**
* A method is removed from an interface.
*/
@Test
public void rewriteInvokeInterface4_methodDeletion() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("tgt.SimpleIClass,tgt.SimpleI");
ReloadableType intface = typeRegistry.addType("tgt.SimpleI", loadBytesForClass("tgt.SimpleI"));
typeRegistry.addType("tgt.SimpleIClass", loadBytesForClass("tgt.SimpleIClass"));
byte[] callerbytes = loadBytesForClass("tgt.StaticICaller");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("tgt.StaticICaller", rewrittenBytes);
Result result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
// new interface version has method removed
intface.loadNewVersion("2", retrieveRename("tgt.SimpleI", "tgt.SimpleI004"));
try {
// run the original working thing post-reload - check it is still ok
result = runUnguarded(callerClazz, "run");
fail("Method no longer exists, should not have been callable");
} catch (InvocationTargetException ite) {
assertTrue(ite.getCause() instanceof NoSuchMethodError);
assertEquals("SimpleI.toInt(Ljava/lang/String;)I", ite.getCause().getMessage());
}
// new interface version has method re-added
intface.loadNewVersion("3", retrieveRename("tgt.SimpleI", "tgt.SimpleI"));
result = runUnguarded(callerClazz, "run");
assertEquals(123, result.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method lambdaInvokeVirtual.
@Test
public void lambdaInvokeVirtual() throws Exception {
String t = "basic.LambdaJ";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
// Since Foo needs promoting to public, have to ensure it is directly loaded:
ReloadableType itype = typeRegistry.addType(t + "$Foo", loadBytesForClass(t + "$Foo"));
byte[] sc = loadBytesForClass(t);
ReloadableType rtype = typeRegistry.addType(t, sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals("fooa", r.returnValue);
itype.loadNewVersion("002", retrieveRename(t + "$Foo", t + "2$Foo"));
rtype.loadNewVersion("002", retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo"));
r = runUnguarded(simpleClass, "run");
assertEquals("fooab", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method lambdaA.
@Test
public void lambdaA() throws Exception {
String t = "basic.LambdaA";
TypeRegistry typeRegistry = getTypeRegistry(t);
byte[] sc = loadBytesForClass(t);
ReloadableType rtype = typeRegistry.addType(t, sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals(77, r.returnValue);
rtype.loadNewVersion("002", rtype.bytesInitial);
r = runUnguarded(simpleClass, "run");
assertEquals(77, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method lambdaWithNonPublicInnerInterface.
@Test
public void lambdaWithNonPublicInnerInterface() throws Exception {
String t = "basic.LambdaG";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
// Since Boo needs promoting to public, have to ensure it is directly loaded:
typeRegistry.addType(t + "$Boo", loadBytesForClass(t + "$Boo"));
byte[] sc = loadBytesForClass(t);
ReloadableType rtype = typeRegistry.addType(t, sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals(99, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2", t + "2$Boo:" + t + "$Boo");
rtype.loadNewVersion("002", renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(44, r.returnValue);
}
Aggregations