Search in sources :

Example 31 with TypeRegistry

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

the class InterfaceExtractorTest method varietyOfMethods.

@Test
public void varietyOfMethods() {
    TypeRegistry registry = getTypeRegistry(null);
    byte[] classBytes = loadBytesForClass("data.SimpleClassFour");
    TypeDescriptor td = new TypeDescriptorExtractor(registry).extract(classBytes, true);
    byte[] bytes = InterfaceExtractor.extract(classBytes, registry, td);
    // @formatter:off
    checkType(bytes, "CLASS: data/SimpleClassFour__I v50 0x0601(public abstract interface) super java/lang/Object\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClassFour;I)V\n" + "METHOD: 0x0401(public abstract) ___init___(Ldata/SimpleClassFour;Ljava/lang/String;)V\n" + "METHOD: 0x0401(public abstract) boo(Ldata/SimpleClassFour;)V\n" + "METHOD: 0x0401(public abstract) foo(Ldata/SimpleClassFour;)V\n" + "METHOD: 0x0401(public abstract) goo(Ldata/SimpleClassFour;IDLjava/lang/String;)Ljava/lang/String;\n" + "METHOD: 0x0401(public abstract) hoo(Ldata/SimpleClassFour;J)I\n" + "METHOD: 0x0401(public abstract) woo(Ldata/SimpleClassFour;)V java/lang/RuntimeException java/lang/IllegalStateException\n" + "METHOD: 0x0401(public abstract) __execute([Ljava/lang/Object;Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + "METHOD: 0x0401(public abstract) ___clinit___()V\n" + "METHOD: 0x0401(public abstract) hashCode(Ldata/SimpleClassFour;)I\n" + "METHOD: 0x0401(public abstract) equals(Ldata/SimpleClassFour;Ljava/lang/Object;)Z\n" + "METHOD: 0x0401(public abstract) clone(Ldata/SimpleClassFour;)Ljava/lang/Object; java/lang/CloneNotSupportedException\n" + "METHOD: 0x0401(public abstract) toString(Ldata/SimpleClassFour;)Ljava/lang/String;\n" + "\n");
// @formatter:on
}
Also used : TypeDescriptor(org.springsource.loaded.TypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 32 with TypeRegistry

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

the class Java8Tests method lambdaWithParameter.

@Test
public void lambdaWithParameter() throws Exception {
    String t = "basic.LambdaB";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "run");
    r = runUnguarded(simpleClass, "run");
    assertEquals(99L, r.returnValue);
    byte[] renamed = retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo");
    rtype.loadNewVersion("002", renamed);
    r = runUnguarded(simpleClass, "run");
    assertEquals(176L, r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 33 with TypeRegistry

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

the class Java8Tests method streamWithLambdaInvokedVirtually.

// inner interface (for the invokeinterface BSM)
@Test
public void streamWithLambdaInvokedVirtually() throws Exception {
    String t = "basic.StreamB";
    TypeRegistry typeRegistry = getTypeRegistry("basic..*");
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "run");
    assertEquals(3, r.returnValue);
    byte[] renamed = retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo");
    rtype.loadNewVersion("002", renamed);
    r = runUnguarded(simpleClass, "run");
    assertEquals(4, r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 34 with TypeRegistry

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

the class Java8Tests method lambdaWithTwoParameters.

@Test
public void lambdaWithTwoParameters() throws Exception {
    String t = "basic.LambdaC";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "run");
    r = runUnguarded(simpleClass, "run");
    assertEquals(6L, r.returnValue);
    byte[] renamed = retrieveRename(t, t + "2", t + "2$Boo:" + t + "$Boo");
    rtype.loadNewVersion("002", renamed);
    r = runUnguarded(simpleClass, "run");
    assertEquals(5L, r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 35 with TypeRegistry

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

the class MethodInvokerRewriterTests method invokevirtualNonCatchersErrorScenario.

@Test
public void invokevirtualNonCatchersErrorScenario() throws Exception {
    String top = "virtual.FourTop";
    String bot = "virtual.FourBot";
    TypeRegistry typeRegistry = getTypeRegistry(top + "," + bot);
    // The first top does not define foo()
    //		ReloadableType topR = 
    typeRegistry.addType(top, loadBytesForClass(top));
    ReloadableType botR = typeRegistry.addType(bot, loadBytesForClass(bot));
    result = runUnguarded(botR.getClazz(), "run");
    assertEquals(42, result.returnValue);
    // Dont load new Top, which means the new method that the subtype will call
    // will not exist
    // topR.loadNewVersion(retrieveRename(top, top + "2"));
    botR.loadNewVersion(retrieveRename(bot, bot + "2", top + "2:" + top));
    // introduced into FourTop
    try {
        result = runUnguarded(botR.getClazz(), "run");
        fail("Should have failed!");
    } catch (InvocationTargetException ite) {
        assertTrue(ite.getCause() instanceof NoSuchMethodError);
        assertEquals("FourBot.bar()I", ite.getCause().getMessage());
    }
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) 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