use of org.springsource.loaded.TypeRegistry 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);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class GroovyTests method basic5.
// Calling from one type to another, now the methods are non-static
@Test
public void basic5() throws Exception {
binLoader = new TestClassloaderWithRewriting();
String t = "simple.BasicE";
String target = "simple.BasicETarget";
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("hello", result.returnValue);
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
rtypeTarget.loadNewVersion("2", retrieveRename(target, target + "2"));
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("foobar", result.returnValue);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method typeLevelAnnotations.
/**
* Testing that type level annotations are copied to the executor (to answer later reflection questions).
*/
@Test
public void typeLevelAnnotations() {
String t = "executor.A";
TypeRegistry typeRegistry = getTypeRegistry(t);
ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
reload(rtype, "2");
Class<?> clazz = rtype.getLatestExecutorClass();
Assert.assertEquals(Utils.getExecutorName(t, "2"), clazz.getName());
Annotation[] annos = clazz.getAnnotations();
Assert.assertNotNull(annos);
Assert.assertEquals(1, annos.length);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method typeLevelAnnotations2.
/**
* Testing that type level annotations are copied to the executor. This loads a different form of the type with a
* second annotation.
*/
@Test
public void typeLevelAnnotations2() {
String t = "executor.A";
TypeRegistry typeRegistry = getTypeRegistry(t);
ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
Class<?> clazz = rtype.getLatestExecutorClass();
Assert.assertEquals(Utils.getExecutorName(t, "2"), clazz.getName());
Annotation[] annos = clazz.getAnnotations();
Assert.assertNotNull(annos);
Assert.assertEquals(2, annos.length);
Set<String> s = new HashSet<String>();
for (Annotation anno : annos) {
s.add(anno.toString());
}
Assert.assertTrue(s.remove("@common.Marker()"));
// Allow for alternate toString() variant
if (!s.remove("@common.Anno(someValue=37, longValue=2, id=abc)")) {
Assert.assertTrue(s.remove("@common.Anno(longValue=2, someValue=37, id=abc)"));
}
Assert.assertEquals(0, s.size());
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class ExecutorBuilderTests method secondVersion.
@Test
public void secondVersion() throws Exception {
String tclass = "executor.TestOne";
TypeRegistry typeRegistry = getTypeRegistry(tclass);
ReloadableType rtype = typeRegistry.addType(tclass, loadBytesForClass(tclass));
rtype.loadNewVersion("2", retrieveRename(tclass, tclass + "2"));
// testing executor is for second version and not first
// @formatter:off
checkType(rtype.getLatestExecutorBytes(), "CLASS: executor/TestOne$$E2 v50 0x0001(public) super java/lang/Object\n" + "SOURCE: TestOne2.java null\n" + "FIELD 0x0001(public) i I\n" + "METHOD: 0x0009(public static) ___init___(Lexecutor/TestOne;)V\n" + " CODE\n" + " L0\n" + " ALOAD 0\n" + " POP\n" + " RETURN\n" + " L1\n" + "METHOD: 0x0009(public static) foo(Lexecutor/TestOne;Ljava/lang/String;)J\n" + " CODE\n" + " L0\n" + " ALOAD 1\n" + " INVOKESTATIC java/lang/Long.parseLong(Ljava/lang/String;)J\n" + " LRETURN\n" + " L1\n" + "METHOD: 0x0009(public static) hashCode(Lexecutor/TestOne;)I\n" + " CODE\n" + " L0\n" + " ALOAD 0\n" + " LDC 0\n" + " LDC i\n" + " INVOKESTATIC org/springsource/loaded/TypeRegistry.instanceFieldInterceptionRequired(ILjava/lang/String;)Z\n" + " IFEQ L1\n" + " DUP\n" + " LDC i\n" + " INVOKESPECIAL executor/TestOne.r$get(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + " CHECKCAST java/lang/Integer\n" + " INVOKEVIRTUAL java/lang/Integer.intValue()I\n" + " GOTO L2\n" + " L1\n" + " GETFIELD executor/TestOne.i I\n" + " L2\n" + " ICONST_2\n" + " IMUL\n" + " IRETURN\n" + " L3\n" + "\n");
Assert.assertEquals(" L0\n" + " ALOAD 1\n" + " INVOKESTATIC java/lang/Long.parseLong(Ljava/lang/String;)J\n" + " LRETURN\n" + " L1\n", toStringMethod(rtype.getLatestExecutorBytes(), "foo", false));
// @formatter:on
//
// @formatter:off
Assert.assertEquals(" L0\n" + " ALOAD 0\n" + " LDC 0\n" + " LDC i\n" + " INVOKESTATIC org/springsource/loaded/TypeRegistry.instanceFieldInterceptionRequired(ILjava/lang/String;)Z\n" + " IFEQ L1\n" + " DUP\n" + " LDC i\n" + " INVOKESPECIAL executor/TestOne.r$get(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;\n" + " CHECKCAST java/lang/Integer\n" + " INVOKEVIRTUAL java/lang/Integer.intValue()I\n" + " GOTO L2\n" + " L1\n" + " GETFIELD executor/TestOne.i I\n" + " L2\n" + " ICONST_2\n" + " IMUL\n" + " IRETURN\n" + " L3\n", toStringMethod(rtype.getLatestExecutorBytes(), "hashCode", false));
// @formatter:on
}
Aggregations