use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method invokevirtualNonCatchersErrorScenario.
@Test
public void invokevirtualNonCatchersErrorScenario() throws Exception {
String top = "virtual.FourTop";
String bot = "virtual.FourBot";
TypeRegistry typeRegistry = getTypeRegistry(top + "," + bot);
// The first top does not define foo()
// ReloadableType topR =
typeRegistry.addType(top, loadBytesForClass(top));
ReloadableType botR = typeRegistry.addType(bot, loadBytesForClass(bot));
result = runUnguarded(botR.getClazz(), "run");
assertEquals(42, result.returnValue);
// Dont load new Top, which means the new method that the subtype will call
// will not exist
// topR.loadNewVersion(retrieveRename(top, top + "2"));
botR.loadNewVersion(retrieveRename(bot, bot + "2", top + "2:" + top));
// introduced into FourTop
try {
result = runUnguarded(botR.getClazz(), "run");
fail("Should have failed!");
} catch (InvocationTargetException ite) {
assertTrue(ite.getCause() instanceof NoSuchMethodError);
assertEquals("FourBot.bar()I", ite.getCause().getMessage());
}
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method callingMethodIntroducedLaterReturningReferenceArray.
@Test
public void callingMethodIntroducedLaterReturningReferenceArray() 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, "callAppleRetArrayString", new Object[] { new String[] { "abc" } });
// Load a version of Apple that does define that method
apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
Result result = runUnguarded(callerClazz, "callAppleRetArrayString", new Object[] { new String[] { "abc", "def" } });
assertEquals("abc", ((String[]) result.returnValue)[0]);
}
use of org.springsource.loaded.ReloadableType 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.ReloadableType 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.ReloadableType in project spring-loaded by spring-projects.
the class FieldReloadingTests method newFieldAdded.
// Field 'i' is added to Add on a reload and interacted with
@Test
public void newFieldAdded() throws Exception {
TypeRegistry r = getTypeRegistry("fields.Add");
ReloadableType add = loadType(r, "fields.Add");
Class<?> addClazz = add.getClazz();
Object addInstance = addClazz.newInstance();
assertEquals(0, runOnInstance(addClazz, addInstance, "getValue").returnValue);
// ClassPrinter.print(add.bytesLoaded, true);
add.loadNewVersion("2", retrieveRename("fields.Add", "fields.Add002"));
assertEquals(0, runOnInstance(addClazz, addInstance, "getValue").returnValue);
runOnInstance(addClazz, addInstance, "setValue", 45);
assertEquals(45, runOnInstance(addClazz, addInstance, "getValue").returnValue);
assertEquals(45, add.getField(addInstance, "i", false));
}
Aggregations