Search in sources :

Example 36 with ReloadableType

use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.

the class ExecutorBuilderTests method basicExternals.

/**
	 * Check properties of the newly created executor.
	 */
@Test
public void basicExternals() throws Exception {
    String t = "executor.TestOne";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    reload(rtype, "37");
    Class<?> clazz = rtype.getLatestExecutorClass();
    Assert.assertEquals(Utils.getExecutorName(t, "37"), clazz.getName());
    Assert.assertEquals(3, clazz.getDeclaredMethods().length);
    Assert.assertEquals(1, clazz.getDeclaredFields().length);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 37 with ReloadableType

use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.

the class ExecutorBuilderTests method staticInitializerReloading4.

/**
	 * Type that doesn't really have a clinit
	 */
@Test
public void staticInitializerReloading4() throws Exception {
    String t = "clinit.Three";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1", result.returnValue);
    rtype.loadNewVersion("3", retrieveRename(t, t + "3"));
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    ClassPrinter.print(rtype.getLatestExecutorBytes());
    assertEquals("4", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 38 with ReloadableType

use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.

the class ExecutorBuilderTests method methodLevelAnnotations.

@Test
public void methodLevelAnnotations() throws Exception {
    String t = "executor.B";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    reload(rtype, "37");
    checkAnnotations(rtype.bytesLoaded, "m()V", "@common.Marker()");
    checkAnnotations(rtype.bytesLoaded, "m2()V");
    checkAnnotations(rtype.getLatestExecutorBytes(), "m(Lexecutor/B;)V", "@common.Marker()");
    checkAnnotations(rtype.getLatestExecutorBytes(), "m2(Lexecutor/B;)V");
    rtype.loadNewVersion("39", retrieveRename("executor.B", "executor.B2"));
    checkAnnotations(rtype.getLatestExecutorBytes(), "m(Lexecutor/B;)V");
    checkAnnotations(rtype.getLatestExecutorBytes(), "m2(Lexecutor/B;)V", "@common.Marker()", "@common.Anno(id=abc)");
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 39 with ReloadableType

use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.

the class CrossLoaderTests method toString.

public String toString(List<Reference<ReloadableType>> list) {
    if (list == null) {
        return "null";
    }
    StringBuilder b = new StringBuilder();
    b.append("[");
    for (int i = 0; i < list.size(); i++) {
        if (i > 0) {
            b.append(",");
        }
        Reference<ReloadableType> ref = list.get(i);
        ReloadableType rtype = ref.get();
        if (rtype != null) {
            b.append(rtype.getName());
        }
    }
    b.append("]");
    return b.toString();
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType)

Example 40 with ReloadableType

use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.

the class CrossLoaderTests method verifyingAssociatedTypesInfo2.

// Large scale test loading a bunch of types and verifying what happens in terms of tagging
@Test
public void verifyingAssociatedTypesInfo2() throws Exception {
    // associatedtypes (top and middle) are in the super loader
    // subassociatedtypes (bottom) are in the sub loader
    ReloadableType bm = subLoader.loadAsReloadableType("associatedtypes.CM");
    ReloadableType cm = subLoader.loadAsReloadableType("associatedtypes.CM");
    assertNotNull(cm);
    assertNotEquals(subLoader, cm.getClazz().getClassLoader());
    ReloadableType im1 = subLoader.loadAsReloadableType("associatedtypes.IM");
    assertNotNull(im1);
    // Cause clinit to run so associations are setup
    runUnguarded(cm.getClazz(), "run");
    assertContains("associatedtypes.CM", toString(im1.getAssociatedSubtypes()));
    assertFalse(cm.isAffectedByReload());
    assertFalse(cm.isAffectedByReload());
    assertFalse(bm.isAffectedByReload());
    // Load CM again, should tag CM and IM
    cm.loadNewVersion("2", cm.bytesInitial);
    assertTrue(cm.isAffectedByReload());
    assertTrue(im1.isAffectedByReload());
    assertTrue(bm.isAffectedByReload());
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) Test(org.junit.Test)

Aggregations

ReloadableType (org.springsource.loaded.ReloadableType)375 Test (org.junit.Test)320 TypeRegistry (org.springsource.loaded.TypeRegistry)287 Result (org.springsource.loaded.test.infra.Result)106 Method (java.lang.reflect.Method)37 InvocationTargetException (java.lang.reflect.InvocationTargetException)26 TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)22 Ignore (org.junit.Ignore)17 CurrentLiveVersion (org.springsource.loaded.CurrentLiveVersion)10 AccessibleObject (java.lang.reflect.AccessibleObject)9 ResultException (org.springsource.loaded.test.infra.ResultException)9 MethodMember (org.springsource.loaded.MethodMember)8 Field (java.lang.reflect.Field)6 TypeDescriptor (org.springsource.loaded.TypeDescriptor)6 IOException (java.io.IOException)5 Annotation (java.lang.annotation.Annotation)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 LoadtimeInstrumentationPlugin (org.springsource.loaded.LoadtimeInstrumentationPlugin)4 File (java.io.File)3