Search in sources :

Example 16 with Result

use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.

the class FieldReloadingTests method defaultFields.

// The problem with default visibility fields is that the executors cannot see them.  So we create accessors for
// these fields in the target types.  If two types in a hierarchy declare the same field, then these accessor methods will be in an 
// override relationship.  The overriding accessors will be subject to virtual dispatch - but the runtime type should be
// correct so that the right one is called.
@Test
public void defaultFields() throws Exception {
    TypeRegistry tr = getTypeRegistry("accessors..*");
    ReloadableType top = tr.addType("accessors.DefaultFields", loadBytesForClass("accessors.DefaultFields"));
    ReloadableType bottom = tr.addType("accessors.DefaultFieldsSub", loadBytesForClass("accessors.DefaultFieldsSub"));
    ClassPrinter.print(top.bytesLoaded);
    Object topInstance = top.getClazz().newInstance();
    Result result = runOnInstance(top.getClazz(), topInstance, "a");
    assertEquals(1, result.returnValue);
    Object botInstance = bottom.getClazz().newInstance();
    result = runOnInstance(bottom.getClazz(), botInstance, "a");
    assertEquals(1, result.returnValue);
    result = runOnInstance(bottom.getClazz(), botInstance, "b");
    assertEquals(2, result.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 17 with Result

use of org.springsource.loaded.test.infra.Result 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 18 with Result

use of org.springsource.loaded.test.infra.Result 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 19 with Result

use of org.springsource.loaded.test.infra.Result 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 20 with Result

use of org.springsource.loaded.test.infra.Result in project spring-loaded by spring-projects.

the class MethodInvokerRewriterTests method callingMethodIntroducedLaterReturningReferenceArray.

@Test
public void callingMethodIntroducedLaterReturningReferenceArray() throws Exception {
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    // Configure it directly such that data.Apple is considered reloadable
    configureForTesting(typeRegistry, "data.Apple");
    ReloadableType apple = typeRegistry.addType("data.Apple", loadBytesForClass("data.Apple"));
    byte[] callerbytes = loadBytesForClass("data.Orange002");
    callerbytes = ClassRenamer.rename("data.Orange", callerbytes, "data.Apple002:data.Apple");
    byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
    Class<?> callerClazz = loadit("data.Orange", rewrittenBytes);
    runExpectNoSuchMethodException(callerClazz, "callAppleRetArrayString", new Object[] { new String[] { "abc" } });
    // Load a version of Apple that does define that method
    apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
    Result result = runUnguarded(callerClazz, "callAppleRetArrayString", new Object[] { new String[] { "abc", "def" } });
    assertEquals("abc", ((String[]) result.returnValue)[0]);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Aggregations

Result (org.springsource.loaded.test.infra.Result)155 Test (org.junit.Test)139 ReloadableType (org.springsource.loaded.ReloadableType)106 TypeRegistry (org.springsource.loaded.TypeRegistry)97 ResultException (org.springsource.loaded.test.infra.ResultException)28 Method (java.lang.reflect.Method)27 InvocationTargetException (java.lang.reflect.InvocationTargetException)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 PrintStream (java.io.PrintStream)5 Constructor (java.lang.reflect.Constructor)4 Ignore (org.junit.Ignore)4 Field (java.lang.reflect.Field)2 ReflectiveInterceptor.jlClassGetField (org.springsource.loaded.ri.ReflectiveInterceptor.jlClassGetField)1