use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class ReflectiveInterceptor method jlrFieldSetChar.
public static void jlrFieldSetChar(Field field, Object target, char value) throws IllegalAccessException {
Class<?> clazz = field.getDeclaringClass();
ReloadableType rtype = getRType(clazz);
if (rtype == null) {
// Not reloadable
field = asSetableField(field, target, char.class, value, true);
field.setChar(target, value);
} else {
asSetableField(field, target, char.class, value, false);
rtype.setField(target, field.getName(), Modifier.isStatic(field.getModifiers()), value);
}
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class ReflectiveInterceptor method jlrFieldSetInt.
public static void jlrFieldSetInt(Field field, Object target, int value) throws IllegalAccessException {
Class<?> clazz = field.getDeclaringClass();
ReloadableType rtype = getRType(clazz);
if (rtype == null) {
// Not reloadable
field = asSetableField(field, target, int.class, value, true);
field.setInt(target, value);
} else {
asSetableField(field, target, int.class, value, false);
rtype.setField(target, field.getName(), Modifier.isStatic(field.getModifiers()), value);
}
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CglibProxyTests method getFastClasses.
// --- helper code
/**
* Find the reloadabletypes that are for FastClass classes, then replace any $$b2473734 with $$........ so we can
* write robust testcases that check for them.
*
* @param reloadableTypes the complete set of reloadabletypes (sparse array)
* @return the names (dotted) of the FastClass reloadabletypes
*/
private Set<String> getFastClasses(ReloadableType[] reloadableTypes) {
Set<String> res = new HashSet<String>();
for (ReloadableType reloadableType : reloadableTypes) {
if (reloadableType != null && reloadableType.getName().indexOf("FastClass") != -1) {
String s = reloadableType.getName();
StringBuilder sb = removeSpecificCodes(s);
res.add(sb.toString());
}
}
return res;
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CglibProxyTests method testSimpleProxyNoSuperCallsNoFastClass.
// Possibly now failing due to quick fix to copy method/field for grails (~build 113)
/**
* This test is quite basic. It is testing interactions with classes through CGLIB generated proxies. The
* ProxyTestcase creates a proxy for a type (@see ProxyBuilder). A proxy knows about the type which it is standing
* in for and knows about a method interceptor that will be called when methods on the proxy are invoked. It is up
* to the interceptor whether the 'original' method runs (by calling super or the MethodProxy passed into the
* interceptor). This first test does *not* call the super methods. No FastClass objects involved in this test.
*/
@Test
public void testSimpleProxyNoSuperCallsNoFastClass() throws Exception {
String t = "example.ProxyTestcase";
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);
}
use of org.springsource.loaded.ReloadableType in project spring-loaded by spring-projects.
the class CglibProxyTests method testSimpleProxyWithSuperCallsWithFastClass.
// Possibly now failing due to quick fix to copy method/field for grails (~build 113)
/**
* Variation of the test above, but now the super calls are allowed to occur. This means FastClass objects will be
* created by CGLIB, these also need auto regenerating and reloading.
*/
@Test
public void testSimpleProxyWithSuperCallsWithFastClass() throws Exception {
// binLoader = new TestClassloaderWithRewriting(true, true, true);
String t = "example.ProxyTestcase";
Class<?> clazz = binLoader.loadClass(t);
String output = runMethodAndCollectOutput(clazz, "run");
// interception should have occurred and original should have been run
assertContains("[void example.Simple.moo()]", output);
assertContains("Simple.moo() running", output);
// Check we loaded it as reloadable
ReloadableType rtype = TypeRegistry.getTypeRegistryFor(binLoader).getReloadableType(toSlash(t), false);
assertNotNull(rtype);
Set<String> rtypesForFastClass = getFastClasses(TypeRegistry.getTypeRegistryFor(binLoader).getReloadableTypes());
assertEquals(2, rtypesForFastClass.size());
assertContains("example.Simple$$FastClassByCGLIB$$........", rtypesForFastClass.toString());
assertContains("example.Simple$$EnhancerByCGLIB$$........$$FastClassByCGLIB$$........", rtypesForFastClass.toString());
// 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"));
output = runMethodAndCollectOutput(clazz, "run");
assertContains("Simple2.boo() running", output);
assertContains("[void example.Simple.boo()]", output);
output = runMethodAndCollectOutput(clazz, "runMoo");
// new version should run: note the 2 on the classname
assertContains("Simple2.moo() running", output);
assertContains("[void example.Simple.moo()]", output);
// try a method with parameters
output = runMethodAndCollectOutput(clazz, "runBar");
assertContains("Simple2.bar(1,abc,3) running", output);
assertContains("[public void example.Simple.bar(int,java.lang.String,long)]", output);
}
Aggregations