Package org.springsource.loaded

Examples of org.springsource.loaded.ReloadableType


  @Test
  public void clashingInstanceStaticMethods() throws Exception {
    String t = "executor.C";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    reload(rtype, "37");
  }
View Full Code Here


  @Test
  public void staticInitializerReloading1() throws Exception {
    String t = "clinit.One";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("5", result.returnValue);
    rtype.loadNewVersion("39", retrieveRename(t, t + "2"));
    rtype.runStaticInitializer(); // call is made on reloadable type
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("7", result.returnValue);
  }
View Full Code Here

  public void fields() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.Front";
    String b = "simple.Back";
    TypeRegistry r = getTypeRegistry(a + "," + b);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    ReloadableType rtypeb = r.addType(b, loadBytesForClass(b));
    result = runUnguarded(rtypea.getClazz(), "run");
    assertEquals(35, result.returnValue);

    try {
      result = runUnguarded(rtypea.getClazz(), "run2");
      fail();
    } catch (InvocationTargetException ite) {
      // success - var2 doesn't exist yet
    }

    rtypeb.loadNewVersion("2", retrieveRename(b, b + "2"));

    result = runUnguarded(rtypea.getClazz(), "run2");
    assertEquals(3355, result.returnValue);
  }
View Full Code Here

  @Test
  public void reflection() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.SelfReflector";
    TypeRegistry r = getTypeRegistry(a);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    result = runUnguarded(rtypea.getClazz(), "run");

    assertEquals(
        "14 $callSiteArray $class$java$lang$String $class$java$lang$StringBuilder $class$java$lang$reflect$Field $class$java$util$ArrayList $class$java$util$Collections $class$java$util$Iterator $class$java$util$List $class$simple$SelfReflector $staticClassInfo __$stMC array$$class$java$lang$reflect$Field i metaClass",
        result.returnValue);
  }
View Full Code Here

  @Test
  public void localVariables() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.LFront";
    TypeRegistry r = getTypeRegistry(a);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    result = runUnguarded(rtypea.getClazz(), "run");
    assertEquals("abc", result.returnValue);
    result = runUnguarded(rtypea.getClazz(), "run2");
    assertEquals(99, result.returnValue);

    rtypea.loadNewVersion("2", retrieveRename(a, a + "2"));

    result = runUnguarded(rtypea.getClazz(), "run");
    assertEquals("xxx", result.returnValue);
    result = runUnguarded(rtypea.getClazz(), "run2");
    assertEquals(88, result.returnValue);
  }
View Full Code Here

  public void fieldsOnInstance() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String a = "simple.Front";
    String b = "simple.Back";
    TypeRegistry r = getTypeRegistry(a + "," + b);
    ReloadableType rtypea = r.addType(a, loadBytesForClass(a));
    ReloadableType rtypeb = r.addType(b, loadBytesForClass(b));
    Object instance = rtypea.getClazz().newInstance();
    result = runOnInstance(rtypea.getClazz(), instance, "run");
    assertEquals(35, result.returnValue);
    try {
      result = runOnInstance(rtypea.getClazz(), instance, "run2");
      fail();
    } catch (Exception e) {
      // success - var2 doesn't exist yet
    }
    // rtypea.fixupGroovyType();
    rtypeb.loadNewVersion("2", retrieveRename(b, b + "2"));

    result = runOnInstance(rtypea.getClazz(), instance, "run2");
    // The field will not be initialized, so will contain 0
    assertEquals(0, result.returnValue);
  }
View Full Code Here

  @Test
  public void basic() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.Basic";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("goodbye", result.returnValue);
  }
View Full Code Here

  @Test
  public void basicInstance() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.Basic";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    Object instance = null;
    instance = rtype.getClazz().newInstance();

    // First method call to 'run' should return "hello"
    result = runOnInstance(rtype.getClazz(), instance, "run");
    assertEquals("hello", result.returnValue);

    // Version 3 makes run() call another local method to get the string
    // "abc"
    rtype.loadNewVersion("3", retrieveRename(t, t + "3"));

    // Field f = rtype.getClazz().getDeclaredField("metaClass");
    // f.setAccessible(true);
    // Object mc = f.get(instance);
    // System.out.println("Metaclass is currently " + mc);
    //
    // f.set(instance, null);
    //
    // f =
    // rtype.getClazz().getDeclaredField("$class$groovy$lang$MetaClass");
    // f.setAccessible(true);
    // f.set(instance, null);
    //
    // Method m = rtype.getClazz().getDeclaredMethod("getMetaClass");
    // m.setAccessible(true);
    // m.invoke(instance);
    // f.setAccessible(true);
    // mc = f.get(instance);

    // 9: invokevirtual #23; //Method
    // $getStaticMetaClass:()Lgroovy/lang/MetaClass;
    // 12: dup
    // 13: invokestatic #27; //Method
    // $get$$class$groovy$lang$MetaClass:()Ljava/lang/Class;
    // 16: invokestatic #33; //Method
    // org/codehaus/groovy/runtime/ScriptBytecodeAdapter.castToType:(Ljava/lang/Object;Ljav
    // a/lang/Class;)Ljava/lang/Object;
    // 19: checkcast #35; //class groovy/lang/MetaClass
    // 22: aload_0
    // 23: swap
    // 24: putfield #37; //Field metaClass:Lgroovy/lang/MetaClass;
    // 27: pop
    // 28: return

    // Method m = rtype.getClazz().getDeclaredMethod("$getStaticMetaClass");
    // m.setAccessible(true);
    // Object o = m.invoke(instance);
    // m =
    // rtype.getClazz().getDeclaredMethod("$get$$class$groovy$lang$MetaClass");
    // m.setAccessible(true);
    // Object p = m.invoke(null);
    // m =
    // rtype.getClazz().getClassLoader().loadClass("org.codehaus.groovy.runtime.ScriptBytecodeAdapter")
    // .getDeclaredMethod("castToType", Object.class, Class.class);
    // m.setAccessible(true);
    //
    // Object mc = m.invoke(null, o, p);
    // Field f = rtype.getClazz().getDeclaredField("metaClass");
    // f.setAccessible(true);
    // f.set(instance, null);

    // instance = rtype.getClazz().newInstance();

    // System.out.println("Metaclass is currently " + mc);
    // Let's reinitialize the instance meta class by duplicating

    result = runOnInstance(rtype.getClazz(), instance, "run");
    // result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("abc", result.returnValue);
  }
View Full Code Here

  @Test
  public void basic2() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicB";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("goodbye", result.returnValue);
  }
View Full Code Here

  @Test
  public void basic3() throws Exception {
    binLoader = new TestClassloaderWithRewriting();
    String t = "simple.BasicC";
    TypeRegistry r = getTypeRegistry(t);
    ReloadableType rtype = r.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("hello", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("goodbye", result.returnValue);
  }
View Full Code Here

TOP

Related Classes of org.springsource.loaded.ReloadableType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.