Package org.springsource.loaded

Examples of org.springsource.loaded.ReloadableType$MergedRewrite$ChainedAdapters


  @Test
  public void testControllers1() throws Exception {
    String t = "controller.Controller";
    String closure = "controller.Controller$_closure1";
    TypeRegistry r = getTypeRegistry(t + "," + closure);
    ReloadableType ttype = r.addType(t, loadBytesForClass(t));
    ReloadableType closuretype = r.addType(closure, loadBytesForClass(closure));

    result = runUnguarded(ttype.getClazz(), "execute");
    assertEquals("[action:list, params:2]", result.stdout);

    // Change the body of the 'index' closure
    closuretype.loadNewVersion("2", retrieveRename(closure, "controller.Controller2$_closure1"));
    result = runUnguarded(ttype.getClazz(), "execute");
    assertEquals("[action:custard, params:345]", result.stdout);

    // Introduced a new closure, left the index one unchanged...
    closuretype.loadNewVersion("3", retrieveRename(closure, "controller.Controller3$_closure1"));

    result = runUnguarded(ttype.getClazz(), "execute");
    System.out.println(result);
    // assertEquals("[action:custard, params:345]", result.stdout);
View Full Code Here


  @Test
  public void staticInitializerReloading1() throws Exception {
    String t = "clinitg.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

  @Test
  public void staticInitializerReloading2() throws Exception {
    String t = "clinitg.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"));

    // use the 'new' ___clinit___ method to drive the static initializer
    Method staticInitializer = rtype.getClazz().getMethod("___clinit___");
    assertNotNull(staticInitializer);
    staticInitializer.invoke(null);

    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("7", result.returnValue);
  }
View Full Code Here

  @Ignore
  @Test
  public void staticInitializerReloading3() throws Exception {
    String t = "clinitg.Two";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("55", result.returnValue);
    rtype.loadNewVersion("39", retrieveRename(t, t + "2"));
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("99", result.returnValue);
  }
View Full Code Here

    String intface = "enums.ExtensibleEnum";
    String runner = "enums.RunnerA";
    TypeRegistry typeRegistry = getTypeRegistry(enumtype + "," + intface + "," + runner);
//    ReloadableType rtypeIntface =
    typeRegistry.addType(intface, loadBytesForClass(intface));
    ReloadableType rtypeEnum = typeRegistry.addType(enumtype, loadBytesForClass(enumtype));
    ReloadableType rtypeRunner = typeRegistry.addType(runner, loadBytesForClass(runner));
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    // ClassPrinter.print(rtypeEnum.bytesInitial);
    assertContains("[RED GREEN BLUE]", result.stdout);
    System.out.println(result);
    byte[] bs = retrieveRename(enumtype, enumtype + "2",
        "enums.WhatAnEnum2$__clinit__closure1:enums.WhatAnEnum$__clinit__closure1",
        "[Lenums/WhatAnEnum2;:[Lenums/WhatAnEnum;",
        "Lenums/WhatAnEnum2;:Lenums/WhatAnEnum;",
        "enums/WhatAnEnum2:enums/WhatAnEnum");
    ClassPrinter.print(bs);
    rtypeEnum.loadNewVersion(bs);
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    System.out.println(result);
    assertContains(
        "[RED GREEN BLUE YELLOW]",
        result.stdout);
View Full Code Here

    String runner = "enums.RunnerB";
    String closure = "enums.WhatAnEnumB$__clinit__closure1";
    TypeRegistry typeRegistry = getTypeRegistry(enumtype + "," + intface + "," + runner + "," + closure);
//    ReloadableType rtypeIntface =
    typeRegistry.addType(intface, loadBytesForClass(intface));
    ReloadableType rtypeClosure = typeRegistry.addType(closure, loadBytesForClass(closure));
    ReloadableType rtypeEnum = typeRegistry.addType(enumtype, loadBytesForClass(enumtype));
    ReloadableType rtypeRunner = typeRegistry.addType(runner, loadBytesForClass(runner));
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    assertContains(
        "[PETS_AT_THE_DISCO 1 JUMPING_INTO_A_HOOP 2 HAVING_A_NICE_TIME 3 LIVING_ON_A_LOG 4 WHAT_DID_YOU_DO 5 UNKNOWN 0]",
        result.stdout);

    byte[] cs = retrieveRename(closure, "enums.WhatAnEnumB2$__clinit__closure1", "enums.WhatAnEnumB2:enums.WhatAnEnumB");
    rtypeClosure.loadNewVersion(cs);
    byte[] bs = retrieveRename(enumtype, enumtype + "2",
        "enums.WhatAnEnumB2$__clinit__closure1:enums.WhatAnEnumB$__clinit__closure1",
        "[Lenums/WhatAnEnumB2;:[Lenums/WhatAnEnumB;","enums/WhatAnEnumB2:enums/WhatAnEnumB");
    rtypeEnum.loadNewVersion(bs);
    result = runUnguarded(rtypeRunner.getClazz(), "run");
    System.out.println(result);
    assertContains(
        "[PETS_AT_THE_DISCO 1 JUMPING_INTO_A_HOOP 2 HAVING_A_NICE_TIME 3 LIVING_ON_A_LOG 4 WHAT_DID_YOU_DO 5 WOBBLE 6 UNKNOWN 0]",
        result.stdout);
  }
