Search in sources :

Example 1 with ISMgr

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());
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) ISMgr(org.springsource.loaded.ISMgr) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 2 with ISMgr

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;
}
Also used : Field(java.lang.reflect.Field) ISMgr(org.springsource.loaded.ISMgr) InvocationTargetException(java.lang.reflect.InvocationTargetException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ResultException(org.springsource.loaded.test.infra.ResultException)

Aggregations

ISMgr (org.springsource.loaded.ISMgr)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 MalformedURLException (java.net.MalformedURLException)1 Test (org.junit.Test)1 ReloadableType (org.springsource.loaded.ReloadableType)1 TypeRegistry (org.springsource.loaded.TypeRegistry)1 ResultException (org.springsource.loaded.test.infra.ResultException)1