Search in sources :

Example 16 with TypeRegistry

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

the class GroovyTests method basic.

// Changing the return value within a method
@Test
public void basic() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.Basic";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("goodbye", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 17 with TypeRegistry

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

the class GroovyTests method basic5.

// Calling from one type to another, now the methods are non-static
@Test
public void basic5() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicE";
    String target = "simple.BasicETarget";
    TypeRegistry r = getTypeRegistry(t + "," + target);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    ReloadableType rtypeTarget = r.addType(target, loadBytesForClass(target));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    rtypeTarget.loadNewVersion("2", retrieveRename(target, target + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("foobar", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 18 with TypeRegistry

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

the class ExecutorBuilderTests method typeLevelAnnotations.

/**
	 * Testing that type level annotations are copied to the executor (to answer later reflection questions).
	 */
@Test
public void typeLevelAnnotations() {
    String t = "executor.A";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    reload(rtype, "2");
    Class<?> clazz = rtype.getLatestExecutorClass();
    Assert.assertEquals(Utils.getExecutorName(t, "2"), clazz.getName());
    Annotation[] annos = clazz.getAnnotations();
    Assert.assertNotNull(annos);
    Assert.assertEquals(1, annos.length);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Annotation(java.lang.annotation.Annotation) Test(org.junit.Test)

Example 19 with TypeRegistry

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

the class ExecutorBuilderTests method typeLevelAnnotations2.

/**
	 * Testing that type level annotations are copied to the executor. This loads a different form of the type with a
	 * second annotation.
	 */
@Test
public void typeLevelAnnotations2() {
    String t = "executor.A";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    Class<?> clazz = rtype.getLatestExecutorClass();
    Assert.assertEquals(Utils.getExecutorName(t, "2"), clazz.getName());
    Annotation[] annos = clazz.getAnnotations();
    Assert.assertNotNull(annos);
    Assert.assertEquals(2, annos.length);
    Set<String> s = new HashSet<String>();
    for (Annotation anno : annos) {
        s.add(anno.toString());
    }
    Assert.assertTrue(s.remove("@common.Marker()"));
    // Allow for alternate toString() variant
    if (!s.remove("@common.Anno(someValue=37, longValue=2, id=abc)")) {
        Assert.assertTrue(s.remove("@common.Anno(longValue=2, someValue=37, id=abc)"));
    }
    Assert.assertEquals(0, s.size());
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Annotation(java.lang.annotation.Annotation) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 20 with TypeRegistry

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

the class ExecutorBuilderTests method secondVersion.

@Test
public void secondVersion() throws Exception {
    String tclass = "executor.TestOne";
    TypeRegistry typeRegistry = getTypeRegistry(tclass);
    ReloadableType rtype = typeRegistry.addType(tclass, loadBytesForClass(tclass));
    rtype.loadNewVersion("2", retrieveRename(tclass, tclass + "2"));
    // testing executor is for second version and not first
    // @formatter:off
    checkType(rtype.getLatestExecutorBytes(), "CLASS: executor/TestOne$$E2 v50 0x0001(public) super java/lang/Object\n" + "SOURCE: TestOne2.java null\n" + "FIELD 0x0001(public) i I\n" + "METHOD: 0x0009(public static) ___init___(Lexecutor/TestOne;)V\n" + "    CODE\n" + " L0\n" + "    ALOAD 0\n" + "    POP\n" + "    RETURN\n" + " L1\n" + "METHOD: 0x0009(public static) foo(Lexecutor/TestOne;Ljava/lang/String;)J\n" + "    CODE\n" + " L0\n" + "    ALOAD 1\n" + "    INVOKESTATIC java/lang/Long.parseLong(Ljava/lang/String;)J\n" + "    LRETURN\n" + " L1\n" + "METHOD: 0x0009(public static) hashCode(Lexecutor/TestOne;)I\n" + "    CODE\n" + " L0\n" + "    ALOAD 0\n" + "    LDC 0\n" + "    LDC i\n" + "    INVOKESTATIC org/springsource/loaded/TypeRegistry.instanceFieldInterceptionRequired(ILjava/lang/String;)Z\n" + "    IFEQ L1\n" + "    DUP\n" + "    LDC i\n" + "    INVOKESPECIAL executor/TestOne.r$get(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + "    CHECKCAST java/lang/Integer\n" + "    INVOKEVIRTUAL java/lang/Integer.intValue()I\n" + "    GOTO L2\n" + " L1\n" + "    GETFIELD executor/TestOne.i I\n" + " L2\n" + "    ICONST_2\n" + "    IMUL\n" + "    IRETURN\n" + " L3\n" + "\n");
    Assert.assertEquals(" L0\n" + "    ALOAD 1\n" + "    INVOKESTATIC java/lang/Long.parseLong(Ljava/lang/String;)J\n" + "    LRETURN\n" + " L1\n", toStringMethod(rtype.getLatestExecutorBytes(), "foo", false));
    // @formatter:on
    //
    // @formatter:off
    Assert.assertEquals(" L0\n" + "    ALOAD 0\n" + "    LDC 0\n" + "    LDC i\n" + "    INVOKESTATIC org/springsource/loaded/TypeRegistry.instanceFieldInterceptionRequired(ILjava/lang/String;)Z\n" + "    IFEQ L1\n" + "    DUP\n" + "    LDC i\n" + "    INVOKESPECIAL executor/TestOne.r$get(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + "    CHECKCAST java/lang/Integer\n" + "    INVOKEVIRTUAL java/lang/Integer.intValue()I\n" + "    GOTO L2\n" + " L1\n" + "    GETFIELD executor/TestOne.i I\n" + " L2\n" + "    ICONST_2\n" + "    IMUL\n" + "    IRETURN\n" + " L3\n", toStringMethod(rtype.getLatestExecutorBytes(), "hashCode", false));
// @formatter:on
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Aggregations

TypeRegistry (org.springsource.loaded.TypeRegistry)322 Test (org.junit.Test)305 ReloadableType (org.springsource.loaded.ReloadableType)287 Result (org.springsource.loaded.test.infra.Result)97 TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 TypeDescriptor (org.springsource.loaded.TypeDescriptor)20 Ignore (org.junit.Ignore)17 Method (java.lang.reflect.Method)13 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)13 MethodMember (org.springsource.loaded.MethodMember)10 IOException (java.io.IOException)5 Properties (java.util.Properties)5 ResultException (org.springsource.loaded.test.infra.ResultException)5 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)4 LoadtimeInstrumentationPlugin (org.springsource.loaded.LoadtimeInstrumentationPlugin)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3