View Full Code Here

  @Ignore // Needs investigating...likely a change in groovy bytecode format tripping us up
  @Test
  public void staticInitializerReloading4() throws Exception {
    String t = "clinitg.Three";
    TypeRegistry typeRegistry = getTypeRegistry(t);
    ReloadableType rtype = typeRegistry.addType(t, loadBytesForClass(t));
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1", result.returnValue);
    rtype.loadNewVersion("2", retrieveRename(t, t + "2"));
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    assertEquals("1", result.returnValue);
    rtype.loadNewVersion("3", retrieveRename(t, t + "3"));
    // Dont need to do this - think that is because of some of the constant
    // reinit stuff we already
    // drive in groovy
    rtype.runStaticInitializer();
    result = runUnguarded(rtype.getClazz(), "run");
    // ClassPrinter.print(rtype.getLatestExecutorBytes());
    assertEquals("4", result.returnValue);
  }
View Full Code Here

  @Test
  public void loadType2() {
    TypeRegistry typeRegistry = getTypeRegistry("data.SimpleClass");
    assertTrue(typeRegistry.isReloadableTypeName("data/SimpleClass"));
    byte[] dsc = loadBytesForClass("data.SimpleClass");
    ReloadableType rtype = typeRegistry.addType("data.SimpleClass", dsc);
    assertNotNull(rtype);
  }
View Full Code Here

    GlobalConfiguration.maxClassDefinitions = 4;

    TypeRegistry typeRegistry = getTypeRegistry(one + "," + two);

    ReloadableType tOne = typeRegistry.addType(one, loadBytesForClass(one));
    ReloadableType tTwo = typeRegistry.addType(two, loadBytesForClass(two));

    result = runUnguarded(tOne.getClazz(), "getValue");
    assertEquals(5, result.returnValue);

    // Should be nothing defined in the child loader
    assertEquals(0, typeRegistry.getChildClassLoader().getDefinedCount());

    tOne.loadNewVersion("002", retrieveRename(one, one + "002"));
    // Should be dispatcher and executor for the reloaded type
    assertEquals(2, typeRegistry.getChildClassLoader().getDefinedCount());
    assertEquals(7, runUnguarded(tOne.getClazz(), "getValue").returnValue);

    tTwo.loadNewVersion("002", tTwo.bytesInitial);
    assertEquals(4, typeRegistry.getChildClassLoader().getDefinedCount());
    result = runUnguarded(tOne.getClazz(), "getValue");
    assertEquals(5, runUnguarded(tTwo.getClazz(), "getValue").returnValue);

    Class<?> cOneExecutor = tOne.getLatestExecutorClass();

    tOne.loadNewVersion("003", tOne.bytesInitial);

    // Now on this reload the child classloader should be recreated as it already has more
    // than 2 defined.
    // Note: this will currently cause us to redefine all the reloadable types
    // according to their most recent version. An optimization may be to only
    // define them on demand
    tTwo.loadNewVersion("002", tTwo.bytesInitial);
    assertEquals(4, typeRegistry.getChildClassLoader().getDefinedCount());
    assertEquals(5, runUnguarded(tTwo.getClazz(), "getValue").returnValue);

    // But what about calling the older types?
    assertEquals(5, runUnguarded(tOne.getClazz(), "getValue").returnValue);
    if (cOneExecutor == tOne.getLatestExecutorClass()) {
      fail("Why are we not using a new executor? the old one should have been removed, freeing up the classloader");
View Full Code Here

    String two = "basic.BasicB";
    String three = "basic.BasicC";

    TypeRegistry typeRegistry = getTypeRegistry(one + "," + two + "," + three);

    ReloadableType tOne = typeRegistry.addType(one, loadBytesForClass(one));
    ReloadableType tTwo = typeRegistry.addType(two, loadBytesForClass(two));
    ReloadableType tThree = typeRegistry.addType(three, loadBytesForClass(three));

    result = runUnguarded(tOne.getClazz(), "getValue");
    assertEquals(5, result.returnValue);

    // Should be nothing defined in the child loader
    assertEquals(0, typeRegistry.getChildClassLoader().getDefinedCount());

    tOne.loadNewVersion("002", retrieveRename(one, one + "002"));
    // Should be dispatcher and executor for the reloaded type
    assertEquals(2, typeRegistry.getChildClassLoader().getDefinedCount());

    tTwo.loadNewVersion("002", tTwo.bytesInitial);
    assertEquals(4, typeRegistry.getChildClassLoader().getDefinedCount());

    tThree.loadNewVersion("002", tThree.bytesInitial);
    assertEquals(6, typeRegistry.getChildClassLoader().getDefinedCount());
  }
View Full Code Here

TOP

Related Classes of org.springsource.loaded.ReloadableType$MergedRewrite$ChainedAdapters

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.