use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting 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);
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting 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);
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting 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
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class GroovyTests method localVariables.
// TODO why doesn't this need swapInit? Is that only required for static
// field constants?
@Test
public void localVariables() throws Exception {
binLoader = new TestClassloaderWithRewriting();
String a = "simple.LFront";
TypeRegistry r = getTypeRegistry(a);
ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
result = runUnguarded(rtypea.getClazz(), "run");
assertEquals("abc", result.returnValue);
result = runUnguarded(rtypea.getClazz(), "run2");
assertEquals(99, result.returnValue);
rtypea.loadNewVersion("2", retrieveRename(a, a + "2"));
result = runUnguarded(rtypea.getClazz(), "run");
assertEquals("xxx", result.returnValue);
result = runUnguarded(rtypea.getClazz(), "run2");
assertEquals(88, result.returnValue);
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting 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);
}
Aggregations