use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class PluginTests method testServicesFileWithPluginCommentedOut.
@SuppressWarnings("unused")
@Test
public void testServicesFileWithPluginCommentedOut() throws Exception {
binLoader = new TestClassloaderWithRewriting("meta2", true);
String t = "simple.Basic";
captureOn();
TypeRegistry r = getTypeRegistry(t);
String output = captureOff();
assertDoesNotContain("Instantiated ReloadEventProcessorPlugin1", output);
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class PluginTests method testSimplePluginWithUnableToReloadEvent.
// Test a simple plugin that processes reload events
@Test
public void testSimplePluginWithUnableToReloadEvent() throws Exception {
binLoader = new TestClassloaderWithRewriting("meta1", true);
String t = "simple.Basic";
captureOn();
TypeRegistry r = getTypeRegistry(t);
String output = captureOff();
assertContains("Instantiated ReloadEventProcessorPlugin1", output);
ReloadableType rtype = r.addType(t, loadBytesForClass(t));
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("hello", result.returnValue);
captureOn();
rtype.loadNewVersion("4", retrieveRename(t, t + "4"));
output = captureOff();
assertContains("ReloadEventProcessorPlugin1: unableToReloadEvent(simple.Basic,simple.Basic,4)", output);
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("hello", result.returnValue);
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class PluginTests method testPluginRerunStaticInitializerRequest.
@Test
public void testPluginRerunStaticInitializerRequest() throws Exception {
binLoader = new TestClassloaderWithRewriting("metaNotExist", true);
String t = "simple.Basic";
ReloadEventProcessorPlugin repp = new ReloadEventProcessorPlugin() {
public void reloadEvent(String typename, Class<?> clazz, String encodedTimestamp) {
System.out.println("Plugin: reloadEvent(" + typename + "," + clazz.getName() + "," + encodedTimestamp + ")");
}
public boolean shouldRerunStaticInitializer(String typename, Class<?> clazz, String encodedTimestamp) {
System.out.println("Plugin: rerun request for " + typename);
return false;
}
};
try {
Plugins.registerGlobalPlugin(repp);
TypeRegistry r = getTypeRegistry(t);
ReloadableType rtype = r.addType(t, loadBytesForClass(t));
captureOn();
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
String output = captureOff();
System.out.println(output);
assertContains("Reloading: Loading new version of simple.Basic [2]", output);
assertUniqueContains("Plugin: reloadEvent(simple.Basic,simple.Basic,2)", output);
assertContains("Reloading: Loading new version of simple.Basic [2]", output);
assertUniqueContains("Plugin: rerun request for simple.Basic", output);
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("goodbye", result.returnValue);
} finally {
Plugins.unregisterGlobalPlugin(repp);
}
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class PluginTests method testGlobalPluginRegistration.
// registering a global plugin
@Test
public void testGlobalPluginRegistration() throws Exception {
binLoader = new TestClassloaderWithRewriting("metaNotExist", true);
String t = "simple.Basic";
ReloadEventProcessorPlugin repp = new ReloadEventProcessorPlugin() {
public void reloadEvent(String typename, Class<?> clazz, String encodedTimestamp) {
System.out.println("Plugin: reloadEvent(" + typename + "," + clazz.getName() + "," + encodedTimestamp + ")");
}
public boolean shouldRerunStaticInitializer(String typename, Class<?> clazz, String encodedTimestamp) {
return false;
}
};
try {
Plugins.registerGlobalPlugin(repp);
TypeRegistry r = getTypeRegistry(t);
ReloadableType rtype = r.addType(t, loadBytesForClass(t));
captureOn();
rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
String output = captureOff();
System.out.println(output);
assertContains("Reloading: Loading new version of simple.Basic [2]", output);
assertUniqueContains("Plugin: reloadEvent(simple.Basic,simple.Basic,2)", output);
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("goodbye", result.returnValue);
} finally {
Plugins.unregisterGlobalPlugin(repp);
}
}
use of org.springsource.loaded.test.infra.TestClassloaderWithRewriting in project spring-loaded by spring-projects.
the class GroovyBenchmarkTests method benchmarkingGroovyMethodInvocations.
/**
* I'm interested in checking the performance difference between having compilable call sites on and off. So let's
* load a program that simply makes a method call 1000s of times. No reloading, this is just to check the runtime
* cost of rewriting.
*/
@Test
public void benchmarkingGroovyMethodInvocations() throws Exception {
binLoader = new TestClassloaderWithRewriting();
String t = "simple.BasicH";
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");
// System.out.println(result.returnValue + "ms");
// compilable off
// 2200,2331,2117
// arrays rather than collections:
// 1775, 1660
// compilable on (but still using collections)
// 516, 716, 669
// compilable on and arrays:
// 238ms (compilable on configurable in GroovyPlugin)
// ok - avoid rewriting field references to $callSiteArray (drops to 319ms)
// 116ms! (this change not yet active)
// changing it so that we dont intercept $getCallSiteArray either
// 92ms
// run directly (main method in BasicH)
// 56 !
System.out.print("warmup ... ");
for (int loop = 0; loop < 10; loop++) {
System.out.print(loop + " ");
result = runUnguarded(rtype.getClazz(), "run");
// System.out.println(result.returnValue + "ms");
}
System.out.println();
long total = 0;
result = runUnguarded(rtype.getClazz(), "run");
total += new Long((String) result.returnValue).longValue();
result = runUnguarded(rtype.getClazz(), "run");
total += new Long((String) result.returnValue).longValue();
result = runUnguarded(rtype.getClazz(), "run");
total += new Long((String) result.returnValue).longValue();
System.out.println("Average for 3 iterations is " + (total / 3) + "ms");
// rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
// rtypeTarget.loadNewVersion("2", retrieveRename(target, target + "2"));
//
// result = runUnguarded(rtype.getClazz(), "run");
// assertEquals("foobar", result.returnValue);
}
Aggregations