use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class TypeRewriterTests method rewriteWithPrimitiveReturnValues_char.
@Test
public void rewriteWithPrimitiveReturnValues_char() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorldPrimitive");
ReloadableType rtype = typeRegistry.addType("data.HelloWorldPrimitive", loadBytesForClass("data.HelloWorldPrimitive"));
Result r = runUnguarded(rtype.getClazz(), "getValueChar");
assertTrue(r.returnValue instanceof Character);
assertEquals('c', r.returnValue);
rtype.loadNewVersion("000", rtype.bytesInitial);
r = runUnguarded(rtype.getClazz(), "getValueChar");
assertTrue(r.returnValue instanceof Character);
assertEquals('c', r.returnValue);
rtype.loadNewVersion("002", retrieveRename("data.HelloWorldPrimitive", "data.HelloWorldPrimitive002"));
r = runUnguarded(rtype.getClazz(), "getValueChar");
assertTrue(r.returnValue instanceof Character);
assertEquals('f', r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class TypeRewriterTests method rewriteStaticWithParams.
@Test
public void rewriteStaticWithParams() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorld");
ReloadableType rtype = typeRegistry.addType("data.HelloWorld", loadBytesForClass("data.HelloWorld"));
Result r = runUnguarded(rtype.getClazz(), "getStaticValueWithParams", "aaa", "bb");
assertTrue(r.returnValue instanceof String);
assertEquals("static message with inserts aaa and bb", r.returnValue);
rtype.loadNewVersion("000", rtype.bytesInitial);
r = runUnguarded(rtype.getClazz(), "getStaticValueWithParams", "c", "d");
assertTrue(r.returnValue instanceof String);
assertEquals("static message with inserts c and d", r.returnValue);
rtype.loadNewVersion("002", retrieveRename("data.HelloWorld", "data.HelloWorld002"));
r = runUnguarded(rtype.getClazz(), "getStaticValueWithParams", "aaa", "bb");
assertTrue(r.returnValue instanceof String);
assertEquals("static message with inserts bb and aaa", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class TypeRewriterTests method rewriteWithPrimitiveReturnValues_byte.
@Test
public void rewriteWithPrimitiveReturnValues_byte() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorldPrimitive");
ReloadableType rtype = typeRegistry.addType("data.HelloWorldPrimitive", loadBytesForClass("data.HelloWorldPrimitive"));
Result r = runUnguarded(rtype.getClazz(), "getValueByte");
assertTrue(r.returnValue instanceof Byte);
assertEquals((byte) 3, r.returnValue);
rtype.loadNewVersion("000", rtype.bytesInitial);
r = runUnguarded(rtype.getClazz(), "getValueByte");
assertTrue(r.returnValue instanceof Byte);
assertEquals((byte) 3, r.returnValue);
rtype.loadNewVersion("002", retrieveRename("data.HelloWorldPrimitive", "data.HelloWorldPrimitive002"));
r = runUnguarded(rtype.getClazz(), "getValueByte");
assertTrue(r.returnValue instanceof Byte);
assertEquals((byte) 6, r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class TypeRewriterTests method rewriteStaticWithPrimitiveParams.
@Test
public void rewriteStaticWithPrimitiveParams() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorld");
ReloadableType rtype = typeRegistry.addType("data.HelloWorld", loadBytesForClass("data.HelloWorld"));
Result r = runUnguarded(rtype.getClazz(), "getStaticValueWithPrimitiveParams", "a", 2, 'c');
assertTrue(r.returnValue instanceof String);
assertEquals("message with inserts a and 2 and c", r.returnValue);
rtype.loadNewVersion("000", rtype.bytesInitial);
r = runUnguarded(rtype.getClazz(), "getStaticValueWithPrimitiveParams", "a", 2, 'c');
assertTrue(r.returnValue instanceof String);
assertEquals("message with inserts a and 2 and c", r.returnValue);
rtype.loadNewVersion("002", retrieveRename("data.HelloWorld", "data.HelloWorld002"));
r = runUnguarded(rtype.getClazz(), "getStaticValueWithPrimitiveParams", "a", 2, 'c');
assertTrue(r.returnValue instanceof String);
assertEquals("message with inserts c and 2 and a", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class TypeRewriterTests method newConstructors2.
/**
* Super/subtypes and in the reload the new constructor in the subtype calls a constructor in the supertype that did
* not initially exist. I think the rewrite of the invokespecial should be able to determine it isn't there at the
* start and use the all powerful _execute method added to the instance at startup (rather than the ___init___)
* which will then call through the dispatcher.
*/
@Test
public void newConstructors2() throws Exception {
String caller = "ctors.CallerB";
String callee = "ctors.CalleeB";
String calleeSuper = "ctors.CalleeSuperB";
TypeRegistry r = getTypeRegistry(caller + "," + callee + "," + calleeSuper);
ReloadableType rcaller = r.addType(caller, loadBytesForClass(caller));
ReloadableType rcalleeSuper = r.addType(calleeSuper, loadBytesForClass(calleeSuper));
ReloadableType rcallee = r.addType(callee, loadBytesForClass(callee));
Result res = null;
// Use the code 'untouched'
Object callerInstance = rcaller.getClazz().newInstance();
res = runOnInstance(rcaller.getClazz(), callerInstance, "runA");
assertEquals("callee", res.returnValue.toString());
// Reload the code, a new constructor in the callee and runB() invokes it
rcalleeSuper.loadNewVersion("002", retrieveRename(calleeSuper, calleeSuper + "2"));
rcaller.loadNewVersion("002", retrieveRename(caller, caller + "2", "ctors.CalleeB2:ctors.CalleeB"));
rcallee.loadNewVersion("002", retrieveRename(callee, callee + "2", "ctors.CalleeSuperB2:ctors.CalleeSuperB"));
// The new runB() method will include a call 'new Callee("abcde")'
// Without a rewrite, it will cause this problem:
// Caused by: java.lang.NoSuchMethodError: ctors.Callee.<init>(Ljava/lang/String;)V
// at ctors.Caller__E002.runB(Caller2.java:10)
// This new Callee constructor also invokes a constructor in the supertype that wasn't there initially
res = runOnInstance(rcaller.getClazz(), callerInstance, "runB");
assertEquals("callee", res.returnValue.toString());
assertContains("Super number was 32768", res.toString());
assertContains("abcde", res.toString());
}
Aggregations