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());
}
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);
}
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;
}
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);
}
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);
}
Aggregations