use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class EnumTests method testEnumsValueOf2.
/**
* Test the Enum.valueOf(EnumClass,String) - needs enumConstantDirectory clearing on reload.
*/
@Test
public void testEnumsValueOf2() throws Exception {
String t = "enumtests.ColoursC";
String runner = "enumtests.RunnerC";
Class<?> clazz = binLoader.loadClass(t);
assertNotNull(clazz);
Class<?> runnerClazz = binLoader.loadClass(runner);
assertNotNull(runnerClazz);
String output = runMethodAndCollectOutput(runnerClazz, "callValueOf2");
assertContains("[Red Green Blue Orange Yellow]", output);
assertContains("value count = 5", output);
// Check we loaded it as reloadable
ReloadableType rtype = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(t), false);
assertNotNull(rtype);
rtype.loadNewVersion(retrieveRename(t, t + "2", t + "2:" + t));
output = runMethodAndCollectOutput(runnerClazz, "callValueOf2");
assertContains("[Red Green Blue Orange Yellow Magenta Cyan]", output);
assertContains("value count = 7", output);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class EnumTests method testEnumsConstructor.
/**
* Old constructor deleted, new one added. This checks that the rewritten clinit that initializes the set of values
* is working.
*/
@Test
public void testEnumsConstructor() throws Exception {
String t = "enumtests.ColoursD";
String runner = "enumtests.RunnerD";
binLoader.loadClass(t);
Class<?> runnerClazz = binLoader.loadClass(runner);
assertNotNull(runnerClazz);
String output = runMethodAndCollectOutput(runnerClazz, "run1");
assertContains("[Red 1111 0 Green 2222 1 Blue 3333 2]", output);
// Check we loaded it as reloadable
ReloadableType rtype = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(t), false);
assertNotNull(rtype);
ReloadableType rtypeRunner = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(runner), false);
assertNotNull(rtypeRunner);
// Changes from ints to chars
rtype.loadNewVersion(retrieveRename(t, t + "2"));
rtypeRunner.loadNewVersion(retrieveRename(runner, runner + "2", "enumtests.ColoursD2:enumtests.ColoursD"));
output = runMethodAndCollectOutput(runnerClazz, "run1");
assertContains("[Red a 0 Green b 1 Blue c 2]", output);
assertContains("value count = 3", output);
}
use of org.springsource.loaded.ReloadableType 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.ReloadableType 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.ReloadableType 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