use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class MethodInvokerRewriterTests method callingMethodIntroducedLaterPrimitiveParamsLongDouble.
@Test
public void callingMethodIntroducedLaterPrimitiveParamsLongDouble() throws Exception {
TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
// Configure it directly such that data.Apple is considered reloadable
configureForTesting(typeRegistry, "data.Apple");
ReloadableType apple = typeRegistry.addType("data.Apple", loadBytesForClass("data.Apple"));
byte[] callerbytes = loadBytesForClass("data.Orange002");
callerbytes = ClassRenamer.rename("data.Orange", callerbytes, "data.Apple002:data.Apple");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("data.Orange", rewrittenBytes);
// public String callApple3(String s, int i, double d, String t, int[] is) {
runExpectNoSuchMethodException(callerClazz, "callApple3x", new Object[] { "abc", 1, 2.0d, "def", new int[] { 42, 53 } });
// Load a version of Apple that does define that method
apple.loadNewVersion("002", retrieveRename("data.Apple", "data.Apple002"));
Result result = runUnguarded(callerClazz, "callApple3x", new Object[] { "abc", 1, 2.0d, "def", new int[] { 42, 53 } });
assertEquals("abc12.0def42", result.returnValue);
// Load a version of Apple that doesn't define it
apple.loadNewVersion("003", loadBytesForClass("data.Apple"));
runExpectNoSuchMethodException(callerClazz, "callApple3x", new Object[] { "abc", 1, 2.0d, "def", new int[] { 42, 53 } });
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class PluginTests method testSimplePlugin.
// Test a simple plugin that processes reload events
@Test
public void testSimplePlugin() 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("2", retrieveRename(t, t + "2"));
output = captureOff();
assertContains("Reloading: Loading new version of simple.Basic [2]", output);
assertContains("ReloadEventProcessorPlugin1: reloadEvent(simple.Basic,simple.Basic,2)", output);
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("goodbye", result.returnValue);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class PluginTests method testPluginRerunStaticInitializerRequest2.
@Test
public void testPluginRerunStaticInitializerRequest2() throws Exception {
binLoader = new TestClassloaderWithRewriting("metaNotExist", true);
String t = "clinit.One";
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);
// if this were false, the result below would be 5!
return true;
}
};
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 clinit.One [2]", output);
assertUniqueContains("Plugin: reloadEvent(clinit.One,clinit.One,2)", output);
assertContains("Reloading: Loading new version of clinit.One [2]", output);
assertUniqueContains("Plugin: rerun request for clinit.One", output);
result = runUnguarded(rtype.getClazz(), "run");
assertEquals("7", result.returnValue);
} finally {
Plugins.unregisterGlobalPlugin(repp);
}
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class ProxyTests method xmultipleInterfaces.
/**
* Proxying with multiple interfaces, changed independently.
*/
// To run these tests you need to have -javaagent specified
@Ignore
@Test
public void xmultipleInterfaces() throws Exception {
// Set so that the Proxy generator can see the interface class
Thread.currentThread().setContextClassLoader(binLoader);
Class<?> clazz = Class.forName("proxy.three.TestA1", false, binLoader);
runUnguarded(clazz, "createProxy");
Class<?> clazzForInterface = Class.forName("proxy.three.TestIntfaceA1", false, binLoader);
Class<?> clazzForInterfaceB1 = Class.forName("proxy.three.TestIntfaceB1", false, binLoader);
// Call a method through the proxy
assertContains("TestInvocationHandler1.invoke() for ma", runUnguarded(clazz, "runMA").stdout);
TypeRegistry tr = TypeRegistry.getTypeRegistryFor(binLoader);
assertNotNull(tr);
ReloadableType rt = tr.getReloadableType(clazzForInterface);
assertNotNull(rt);
ReloadableType rt2 = tr.getReloadableType(clazzForInterfaceB1);
assertNotNull(rt2);
// new version adds a method called na
byte[] newVersionOfTestInterfaceA1 = retrieveRename("proxy.three.TestIntfaceA1", "proxy.three.TestIntfaceA2");
rt.loadNewVersion(newVersionOfTestInterfaceA1);
// running m() should still work
assertContains("TestInvocationHandler1.invoke() for ma", runUnguarded(clazz, "runMA").stdout);
// Now load new version of proxy.TestA1 that will enable us to call n on the new interface
byte[] newVersionOfTestA2 = retrieveRename("proxy.three.TestA1", "proxy.three.TestA2", "proxy.three.TestIntfaceA2:proxy.three.TestIntfaceA1", "proxy.three.TestIntfaceB2:proxy.three.TestIntfaceB1");
tr.getReloadableType(clazz).loadNewVersion(newVersionOfTestA2);
// running ma() should still work
assertContains("TestInvocationHandler1.invoke() for ma", runUnguarded(clazz, "runMA").stdout);
// running na() should now work! (if the proxy was auto regen/reloaded)
assertContains("TestInvocationHandler1.invoke() for na", runUnguarded(clazz, "runNA").stdout);
// should be OK - mb() was in from the start
assertContains("TestInvocationHandler1.invoke() for mb", runUnguarded(clazz, "runMB").stdout);
// TestIntfaceB1 hasn't been reloaded yet, nb() isnt on the interface (nor proxy)
try {
runUnguarded(clazz, "runNB");
fail();
} catch (InvocationTargetException re) {
assertTrue(re.getCause() instanceof NoSuchMethodError);
assertEquals("proxy.three.TestIntfaceB1.nb()V", re.getCause().getMessage());
}
// new version adds a method called nb
byte[] newVersionOfTestInterfaceB1 = retrieveRename("proxy.three.TestIntfaceB1", "proxy.three.TestIntfaceB2");
rt2.loadNewVersion("3", newVersionOfTestInterfaceB1);
// running nb() should now work! (if the proxy was auto regen/reloaded)
assertContains("TestInvocationHandler1.invoke() for nb", runUnguarded(clazz, "runNB").stdout);
Set<ReloadableType> proxies = tr.getJDKProxiesFor("proxy/three/TestIntfaceA1");
assertFalse(proxies.isEmpty());
ReloadableType proxyRT = proxies.iterator().next();
assertStartsWith("proxy.three.", proxyRT.getName());
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class ProxyTests method xnonPublicInterface.
/**
* For non public interfaces the proxies are generated in the same package as the interface.
*/
// To run these tests you need to have -javaagent specified
@Ignore
@Test
public void xnonPublicInterface() throws Exception {
// Set so that the Proxy generator can see the interface class
Thread.currentThread().setContextClassLoader(binLoader);
Class<?> clazz = Class.forName("proxy.two.TestA1", false, binLoader);
Result r = runUnguarded(clazz, "createProxy");
Class<?> clazzForInterface = Class.forName("proxy.two.TestIntfaceA1", false, binLoader);
// Call a method through the proxy
r = runUnguarded(clazz, "runM");
assertContains("TestInvocationHandler1.invoke() for m", r.stdout);
TypeRegistry tr = TypeRegistry.getTypeRegistryFor(binLoader);
assertNotNull(tr);
ReloadableType rt = tr.getReloadableType(clazzForInterface);
assertNotNull(rt);
// new version adds a method called n
byte[] newVersionOfTestInterfaceA1 = retrieveRename("proxy.two.TestIntfaceA1", "proxy.two.TestIntfaceA2");
rt.loadNewVersion(newVersionOfTestInterfaceA1);
// running m() should still work
r = runUnguarded(clazz, "runM");
assertContains("TestInvocationHandler1.invoke() for m", r.stdout);
// Now load new version of proxy.TestA1 that will enable us to call n on the new interface
byte[] newVersionOfTestA2 = retrieveRename("proxy.two.TestA1", "proxy.two.TestA2", "proxy.two.TestIntfaceA2:proxy.two.TestIntfaceA1");
tr.getReloadableType(clazz).loadNewVersion(newVersionOfTestA2);
// running m() should still work
r = runUnguarded(clazz, "runM");
assertContains("TestInvocationHandler1.invoke() for m", r.stdout);
// running n() should now work! (if the proxy was auto regen/reloaded)
r = runUnguarded(clazz, "runN");
assertContains("TestInvocationHandler1.invoke() for n", r.stdout);
Set<ReloadableType> proxies = tr.getJDKProxiesFor("proxy/two/TestIntfaceA1");
assertFalse(proxies.isEmpty());
ReloadableType proxyRT = proxies.iterator().next();
assertStartsWith("proxy.two.", proxyRT.getName());
}
Aggregations