Package org.springsource.loaded

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


 
  // The supertype is not reloadable,it is in a jar
  @Test
  public void invokeStaticReloading_gh4_5() throws Exception {
    TypeRegistry tr = getTypeRegistry("invokestatic.issue4..*");
    ReloadableType B = tr.addType("invokestatic.issue4.BBBB", loadBytesForClass("invokestatic.issue4.BBBB"));
   
    Result r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("Hello",(String)r.returnValue);
   
    ReloadableType thesuper = B.getSuperRtype();
    assertNull(thesuper);
    thesuper = tr.getReloadableType("invokestatic/issue4/subpkg/AAAA");
    assertNull(thesuper);
 
    B.loadNewVersion(B.bytesInitial);
View Full Code Here


 
  // Basic write/read then reload then write/read again
  @Test
  public void serialization1() 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
    // Tried running the Serialize code directly but with a clinit in the Person class: 2b4c0df4

    ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
   
    Result r = null;
    r = runUnguarded(runner.getClazz(), "run");
    assertContains("check ok", r.stdout);

    person.loadNewVersion("2",retrieveRename("remote.Person", "remote.Person2"));
   
    r = runUnguarded(runner.getClazz(), "run");
    assertContains("check ok", r.stdout);   
  }
View Full Code Here

  // Unlike the first test, this one will reload the class in between serialize and deserialize
  @Test
  public void serialization2() throws Exception {
    TypeRegistry tr = getTypeRegistry("remote..*");
    ReloadableType person = tr.addType("remote.Person", loadBytesForClass("remote.Person"));
   
    // byteinfo:len=98:crc=7e07276a
    ReloadableType runner = tr.addType("remote.Serialize", loadBytesForClass("remote.Serialize"));
   
    Class<?> clazz = runner.getClazz();
    Object instance = clazz.newInstance();
   
    Result r = null;
   
    // Basic: write and read the same Person
View Full Code Here

 
  // Variant of the second test but using serialVersionUID and adding methods to the class on reload
  @Test
  public void serialization3() throws Exception {
    TypeRegistry tr = getTypeRegistry("remote..*");
    ReloadableType person = tr.addType("remote.PersonB", loadBytesForClass("remote.PersonB"));
    ReloadableType runner = tr.addType("remote.SerializeB", loadBytesForClass("remote.SerializeB"));
   
    Class<?> clazz = runner.getClazz();
    Object instance = clazz.newInstance();
   
    Result r = null;
   
    // Basic: write and read the same Person
    r = runOnInstance(runner.getClazz(),instance,"writePerson");
    assertStdoutContains("Person stored ok", r);
    r = runOnInstance(runner.getClazz(),instance,"readPerson");
    assertContains("Person read ok", r.stdout);

    // Advanced: write it, reload, then read back from the written form
    r = runOnInstance(runner.getClazz(),instance,"writePerson");
    assertStdoutContains("Person stored ok", r);
    person.loadNewVersion("2",retrieveRename("remote.PersonB", "remote.PersonB2"));
    r = runOnInstance(runner.getClazz(),instance,"readPerson");
    assertContains("Person read ok", r.stdout);
   
    r = runOnInstance(clazz,instance,"printInitials");
    assertContains("Person read ok\nWS", r.stdout);
  }
View Full Code Here

  public void newConstructors2() throws Exception {
    String caller = "ctors.CallerB";
    String callee = "ctors.CalleeB";
    String calleeSuper = "ctors.CalleeSuperB";
    TypeRegistry r = getTypeRegistry(caller + "," + callee + "," + calleeSuper);
    ReloadableType rcaller = r.addType(caller, loadBytesForClass(caller));
    ReloadableType rcalleeSuper = r.addType(calleeSuper, loadBytesForClass(calleeSuper));
    ReloadableType rcallee = r.addType(callee, loadBytesForClass(callee));
    Result res = null;

    // Use the code 'untouched'
    Object callerInstance = rcaller.getClazz().newInstance();
    res = runOnInstance(rcaller.getClazz(), callerInstance, "runA");
    assertEquals("callee", res.returnValue.toString());

    // Reload the code, a new constructor in the callee and runB() invokes it
    rcalleeSuper.loadNewVersion("002", retrieveRename(calleeSuper, calleeSuper + "2"));
    rcaller.loadNewVersion("002", retrieveRename(caller, caller + "2", "ctors.CalleeB2:ctors.CalleeB"));
    rcallee.loadNewVersion("002", retrieveRename(callee, callee + "2", "ctors.CalleeSuperB2:ctors.CalleeSuperB"));

    // The new runB() method will include a call 'new Callee("abcde")'
    // Without a rewrite, it will cause this problem:
    // Caused by: java.lang.NoSuchMethodError: ctors.Callee.<init>(Ljava/lang/String;)V
    //   at ctors.Caller__E002.runB(Caller2.java:10)
View Full Code Here

  @Test
  public void rewriteInstanceFields() throws Exception {
    // turn off to simplify debugging verify problems:
    // GlobalConfiguration.rewriteMethodExecutions = false;
    TypeRegistry r = getTypeRegistry("data.HelloWorldFields");
    ReloadableType rtype = r.addType("data.HelloWorldFields", loadBytesForClass("data.HelloWorldFields"));
    assertEquals("Hello Andy", runUnguarded(rtype.getClazz(), "greet").stdout);

    // Just reload that same version (creates new CurrentLiveVersion)
    rtype.loadNewVersion("000", rtype.bytesInitial);
    assertEquals("Hello Andy", runUnguarded(rtype.getClazz(), "greet").stdout);

    // Load a real new version
    rtype.loadNewVersion("002", retrieveRename("data.HelloWorldFields", "data.HelloWorldFields002"));
    assertEquals("Hello Christian", runUnguarded(rtype.getClazz(), "greet").stdout);

    Object o = rtype.getClazz().newInstance();
    assertEquals("Hello Christian", runOnInstance(rtype.getClazz(), o, "greet").stdout);
    runOnInstance(rtype.getClazz(), o, "setMessage", "Hello Christian");
    assertEquals("Hello Christian", runOnInstance(rtype.getClazz(), o, "greet").stdout);
  }
View Full Code Here

  }

  @Test
  public void primitiveFieldRewriting() throws Exception {
    TypeRegistry r = getTypeRegistry("data.FieldsB");
    ReloadableType rtype = r.addType("data.FieldsB", loadBytesForClass("data.FieldsB"));
    Class<?> c = rtype.getClazz();
    Object instance = c.newInstance();
    assertEquals(23, runOnInstance(c, instance, "getI").returnValue);
    assertEquals("{1,2,3}", intArrayToString(runOnInstance(c, instance, "getIs").returnValue));
    assertEquals(false, runOnInstance(c, instance, "isB").returnValue);
    assertEquals('a', runOnInstance(c, instance, "getC").returnValue);
View Full Code Here

  }

  @Test
  public void primitiveStaticFieldRewriting() throws Exception {
    TypeRegistry r = getTypeRegistry("data.StaticFieldsB");
    ReloadableType rtype = r.addType("data.StaticFieldsB", loadBytesForClass("data.StaticFieldsB"));
    Class<?> c = rtype.getClazz();
    Object instance = c.newInstance();
    assertEquals(23, runOnInstance(c, instance, "getI").returnValue);
    assertEquals(false, runOnInstance(c, instance, "isB").returnValue);
    assertEquals("{true,false,true}", objectArrayToString(runOnInstance(c, instance, "getBs").returnValue));
    assertEquals('a', runOnInstance(c, instance, "getC").returnValue);
View Full Code Here

  @Test
  public void rewriteStaticFields() throws Exception {
    // turn off to simplify debugging verify problems:
    // GlobalConfiguration.rewriteMethodExecutions = true;
    TypeRegistry r = getTypeRegistry("data.HelloWorldStaticFields");
    ReloadableType rtype = r.addType("data.HelloWorldStaticFields", loadBytesForClass("data.HelloWorldStaticFields"));
    assertEquals("Hello Andy", runUnguarded(rtype.getClazz(), "greet").stdout);

    // Just reload that same version (creates new CurrentLiveVersion)
    rtype.loadNewVersion("000", rtype.bytesInitial);
    assertEquals("Hello Andy", runUnguarded(rtype.getClazz(), "greet").stdout);

    // Load a real new version
    // won't say 'hello christian' because field static initializers are not re-run
    rtype.loadNewVersion("002", retrieveRename("data.HelloWorldStaticFields", "data.HelloWorldStaticFields002"));
    assertEquals("Hello Andy", runUnguarded(rtype.getClazz(), "greet").stdout);

    Object o = rtype.getClazz().newInstance();
    assertEquals("Hello Andy", runOnInstance(rtype.getClazz(), o, "greet").stdout);
    runOnInstance(rtype.getClazz(), o, "setMessage", "Hello Christian");
    assertEquals("Hello Christian", runOnInstance(rtype.getClazz(), o, "greet").stdout);
  }
View Full Code Here

   * Just does a rewrite and checks the result will run a simple method
   */
  @Test
  public void rewrite() throws Exception {
    TypeRegistry typeRegistry = getTypeRegistry("data.HelloWorld");
    ReloadableType rtype = typeRegistry.addType("data.HelloWorld", loadBytesForClass("data.HelloWorld"));
    runUnguarded(rtype.getClazz(), "greet");

    // Just transform the existing version into a dispatcher/executor
    rtype.loadNewVersion("000", rtype.bytesInitial);
    assertEquals("Greet from HelloWorld", runUnguarded(rtype.getClazz(), "greet").stdout);

    // Load a real new version
    rtype.loadNewVersion("002", retrieveRename("data.HelloWorld", "data.HelloWorld002"));
    assertEquals("Greet from HelloWorld 2", runUnguarded(rtype.getClazz(), "greet").stdout);
  }
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.