use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CodeGenerationTests method simpleClass.
@Test
public void simpleClass() {
byte[] bs = loadBytesForClass("codegen.Simple");
ReloadableType simpleClass = typeRegistry.addType("codegen.Simple", bs);
assertNotNull(simpleClass);
// just checking no crash for loading it!
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CodeGenerationTests method interfaceCalls.
@Test
public void interfaceCalls() throws Exception {
TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
String theInterface = "interfaces.TheInterface";
String theImplementation = "interfaces.TheImplementation";
String theRunner = "interfaces.Runner";
configureForTesting(typeRegistry, theInterface + "," + theImplementation);
ReloadableType rInterface = typeRegistry.addType(theInterface, loadBytesForClass(theInterface));
ReloadableType rImpl = typeRegistry.addType(theImplementation, loadBytesForClass(theImplementation));
Class<?> theRunnerClazz = loadClass(theRunner);
Assert.assertEquals(35, runUnguarded(theRunnerClazz, "runGetValue").returnValue);
// Just load a new version of the getValue() method and see if it is picked up:
loadNewVersion(rImpl, 2);
Assert.assertEquals(23, runUnguarded(theRunnerClazz, "runGetValue").returnValue);
// Now a new version with toString()
loadNewVersion(rImpl, 3);
Assert.assertEquals("i am version 3", runUnguarded(theRunnerClazz, "runToString").returnValue);
// Now change the interface - add a method
// loadNewVersion(rInterface, 4);
// loadNewVersion(rImpl, 4);
byte[] impl4 = ClassRenamer.rename("interfaces.TheImplementation", loadBytesForClass("interfaces.TheImplementation004"), "interfaces.TheInterface004:interfaces.TheInterface");
byte[] interface4 = ClassRenamer.rename("interfaces.TheInterface", loadBytesForClass("interfaces.TheInterface004"), "interfaces.TheInterface004:interfaces.TheInterface");
rImpl.loadNewVersion("004", impl4);
rInterface.loadNewVersion("004", interface4);
// ClassPrinter.print(rImpl.getLatestExecutorBytes());
Assert.assertEquals("oranges", runUnguarded(theRunnerClazz, "doit").returnValue);
// reloadableSub.loadNewVersion("002", retrieveRename(bottom, bottom + "002"));
// ClassPrinter.print("new sub executor", reloadableSub.getLatestExecutorBytes());
// result = runUnguarded(theRunnerClazz, "runSubMethod");
// Assert.assertEquals(42, result.returnValue);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CrossLoaderTests method reloadTargetInSuperLoaderCallingSuper.
/**
* In a class loaded by the subloader, calling a new method in a class loaded by the superloader using super<dot>.
* (ispcheck)
*/
@Test
public void reloadTargetInSuperLoaderCallingSuper() throws Exception {
String top = "superpkg.TopB";
String bot = "subpkg.BottomB";
ReloadableType rtypeA = subLoader.loadAsReloadableType(top);
ReloadableType rtypeB = subLoader.loadAsReloadableType(bot);
rtypeA.loadNewVersion("2", retrieveRename(top, top + "002"));
rtypeB.loadNewVersion("2", retrieveRename(bot, bot + "002", top + "002:" + top));
// Check the registry looks right for Top
int topId = NameRegistry.getIdFor("superpkg/TopB");
TypeRegistry trTop = TypeRegistry.getTypeRegistryFor(subLoader.getParent());
assertEquals(0, topId);
assertEquals(top, trTop.getReloadableType(topId).getName());
assertEquals(top, trTop.getReloadableType("superpkg/TopB").getName());
int bottomId = NameRegistry.getIdFor("subpkg/BottomB");
TypeRegistry trBot = TypeRegistry.getTypeRegistryFor(subLoader);
assertEquals(1, bottomId);
assertEquals(bot, trBot.getReloadableType(bottomId).getName());
assertEquals(bot, trBot.getReloadableType("subpkg/BottomB").getName());
// Now call the m() in the Bottom003 type, which calls super.newMethodOnTop()
result = runUnguarded(rtypeB.getClazz(), "m");
assertEquals("TopB002.m() running", result.stdout);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CrossLoaderTests method reloadCheckingCompatibilityForReturnedFields.
/**
* This is testing field access when the value of the field is being checked against what is allowed to be returned.
* With multiple classloaders around this can get a little messy, say the method returns 'Serializable' but the
* actual method returns a type that the reloadable types classloader can't see (something from a subloader).<br>
* Heres a trace when things go wrong:
*
* Caused by: org.springsource.loaded.UnableToLoadClassException: Unable to find data for class 'subpkg/Subby' at
* org.springsource.loaded.Utils.loadClassAsBytes2(Utils.java:763) <br>
* at org.springsource.loaded.TypeRegistry.getDescriptorFor(TypeRegistry.java:246) <br>
* at org.springsource.loaded.Utils.isAssignableFrom(Utils.java:1480) <br>
* at org.springsource.loaded.Utils.checkCompatibility(Utils.java:1460) <br>
* at org.springsource.loaded.ISMgr.getValue(ISMgr.java:125) <br>
* at superpkg.TargetD.r$get(TargetD.java) <br>
* at superpkg.TargetD$$E2.getOne(TargetD002.java:17) <br>
* at superpkg.TargetD$$D2.getOne(Unknown Source) <br>
* at superpkg.TargetD.getOne(TargetD.java) <br>
* at subpkg.InvokerD.run(InvokerD.java:8)
*/
@Test
public void reloadCheckingCompatibilityForReturnedFields() throws Exception {
// start out same as previous test, then loads a further version:
String target = "superpkg.TargetD";
String invoker = "subpkg.InvokerD";
ReloadableType targetR = subLoader.loadAsReloadableType(target);
ReloadableType invokerR = subLoader.loadAsReloadableType(invoker);
result = runUnguardedWithCCL(invokerR.getClazz(), subLoader, "run");
assertEquals("null", result.stdout);
targetR.loadNewVersion("2", retrieveRename(target, target + "002"));
// invokerR.loadNewVersion("2", retrieveRename(invoker, invoker + "002", target + "002:" + target));
// Now call the run() in the Invoker type, which calls 'Target.m()' where Target is in a different loader
// and has been reloaded
result = runUnguardedWithCCL(invokerR.getClazz(), subLoader, "run");
assertEquals("a subby", result.stdout);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CrossLoaderTests method cglibProxiesAcrossLoader1.
// TODO unfinished do I have to worry about proxies loaded by sub classloaders or not?
// Avoiding fastclass in this test, one less thing to worry about
@Test
public void cglibProxiesAcrossLoader1() throws Exception {
binLoader = new SubLoader(new String[] {}, new String[] { "../testdata/lib/cglib-nodep-2.2.jar" });
subLoader = (SubLoader) binLoader;
String t = "subpkg.ProxyTestcase";
ReloadableType proxyTestcaseR = subLoader.loadAsReloadableType(t);
result = runUnguarded(proxyTestcaseR.getClazz(), "run");
System.out.println(result);
result = runUnguarded(proxyTestcaseR.getClazz(), "getProxyLoader");
System.out.println(result.returnValue);
result = runUnguarded(proxyTestcaseR.getClazz(), "getSimpleLoader");
System.out.println(result.returnValue);
// Class<?> clazz = binLoader.loadClass(t);
//
// runMethodAndCollectOutput(clazz, "configureTest1");
//
// String output = runMethodAndCollectOutput(clazz, "run");
// // interception should have occurred and original should not have been run
// assertContains("[void example.Simple.moo()]", output);
// assertDoesNotContain("Simple.moo() running", output);
//
// // Check we loaded it as reloadable
// ReloadableType rtype = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(t), false);
// assertNotNull(rtype);
//
// // Check the incidental types were loaded as reloadable
// ReloadableType rtype2 = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash("example.Simple"), false);
// assertNotNull(rtype2);
//
// rtype.loadNewVersion(retrieveRename(t, t + "2", "example.Simple2:example.Simple"));
// rtype2.loadNewVersion(retrieveRename("example.Simple", "example.Simple2"));
//
// // Now running 'boo()' which did not exist in the original. Remember this is invoked via proxy and so will only work
// // if the proxy was autoregenerated and reloaded!
// output = runMethodAndCollectOutput(clazz, "run");
// assertContains("[void example.Simple.boo()]", output);
// assertDoesNotContain("Simple2.boo running()", output);
}
Aggregations