use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class Java8Tests method defaultMethods2.
// A class implements an interface. A default method is added to the interface on
// a reload and invoked from a reloaded version of the class.
@Ignore
@Test
public void defaultMethods2() throws Exception {
String t = "basic.DefaultMethodsI2A";
String t2 = "basic.DefaultMethodsC2A";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
byte[] ia = loadBytesForClass(t);
ReloadableType rtypeI = typeRegistry.addType(t, ia);
byte[] ca = loadBytesForClass(t2);
ReloadableType rtypeC = typeRegistry.addType(t2, ca);
Class<?> simpleClass = rtypeC.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
// byte[] renamed = retrieveRename(t, t + "2");
rtypeI.loadNewVersion("002", ia);
// ClassPrinter.print(rtypeI.getBytesLoaded());
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2");
rtypeI.loadNewVersion(renamed);
renamed = retrieveRename(t2, t2 + "2", t + "2:" + t);
rtypeC.loadNewVersion(renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(42, r.returnValue);
assertEquals("FOO", r.stdout);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method invokevirtual2.
/**
* Two classes in a hierarchy, both reloadable. Neither of them defines a toString(), what happens as we reload
* versions of them adding then removing toString().
*/
@Test
public void invokevirtual2() throws Exception {
String caller = "virtual.CallerTwo";
String top = "virtual.CalleeTwoTop";
String bottom = "virtual.CalleeTwoBottom";
TypeRegistry typeRegistry = getTypeRegistry(top + "," + bottom);
// The first target does not define toString()
ReloadableType reloadableTop = typeRegistry.addType(top, loadBytesForClass(top));
// ReloadableType reloadableBottom =
typeRegistry.addType(bottom, loadBytesForClass(bottom));
Class<?> callerClazz = loadit(caller, loadBytesForClass(caller));
Result result = null;
result = runUnguarded(callerClazz, "runTopToString");
assertTrue(((String) result.returnValue).startsWith("virtual.CalleeTwoTop@"));
result = runUnguarded(callerClazz, "runBottomToString");
assertTrue(((String) result.returnValue).startsWith("virtual.CalleeTwoBottom@"));
reloadableTop.loadNewVersion("002", retrieveRename(top, top + "002"));
result = runUnguarded(callerClazz, "runTopToString");
assertTrue(((String) result.returnValue).startsWith("topToString"));
result = runUnguarded(callerClazz, "runBottomToString");
// still no impl in bottom, so hits top
assertTrue(((String) result.returnValue).startsWith("topToString"));
// remove it again
reloadableTop.loadNewVersion("003", retrieveRename(top, top + "003"));
result = runUnguarded(callerClazz, "runBottomToString");
assertTrue(((String) result.returnValue).startsWith("virtual.CalleeTwoBottom@"));
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method invokevirtualNonCatchers.
/**
* Testing what happens when reloading introduces a new method in the supertype that is called from the subtype.
*/
@Test
public void invokevirtualNonCatchers() 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);
topR.loadNewVersion(retrieveRename(top, top + "2"));
botR.loadNewVersion(retrieveRename(bot, bot + "2", top + "2:" + top));
// now 'run()' should be invoking super.bar() where bar() is a new method
// introduced into FourTop
result = runUnguarded(botR.getClazz(), "run");
assertEquals(77, result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method invokevirtualNonCatchers3.
/**
* Similar to previous test but now new method is in the middle of the hierarchy (and in the top, but the middle one
* should be answering the request)
*/
@Test
public void invokevirtualNonCatchers3() throws Exception {
String top = "virtual.FourTopC";
String mid = "virtual.FourMidC";
String bot = "virtual.FourBotC";
TypeRegistry typeRegistry = getTypeRegistry(top + "," + bot);
ReloadableType topR = typeRegistry.addType(top, loadBytesForClass(top));
ReloadableType midR = typeRegistry.addType(mid, loadBytesForClass(mid));
ReloadableType botR = typeRegistry.addType(bot, loadBytesForClass(bot));
result = runUnguarded(botR.getClazz(), "run");
assertEquals(42, result.returnValue);
topR.loadNewVersion(retrieveRename(top, top + "2"));
midR.loadNewVersion(retrieveRename(mid, mid + "2", top + "2:" + top));
botR.loadNewVersion(retrieveRename(bot, bot + "2", mid + "2:" + mid));
// now 'run()' should be invoking super.bar() where bar() is a new method
// introduced into FourTop
result = runUnguarded(botR.getClazz(), "run");
assertEquals(99, result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method rewriteInvokeInterface5_paramsChanged.
/**
* A method is changed on an interface - parameter type change.
*/
@Test
public void rewriteInvokeInterface5_paramsChanged() 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 version has method removed
intface.loadNewVersion("2", retrieveRename("tgt.SimpleI", "tgt.SimpleI005"));
impl.loadNewVersion("2", retrieveRename("tgt.SimpleIClass", "tgt.SimpleIClass005", "tgt.SimpleI005:tgt.SimpleI"));
callerbytes = loadBytesForClass("tgt.StaticICaller005");
callerbytes = ClassRenamer.rename("tgt.StaticICaller005", callerbytes, "tgt.SimpleI005:tgt.SimpleI", "tgt.SimpleIClass005:tgt.SimpleIClass", "tgt.SimpleIClass005:tgt.SimpleIClass");
rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
callerClazz = loadit("tgt.StaticICaller005", rewrittenBytes);
result = runUnguarded(callerClazz, "run");
assertEquals(72, result.returnValue);
}
Aggregations