use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method invokeStaticReloading_gh4_5.
// The supertype is not reloadable,it is in a jar
@Test
public void invokeStaticReloading_gh4_5() throws Exception {
TypeRegistry tr = getTypeRegistry("invokestatic.issue4..*");
ReloadableType B = tr.addType("invokestatic.issue4.BBBB", loadBytesForClass("invokestatic.issue4.BBBB"));
Result r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("Hello", r.returnValue);
ReloadableType thesuper = B.getSuperRtype();
assertNull(thesuper);
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 serialization2.
// Unlike the first test, this one will reload the class in between serialize and deserialize
@Test
public void serialization2() throws Exception {
TypeRegistry tr = getTypeRegistry("remote..*");
ReloadableType person = tr.addType("remote.Person", loadBytesForClass("remote.Person"));
// byteinfo:len=98:crc=7e07276a
ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
Class<?> clazz = runner.getClazz();
Object instance = clazz.newInstance();
Result r = null;
// Basic: write and read the same Person
r = runOnInstance(clazz, instance, "writePerson");
assertStdoutContains("Person stored ok", r);
r = runOnInstance(clazz, instance, "readPerson");
assertContains("Person read ok", r.stdout);
// Advanced: write it, reload, then read back from the written form
r = runOnInstance(clazz, instance, "writePerson");
assertStdoutContains("Person stored ok", r);
person.loadNewVersion("2", retrieveRename("remote.Person", "remote.Person2"));
r = runOnInstance(clazz, instance, "readPerson");
assertContains("Person read ok", r.stdout);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method useReloadingAPI.
@Test
public void useReloadingAPI() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("basic.Basic");
byte[] sc = loadBytesForClass("basic.Basic");
ReloadableType rtype = typeRegistry.addType("basic.Basic", sc);
Class<?> simpleClass = rtype.getClazz();
Result r = runUnguarded(simpleClass, "foo");
r = runUnguarded(simpleClass, "getValue");
assertEquals(5, r.returnValue);
int rc = SpringLoaded.loadNewVersionOfType(rtype.getClazz(), retrieveRename("basic.Basic", "basic.Basic002"));
assertEquals(0, rc);
assertEquals(7, runUnguarded(simpleClass, "getValue").returnValue);
rc = SpringLoaded.loadNewVersionOfType(rtype.getClazz().getClassLoader(), rtype.dottedtypename, retrieveRename("basic.Basic", "basic.Basic003"));
assertEquals(0, rc);
assertEquals(3, runUnguarded(simpleClass, "getValue").returnValue);
// null classloader
rc = SpringLoaded.loadNewVersionOfType(null, rtype.dottedtypename, retrieveRename("basic.Basic", "basic.Basic003"));
assertEquals(1, rc);
// fake typename
rc = SpringLoaded.loadNewVersionOfType(rtype.getClazz().getClassLoader(), "a.b.C", retrieveRename("basic.Basic", "basic.Basic003"));
assertEquals(2, rc);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method serialization1.
// Basic write/read then reload then write/read again
@Test
public void serialization1() 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
// Tried running the Serialize code directly but with a clinit in the Person class: 2b4c0df4
ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
Result r = null;
r = runUnguarded(runner.getClazz(), "run");
assertContains("check ok", r.stdout);
person.loadNewVersion("2", retrieveRename("remote.Person", "remote.Person2"));
r = runUnguarded(runner.getClazz(), "run");
assertContains("check ok", r.stdout);
}
use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.
the class ReloadableTypeTests method invokeStaticReloading_gh4_2.
@Test
public void invokeStaticReloading_gh4_2() throws Exception {
TypeRegistry tr = getTypeRegistry("invokestatic..*");
tr.addType("invokestatic.issue4.AA", loadBytesForClass("invokestatic.issue4.AA"));
ReloadableType BB = tr.addType("invokestatic.issue4.BB", loadBytesForClass("invokestatic.issue4.BB"));
Result r = runUnguarded(BB.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
BB.loadNewVersion(BB.bytesInitial);
r = runUnguarded(BB.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
}
Aggregations