use of org.springsource.loaded.ISMgr in project spring-loaded by spring-projects.
the class FieldReloadingTests method inheritedNonReloadable2.
// Now a pair of types with one field initially. New field added - original should continue to be accessed
// through the GETFIELD, the new one via the map
@Test
public void inheritedNonReloadable2() throws Exception {
String top = "fields.X";
TypeRegistry tr = getTypeRegistry(top);
ReloadableType rTop = tr.addType(top, loadBytesForClass(top));
Class<?> cTop = rTop.getClazz();
Object iTop = cTop.newInstance();
assertEquals(5, runOnInstance(cTop, iTop, "getI").returnValue);
runOnInstance(cTop, iTop, "setI", 4);
assertEquals(4, runOnInstance(cTop, iTop, "getI").returnValue);
// // Now reload the ReloadableTop class and introduce that field i which will shadow the one in the supertype
rTop.loadNewVersion("2", retrieveRename(top, top + "002"));
assertEquals(0, runOnInstance(cTop, iTop, "getJ").returnValue);
runOnInstance(cTop, iTop, "setJ", 44);
assertEquals(44, runOnInstance(cTop, iTop, "getJ").returnValue);
assertEquals(4, runOnInstance(cTop, iTop, "getI").returnValue);
ISMgr fa = getFieldAccessor(iTop);
assertContains("j=44", fa.toString());
assertDoesNotContain("i=", fa.toString());
}
use of org.springsource.loaded.ISMgr in project spring-loaded by spring-projects.
the class SpringLoadedTests method getFieldAccessor.
protected ISMgr getFieldAccessor(Object o) {
Class<?> clazz = o.getClass();
try {
Field f = clazz.getDeclaredField(Constants.fInstanceFieldsName);
f.setAccessible(true);
return (ISMgr) f.get(o);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
Aggregations