Search in sources :

Example 46 with ReloadableType

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

the class GroovyTests method staticInitializerReloading3.

/**
	 * Dealing with final fields. This test was passing until groovy started really inlining the final fields. After
	 * doing so it isn't sufficient to run the static initializer to get them set to the new values.
	 */
@Ignore
@Test
public void staticInitializerReloading3() throws Exception {
    String t = "clinitg.Two";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("55", result.returnValue);
    rtype.loadNewVersion("39", retrieveRename(t, t + "2"));
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("99", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with ReloadableType

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

the class GroovyTests method simpleValues.

// Needs groovy 1.7.8
@Test
public void simpleValues() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.Values";
    String target = "simple.BasicFTarget";
    // GlobalConfiguration.logging = true;
    // GlobalConfiguration.isRuntimeLogging = true;
    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(new Integer(123), result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    // rtypeTarget.loadNewVersion("2", retrieveRename(target, target +
    // "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals(new Integer(456), result.returnValue);
//
// result = null;
//
// // The target method has been removed, should now fail to call it
// try {
// runUnguarded(rtype.getClazz(), "run");
// fail();
// } catch (InvocationTargetException ite) {
// // success
// }
//
// // Load the original back in, should work again
// rtypeTarget.loadNewVersion("3", retrieveRename(target, target));
// result = runUnguarded(rtype.getClazz(), "run");
// assertEquals("123", result.returnValue);
//
// // rtype.loadNewVersion("2", rtype.bytesInitial); //reload yourself
//
// // Load a new version that now returns an int
// rtypeTarget.loadNewVersion("4", retrieveRename(target, target +
// "4"));
// result = runUnguarded(rtype.getClazz(), "run");
// assertEquals("4456", 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 48 with ReloadableType

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

the class GroovyTests method enums.

/**
	 * Reloading enums written in groovy - very simple enum
	 */
@Test
public void enums() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String enumtype = "enums.WhatAnEnum";
    String intface = "enums.ExtensibleEnum";
    String runner = "enums.RunnerA";
    TypeRegistry typeRegistry = getTypeRegistry(enumtype + "," + intface + "," + runner);
    //		ReloadableType rtypeIntface = 
    typeRegistry.addType(intface, loadBytesForClass(intface));
    ReloadableType rtypeEnum = typeRegistry.addType(enumtype, loadBytesForClass(enumtype));
    ReloadableType rtypeRunner = typeRegistry.addType(runner, loadBytesForClass(runner));
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    // ClassPrinter.print(rtypeEnum.bytesInitial);
    assertContains("[RED GREEN BLUE]", result.stdout);
    System.out.println(result);
    byte[] bs = retrieveRename(enumtype, enumtype + "2", "enums.WhatAnEnum2$__clinit__closure1:enums.WhatAnEnum$__clinit__closure1", "[Lenums/WhatAnEnum2;:[Lenums/WhatAnEnum;", "Lenums/WhatAnEnum2;:Lenums/WhatAnEnum;", "enums/WhatAnEnum2:enums/WhatAnEnum");
    ClassPrinter.print(bs);
    rtypeEnum.loadNewVersion(bs);
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    System.out.println(result);
    assertContains("[RED GREEN BLUE YELLOW]", result.stdout);
// assertEquals("55", result.returnValue);
// rtype.loadNewVersion("39", retrieveRename(t, t + "2"));
// rtype.runStaticInitializer();
// result = runUnguarded(rtype.getClazz(), "run");
// assertEquals("99", 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 49 with ReloadableType

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

the class GroovyTests method methodCallTargetComingAndGoing.

@Ignore
// Are we just not having to because isCompilable is off?
@Test
public void methodCallTargetComingAndGoing() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicG";
    String target = "simple.BasicGTarget";
    TypeRegistry r = getTypeRegistry(t + "," + target);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    ReloadableType rtypeTarget = r.addType(target, loadBytesForClass(target));
    // exist on BasicGTarget
    try {
        result = runUnguarded(rtype.getClazz(), "run");
        fail();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
        assertCause(ite, "MissingMethodException");
    }
    // Now a version of BasicGTarget is loaded that does define the method
    rtypeTarget.loadNewVersion("2", retrieveRename(target, target + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hw", result.returnValue);
    // Now load the original version so the method is gone again
    // retrieveRename(target,
    rtypeTarget.loadNewVersion("3", rtypeTarget.bytesInitial);
    // "2"));
    try {
        result = runUnguarded(rtype.getClazz(), "run");
        fail();
    } catch (InvocationTargetException ite) {
        ite.printStackTrace();
        assertCause(ite, "MissingMethodException");
    }
// Here is the stack when it fails with a NSME:
// java.lang.reflect.InvocationTargetException
// at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
// at
// sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
// at
// sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
// at java.lang.reflect.Method.invoke(Method.java:597)
// at
// org.springsource.loaded.test.SpringLoadedTests.runUnguarded(SpringLoadedTests.java:201)
// at
// org.springsource.loaded.test.GroovyTests.methodCallTargetComingAndGoing(GroovyTests.java:340)
// at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
// at
// sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
// at
// sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
// at java.lang.reflect.Method.invoke(Method.java:597)
// at
// org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
// at
// org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
// at
// org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
// at
// org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
// at
// org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
// at
// org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:31)
// at
// org.junit.runners.BlockJUnit4ClassRunner.runNotIgnored(BlockJUnit4ClassRunner.java:79)
// at
// org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:71)
// at
// org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:49)
// at org.junit.runners.ParentRunner$3.run(ParentRunner.java:193)
// at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:52)
// at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:191)
// at org.junit.runners.ParentRunner.access$000(ParentRunner.java:42)
// at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:184)
// at org.junit.runners.ParentRunner.run(ParentRunner.java:236)
// at
// org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
// at
// org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
// at
// org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
// at
// org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
// at
// org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
// at
// org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
// Caused by: java.lang.NoSuchMethodError:
// BasicGTarget.foo()Ljava/lang/String;
// at
// org.springsource.loaded.TypeRegistry.istcheck(TypeRegistry.java:1090)
// at simple.BasicGTarget$foo.call(Unknown Source)
// at simple.BasicG.run(BasicG.groovy:6)
// ... 31 more
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TestClassloaderWithRewriting(org.springsource.loaded.test.infra.TestClassloaderWithRewriting) TypeRegistry(org.springsource.loaded.TypeRegistry) InvocationTargetException(java.lang.reflect.InvocationTargetException) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 50 with ReloadableType

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

the class GroovyTests method staticInitializerReloading2.

@Test
public void staticInitializerReloading2() throws Exception {
    String t = "clinitg.One";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("5", result.returnValue);
    rtype.loadNewVersion("39", retrieveRename(t, t + "2"));
    // use the 'new' ___clinit___ method to drive the static initializer
    Method staticInitializer = rtype.getClazz().getMethod("___clinit___");
    assertNotNull(staticInitializer);
    staticInitializer.invoke(null);
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("7", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) Method(java.lang.reflect.Method) TypeRegistry(org.springsource.loaded.TypeRegistry) 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