Search in sources :

Example 26 with TypeRegistry

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);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 27 with TypeRegistry

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());
}
Also used : IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeDescriptor(org.springsource.loaded.TypeDescriptor) IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) TypeDescriptorExtractor(org.springsource.loaded.TypeDescriptorExtractor) Test(org.junit.Test)

Example 28 with TypeRegistry

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));
}
Also used : IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeDescriptor(org.springsource.loaded.TypeDescriptor) IncrementalTypeDescriptor(org.springsource.loaded.IncrementalTypeDescriptor) TypeRegistry(org.springsource.loaded.TypeRegistry) MethodMember(org.springsource.loaded.MethodMember) Test(org.junit.Test)

Example 29 with TypeRegistry

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");
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 30 with TypeRegistry

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");
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Aggregations

TypeRegistry (org.springsource.loaded.TypeRegistry)322 Test (org.junit.Test)305 ReloadableType (org.springsource.loaded.ReloadableType)287 Result (org.springsource.loaded.test.infra.Result)97 TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 TypeDescriptor (org.springsource.loaded.TypeDescriptor)20 Ignore (org.junit.Ignore)17 Method (java.lang.reflect.Method)13 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)13 MethodMember (org.springsource.loaded.MethodMember)10 IOException (java.io.IOException)5 Properties (java.util.Properties)5 ResultException (org.springsource.loaded.test.infra.ResultException)5 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)4 LoadtimeInstrumentationPlugin (org.springsource.loaded.LoadtimeInstrumentationPlugin)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3