use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class DispatcherBuilderTests method staticMethod.
@Test
public void staticMethod() throws Exception {
String tclass = "dispatcher.Staticmethod";
TypeRegistry typeRegistry = getTypeRegistry(tclass);
ReloadableType rtype = typeRegistry.addType(tclass, loadBytesForClass(tclass));
// Simply reloads itself to trigger new version handling code paths in both infrastructure and generated code
rtype.loadNewVersion("2", rtype.bytesInitial);
// ClassPrinter.print(rtype.interfaceBytes);
// ClassPrinter.print(rtype.getLatestExecutorBytes());
byte[] callerbytes = loadBytesForClass("dispatcher.StaticmethodCaller");
byte[] rewrittenBytes = MethodInvokerRewriter.rewrite(typeRegistry, callerbytes);
Class<?> callerClazz = loadit("dispatcher.StaticmethodCaller", rewrittenBytes);
result = runUnguarded(callerClazz, "run");
Assert.assertTrue(result.stdout.indexOf("abc") != -1);
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class IncrementalTypeDescriptorTests method deletedMethods.
// @Test
// public void newversionDescriptor() {
// byte[] classBytes = loadBytesForClass("data.SimpleClassFour");
// TypeDescriptor td = TypeDescriptorExtractor.extractFor(classBytes);
//
// byte[] classBytes2 = retrieveRename("data.SimpleClassFour", "data.SimpleClassFour002");
// TypeDescriptor td2 = TypeDescriptorExtractor.extractFor(classBytes2);
//
// IncrementalTypeDescriptor nvtd = new IncrementalTypeDescriptor(td);
// nvtd.setLatestTypeDescriptor(td2);
//
// // Now ask it questions about the changes
// List<MethodMember> ms = nvtd.getNewOrChangedMethods();
// Assert.assertEquals(2, ms.size());
//
// MethodMember rm = grabFrom(ms, "extraOne");
// Assert.assertNotNull(rm);
// Assert.assertEquals("0x1 extraOne(Ljava/lang/String;)V", rm.toString());
//
// rm = grabFrom(ms, "extraTwo");
// Assert.assertNotNull(rm);
// Assert.assertEquals("0x9 extraTwo(I)Ljava/lang/Double;", rm.toString());
// //
// // boolean b = nvtd.defines(false, "extraOne", "(Ljava/lang/String;)V");
// // Assert.assertTrue(b);
// //
// // b = nvtd.defines(true, "extraOne", "(Ljava/lang/String;)V");
// // Assert.assertFalse(b);
// }
// regular method deleted
@Test
public void deletedMethods() throws Exception {
TypeRegistry registry = getTypeRegistry("");
byte[] bytes = loadBytesForClass("typedescriptor.A");
TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(registry).extract(bytes, true);
byte[] bytes2 = ClassRenamer.rename("typedescriptor.A", loadBytesForClass("typedescriptor.A2"));
TypeDescriptor typeDescriptor2 = new TypeDescriptorExtractor(registry).extract(bytes2, true);
IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
itd.setLatestTypeDescriptor(typeDescriptor2);
Assert.assertEquals(1, itd.getDeletedMethods().size());
Assert.assertEquals("0x1 m()V", itd.getDeletedMethods().get(0).toString());
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class IncrementalTypeDescriptorTests method changedModifiers.
// More subtle changes (modifier flags)
@Test
public void changedModifiers() throws Exception {
TypeRegistry registry = getTypeRegistry("");
byte[] bytes = loadBytesForClass("typedescriptor.C");
TypeDescriptor typeDescriptor = registry.getExtractor().extract(bytes, true);
byte[] bytes2 = ClassRenamer.rename("typedescriptor.C", loadBytesForClass("typedescriptor.C2"));
TypeDescriptor typeDescriptor2 = registry.getExtractor().extract(bytes2, true);
IncrementalTypeDescriptor itd = new IncrementalTypeDescriptor(typeDescriptor);
itd.setLatestTypeDescriptor(typeDescriptor2);
System.out.println(itd.toString(true));
List<MethodMember> changed = itd.getNewOrChangedMethods();
MethodMember m = getMethod(changed, "staticMethod");
Assert.assertTrue(IncrementalTypeDescriptor.isNowNonStatic(m));
m = getMethod(changed, "instanceMethod");
Assert.assertTrue(IncrementalTypeDescriptor.isNowStatic(m));
m = getMethod(changed, "publicMethod1");
Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
// TODO Not detected as protected methods always made public in reloadable types... is that OK?
// m = getMethod(changed, "publicMethod2");
// Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
m = getMethod(changed, "publicMethod3");
Assert.assertTrue(IncrementalTypeDescriptor.hasVisibilityChanged(m));
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class InnerClassesTests method reloadDefaultVisClass.
/**
* Similar to the first test but this is just using a regular default visibility class.
*/
@Test
public void reloadDefaultVisClass() throws Exception {
String tclass = "inners.Two";
TypeRegistry typeRegistry = getTypeRegistry("inners..*");
typeRegistry.addType("inners.TwoDefault", loadBytesForClass("inners.TwoDefault"));
ReloadableType rtype = typeRegistry.addType(tclass, loadBytesForClass(tclass));
runUnguarded(rtype.getClazz(), "runner");
rtype.loadNewVersion("2", retrieveRename(tclass, tclass + "2"));
runUnguarded(rtype.getClazz(), "runner");
}
use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.
the class InnerClassesTests method reloadDefaultVisInner.
/**
* This tests what happens when referencing an inner type. When the reload occurs the new executor lives in a new
* classloader which would mean it cannot see a default visibility inner type. Default inner types (and default
* ctors) are being promoted to public so that they can be seen from the other classloader - that enables the test
* to work.
*/
@Test
public void reloadDefaultVisInner() throws Exception {
TypeRegistry typeRegistry = getTypeRegistry("inners..*");
typeRegistry.addType("inners.One$Inner", loadBytesForClass("inners.One$Inner"));
ReloadableType rtype = typeRegistry.addType("inners.One", loadBytesForClass("inners.One"));
runUnguarded(rtype.getClazz(), "runner");
rtype.loadNewVersion("2", retrieveRename("inners.One", "inners.One2", "inners.One2$Inner:inners.One$Inner"));
runUnguarded(rtype.getClazz(), "runner");
}
Aggregations