Search in sources :

Example 91 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method loadType.

/**
	 * Check the basics.
	 */
@Test
public void loadType() {
    TypeRegistry typeRegistry = getTypeRegistry("data.SimpleClass");
    byte[] sc = loadBytesForClass("data.SimpleClass");
    ReloadableType rtype = new ReloadableType("data.SimpleClass", sc, 1, typeRegistry, null);
    assertEquals(1, rtype.getId());
    assertEquals("data.SimpleClass", rtype.getName());
    assertEquals("data/SimpleClass", rtype.getSlashedName());
    assertNotNull(rtype.getTypeDescriptor());
    assertEquals(typeRegistry, rtype.getTypeRegistry());
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 92 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method serialization4.

// Deserialize something we serialized earlier
// This test cannot work without the agent. The agent must intercept java.lang.ObjectStream and its use of reflection
// There is a test that will work in the SpringLoadedTestsInSeparateJVM
public void serialization4() throws Exception {
    TypeRegistry tr = getTypeRegistry("remote..*");
    //		ReloadableType person =
    tr.addType("remote.Person", loadBytesForClass("remote.Person"));
    // When the Serialize class is run directly, we see: byteinfo:len=98:crc=c1047cf6
    // When run via this test, we see: byteinfo:len=98:crc=7e07276a
    ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
    Class<?> clazz = runner.getClazz();
    Object instance = clazz.newInstance();
    Result r = runOnInstance(clazz, instance, "checkPredeserializedData");
    assertStdoutContains("Person stored ok", r);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result)

Example 93 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class SpringLoadedTests method getTypeRegistry.

/**
	 * Create a type registry, configure it with the specified reloadable type/packages and return it.
	 *
	 * @return new TypeRegistry
	 */
protected TypeRegistry getTypeRegistry(String includePatterns) {
    TypeRegistry.reinitialize();
    TypeRegistry tr = TypeRegistry.getTypeRegistryFor(binLoader);
    GlobalConfiguration.InTestMode = true;
    GlobalConfiguration.allowSplitPackages = true;
    Properties p = new Properties();
    if (includePatterns != null) {
        p.setProperty(TypeRegistry.Key_Inclusions, includePatterns);
    }
    if (tr == null) {
        throw new IllegalStateException("maybe you need to run with: -Dspringloaded=limit=false -Xmx512M -XX:MaxPermSize=256m -noverify");
    }
    tr.configure(p);
    return tr;
}
Also used : Properties(java.util.Properties) TypeRegistry(org.springsource.loaded.TypeRegistry)

Example 94 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReflectiveReflectionTests method testJRMethodGetAnnotationViaAccessibleObject.

@Test
public void testJRMethodGetAnnotationViaAccessibleObject() throws Exception {
    String t = "iri.JLRMGetAnnotationViaAccessibleObject";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("@reflection.AnnoT() null", result.returnValue);
    rtype.loadNewVersion(retrieveRenameRetarget(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("null @java.lang.Deprecated()", result.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Test(org.junit.Test)

Example 95 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReflectiveReflectionTests method testJLRFGetAnnotations.

@Test
public void testJLRFGetAnnotations() throws Exception {
    String t = "iri.JLRFGetAnnotations";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1:@reflection.AnnoT()", result.returnValue);
    rtype.loadNewVersion(retrieveRenameRetarget(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1:@java.lang.Deprecated()", result.returnValue);
}
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