Search in sources :

Example 6 with ReloadableType

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

Example 7 with ReloadableType

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

Example 8 with ReloadableType

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;
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) HashSet(java.util.HashSet)

Example 9 with ReloadableType

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

Example 10 with ReloadableType

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

Aggregations

ReloadableType (org.springsource.loaded.ReloadableType)375 Test (org.junit.Test)320 TypeRegistry (org.springsource.loaded.TypeRegistry)287 Result (org.springsource.loaded.test.infra.Result)106 Method (java.lang.reflect.Method)37 InvocationTargetException (java.lang.reflect.InvocationTargetException)26 TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)22 Ignore (org.junit.Ignore)17 CurrentLiveVersion (org.springsource.loaded.CurrentLiveVersion)10 AccessibleObject (java.lang.reflect.AccessibleObject)9 ResultException (org.springsource.loaded.test.infra.ResultException)9 MethodMember (org.springsource.loaded.MethodMember)8 Field (java.lang.reflect.Field)6 TypeDescriptor (org.springsource.loaded.TypeDescriptor)6 IOException (java.io.IOException)5 Annotation (java.lang.annotation.Annotation)4 ZipEntry (java.util.zip.ZipEntry)4 ZipFile (java.util.zip.ZipFile)4 LoadtimeInstrumentationPlugin (org.springsource.loaded.LoadtimeInstrumentationPlugin)4 File (java.io.File)3