use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class FieldReloadingTests method defaultFields.
// The problem with default visibility fields is that the executors cannot see them. So we create accessors for
// these fields in the target types. If two types in a hierarchy declare the same field, then these accessor methods will be in an
// override relationship. The overriding accessors will be subject to virtual dispatch - but the runtime type should be
// correct so that the right one is called.
@Test
public void defaultFields() throws Exception {
TypeRegistry tr = getTypeRegistry("accessors..*");
ReloadableType top = tr.addType("accessors.DefaultFields", loadBytesForClass("accessors.DefaultFields"));
ReloadableType bottom = tr.addType("accessors.DefaultFieldsSub", loadBytesForClass("accessors.DefaultFieldsSub"));
ClassPrinter.print(top.bytesLoaded);
Object topInstance = top.getClazz().newInstance();
Result result = runOnInstance(top.getClazz(), topInstance, "a");
assertEquals(1, result.returnValue);
Object botInstance = bottom.getClazz().newInstance();
result = runOnInstance(bottom.getClazz(), botInstance, "a");
assertEquals(1, result.returnValue);
result = runOnInstance(bottom.getClazz(), botInstance, "b");
assertEquals(2, result.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method lambdaWithParameter.
@Test
public void lambdaWithParameter() throws Exception {
String t = "basic.LambdaB";
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(99L, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo");
rtype.loadNewVersion("002", renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(176L, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method streamWithLambdaInvokedVirtually.
// inner interface (for the invokeinterface BSM)
@Test
public void streamWithLambdaInvokedVirtually() throws Exception {
String t = "basic.StreamB";
TypeRegistry typeRegistry = getTypeRegistry("basic..*");
byte[] sc = loadBytesForClass(t);
ReloadableType rtype = typeRegistry.addType(t, sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "run");
assertEquals(3, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo");
rtype.loadNewVersion("002", renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(4, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class Java8Tests method lambdaWithTwoParameters.
@Test
public void lambdaWithTwoParameters() throws Exception {
String t = "basic.LambdaC";
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(6L, r.returnValue);
byte[] renamed = retrieveRename(t, t + "2", t + "2$Boo:" + t + "$Boo");
rtype.loadNewVersion("002", renamed);
r = runUnguarded(simpleClass, "run");
assertEquals(5L, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result 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]);
}
Aggregations