use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ReloadableTypeTests method invokeStaticReloading_gh4_1.
// github issue 4
@Test
public void invokeStaticReloading_gh4_1() throws Exception {
TypeRegistry tr = getTypeRegistry("invokestatic..*");
tr.addType("invokestatic.issue4.A", loadBytesForClass("invokestatic.issue4.A"));
ReloadableType B = tr.addType("invokestatic.issue4.B", loadBytesForClass("invokestatic.issue4.B"));
Result r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
B.loadNewVersion(B.bytesInitial);
r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ReloadableTypeTests method callIt.
/**
* Check calling it, reloading it and calling the new version.
*/
@Test
public void callIt() 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);
rtype.loadNewVersion("002", retrieveRename("basic.Basic", "basic.Basic002"));
r = runUnguarded(simpleClass, "getValue");
assertEquals(7, r.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ReloadableTypeTests method invokeStaticReloading_gh4_4.
@Test
public void invokeStaticReloading_gh4_4() throws Exception {
TypeRegistry tr = getTypeRegistry("invokestatic..*");
ReloadableType A = tr.addType("invokestatic.issue4.A", loadBytesForClass("invokestatic.issue4.A"));
ReloadableType B = tr.addType("invokestatic.issue4.B", loadBytesForClass("invokestatic.issue4.B"));
Result r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
A.loadNewVersion(A.bytesInitial);
B.loadNewVersion(B.bytesInitial);
r = runUnguarded(B.getClazz(), "getMessage");
assertEquals("String1", r.returnValue);
}
use of org.springsource.loaded.TypeRegistry 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.TypeRegistry 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);
}
Aggregations