use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class Java8Tests method lambdaMethodReference.
// https://github.com/spring-projects/spring-loaded/issues/87
@Test
public void lambdaMethodReference() throws Exception {
String t = "basic.LambdaM";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
byte[] sc = loadBytesForClass(t);
ReloadableType rtype = typeRegistry.addType(t, sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "run");
r = runUnguarded(simpleClass, "run");
assertEquals("{5=test3}", r.returnValue);
//, t + "2$Foo:" + t + "$Foo"));
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
r = runUnguarded(simpleClass, "run");
assertEquals("{10=test3}", r.returnValue);
}
use of org.springsource.loaded.ReloadableType 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.ReloadableType 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.ReloadableType 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.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method privateMethodCallsAndInvokeSpecial.
/**
* Rewriting invokespecial when used for private method access.
*/
@Test
public void privateMethodCallsAndInvokeSpecial() throws Exception {
registry = getTypeRegistry("invokespecial..*");
ReloadableType t = loadType(registry, "invokespecial.ContainsPrivateCalls");
// ReloadableType rt = loadType(tr, "invokespecial.Able2");
// ReloadableType st = loadType(tr, "invokespecial.Simple2");
Class<?> clazz = t.getClazz();
Object o = clazz.newInstance();
Method m = clazz.getDeclaredMethod("callMyPrivates");
// Straightforward call, no reloading:
assertEquals("12123abctruez", m.invoke(o));
// Reload itself, to cause executor creation:
reload(t, "001");
// Now the executor is being used. The INVOKESPECIALs in the code will be rewritten to invokestatic
// calls in the executor that is built
assertEquals("12123abctruez", m.invoke(o));
}
Aggregations