use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method invokeStaticReloading_gh4_6.
// extra class in the middle: A in jar, subtype AB reloadable, subtype BBBBB reloadable
@Test
public void invokeStaticReloading_gh4_6() throws Exception {
TypeRegistry tr = getTypeRegistry("invokestatic.issue4..*");
tr.addType("invokestatic.issue4.AB", loadBytesForClass("invokestatic.issue4.AB"));
ReloadableType B = tr.addType("invokestatic.issue4.BBBBB", loadBytesForClass("invokestatic.issue4.BBBBB"));
Result r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("Hello", r.returnValue);
ReloadableType thesuper = B.getSuperRtype();
thesuper = tr.getReloadableType("invokestatic/issue4/subpkg/AAAA");
assertNull(thesuper);
B.loadNewVersion(B.bytesInitial);
r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("Hello", r.returnValue);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method serialization3.
// Variant of the second test but using serialVersionUID and adding methods to the class on reload
@Test
public void serialization3() throws Exception {
TypeRegistry tr = getTypeRegistry("remote..*");
ReloadableType person = tr.addType("remote.PersonB", loadBytesForClass("remote.PersonB"));
ReloadableType runner = tr.addType("remote.SerializeB", loadBytesForClass("remote.SerializeB"));
Class<?> clazz = runner.getClazz();
Object instance = clazz.newInstance();
Result r = null;
// Basic: write and read the same Person
r = runOnInstance(runner.getClazz(), instance, "writePerson");
assertStdoutContains("Person stored ok", r);
r = runOnInstance(runner.getClazz(), instance, "readPerson");
assertContains("Person read ok", r.stdout);
// Advanced: write it, reload, then read back from the written form
r = runOnInstance(runner.getClazz(), instance, "writePerson");
assertStdoutContains("Person stored ok", r);
person.loadNewVersion("2", retrieveRename("remote.PersonB", "remote.PersonB2"));
r = runOnInstance(runner.getClazz(), instance, "readPerson");
assertContains("Person read ok", r.stdout);
r = runOnInstance(clazz, instance, "printInitials");
assertContains("Person read ok\nWS", r.stdout);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method serialization4.
// Deserialize something we serialized earlier
// This test cannot work without the agent. The agent must intercept java.lang.ObjectStream and its use of reflection
// There is a test that will work in the SpringLoadedTestsInSeparateJVM
public void serialization4() throws Exception {
TypeRegistry tr = getTypeRegistry("remote..*");
// ReloadableType person =
tr.addType("remote.Person", loadBytesForClass("remote.Person"));
// When the Serialize class is run directly, we see: byteinfo:len=98:crc=c1047cf6
// When run via this test, we see: byteinfo:len=98:crc=7e07276a
ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
Class<?> clazz = runner.getClazz();
Object instance = clazz.newInstance();
Result r = runOnInstance(clazz, instance, "checkPredeserializedData");
assertStdoutContains("Person stored ok", r);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class SpringLoadedTests method runUnguarded.
public Result runUnguarded(Class<?> clazz, String methodname, Object... params) throws InstantiationException, IllegalAccessException, SecurityException, NoSuchMethodException, IllegalArgumentException, InvocationTargetException {
PrintStream oldo = System.out;
PrintStream olde = System.err;
Object result = null;
ByteArrayOutputStream oso = new ByteArrayOutputStream();
ByteArrayOutputStream ose = new ByteArrayOutputStream();
try {
if (capture) {
System.setOut(new PrintStream(oso));
System.setErr(new PrintStream(ose));
}
Object o = clazz.newInstance();
Method m = null;
Method[] ms = clazz.getMethods();
for (Method mm : ms) {
if (mm.getName().equals(methodname)) {
m = mm;
break;
}
}
if (m == null) {
Assert.fail("Invocation failure: could not find method '" + methodname + "' on type '" + clazz.getName());
}
m.setAccessible(true);
result = m.invoke(o, params);
} finally {
if (capture) {
System.setOut(oldo);
System.setErr(olde);
}
}
return new Result(result, oso.toString().replace("\r", ""), ose.toString().replace("\r", ""));
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ExecutionContextsTest method test.
@Override
public Result test() throws ResultException, RejectedChoice, Exception {
//Check that each context is loading the correct version of the class
if (version.equals("")) {
try {
getDeclaredMethod();
Assert.fail("lateMethod should not exist in first version of the test");
} catch (NoSuchMethodException e) {
//OK
}
} else {
Method m = getDeclaredMethod();
Assert.assertEquals("lateMethod", m.getName());
}
//Check that tests are generated/executed in the order they are presumed to:
checkTestHistory();
return new Result(targetTypeName, "", "");
}
Aggregations