Search in sources :

Example 61 with ReloadableType

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

the class Java8Tests method lambdaInvokeVirtual.

@Test
public void lambdaInvokeVirtual() throws Exception {
    String t = "basic.LambdaJ";
    TypeRegistry typeRegistry = getTypeRegistry("basic..*");
    // Since Foo needs promoting to public, have to ensure it is directly loaded:
    ReloadableType itype = typeRegistry.addType(t + "$Foo", loadBytesForClass(t + "$Foo"));
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "run");
    r = runUnguarded(simpleClass, "run");
    assertEquals("fooa", r.returnValue);
    itype.loadNewVersion("002", retrieveRename(t + "$Foo", t + "2$Foo"));
    rtype.loadNewVersion("002", retrieveRename(t, t + "2", t + "2$Foo:" + t + "$Foo"));
    r = runUnguarded(simpleClass, "run");
    assertEquals("fooab", 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 62 with ReloadableType

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

the class Java8Tests method lambdaA.

@Test
public void lambdaA() throws Exception {
    String t = "basic.LambdaA";
    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(77, r.returnValue);
    rtype.loadNewVersion("002", rtype.bytesInitial);
    r = runUnguarded(simpleClass, "run");
    assertEquals(77, 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 63 with ReloadableType

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

the class Java8Tests method lambdaWithNonPublicInnerInterface.

@Test
public void lambdaWithNonPublicInnerInterface() throws Exception {
    String t = "basic.LambdaG";
    TypeRegistry typeRegistry = getTypeRegistry("basic..*");
    // Since Boo needs promoting to public, have to ensure it is directly loaded:
    typeRegistry.addType(t + "$Boo", loadBytesForClass(t + "$Boo"));
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "run");
    r = runUnguarded(simpleClass, "run");
    assertEquals(99, r.returnValue);
    byte[] renamed = retrieveRename(t, t + "2", t + "2$Boo:" + t + "$Boo");
    rtype.loadNewVersion("002", renamed);
    r = runUnguarded(simpleClass, "run");
    assertEquals(44, 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 64 with ReloadableType

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

the class Java8Tests method streamWithLambdaInvokedVirtually2.

// not an inner interface this time (for the invokeinterface BSM)
@Test
public void streamWithLambdaInvokedVirtually2() throws Exception {
    String t = "basic.StreamBB";
    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");
    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 65 with ReloadableType

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

the class Java8Tests method issue104.

@Test
public void issue104() throws Exception {
    String t = "bugs.Issue104";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    byte[] sc = loadBytesForClass(t);
    ReloadableType rtype = typeRegistry.addType(t, sc);
    Class<?> clazz = rtype.getClazz();
    @SuppressWarnings("unused") Result r = runUnguarded(clazz, "run");
    r = runUnguarded(clazz, "run");
    rtype.loadNewVersion("002", rtype.bytesInitial);
    r = runUnguarded(clazz, "run");
// TODO should assert something but the issue is that the JVM crashes...
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) 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