Search in sources :

Example 86 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method invokeStaticReloading_gh4_1.

// github issue 4
@Test
public void invokeStaticReloading_gh4_1() throws Exception {
    TypeRegistry tr = getTypeRegistry("invokestatic..*");
    tr.addType("invokestatic.issue4.A", loadBytesForClass("invokestatic.issue4.A"));
    ReloadableType B = tr.addType("invokestatic.issue4.B", loadBytesForClass("invokestatic.issue4.B"));
    Result r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("String1", r.returnValue);
    B.loadNewVersion(B.bytesInitial);
    r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("String1", r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 87 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method callIt.

/**
	 * Check calling it, reloading it and calling the new version.
	 */
@Test
public void callIt() throws Exception {
    TypeRegistry typeRegistry = getTypeRegistry("basic.Basic");
    byte[] sc = loadBytesForClass("basic.Basic");
    ReloadableType rtype = typeRegistry.addType("basic.Basic", sc);
    Class<?> simpleClass = rtype.getClazz();
    Result r = runUnguarded(simpleClass, "foo");
    r = runUnguarded(simpleClass, "getValue");
    assertEquals(5, r.returnValue);
    rtype.loadNewVersion("002", retrieveRename("basic.Basic", "basic.Basic002"));
    r = runUnguarded(simpleClass, "getValue");
    assertEquals(7, r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 88 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method invokeStaticReloading_gh4_4.

@Test
public void invokeStaticReloading_gh4_4() throws Exception {
    TypeRegistry tr = getTypeRegistry("invokestatic..*");
    ReloadableType A = tr.addType("invokestatic.issue4.A", loadBytesForClass("invokestatic.issue4.A"));
    ReloadableType B = tr.addType("invokestatic.issue4.B", loadBytesForClass("invokestatic.issue4.B"));
    Result r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("String1", r.returnValue);
    A.loadNewVersion(A.bytesInitial);
    B.loadNewVersion(B.bytesInitial);
    r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("String1", r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 89 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method invokeStaticReloading_gh4_6.

// extra class in the middle: A in jar, subtype AB reloadable, subtype BBBBB reloadable
@Test
public void invokeStaticReloading_gh4_6() throws Exception {
    TypeRegistry tr = getTypeRegistry("invokestatic.issue4..*");
    tr.addType("invokestatic.issue4.AB", loadBytesForClass("invokestatic.issue4.AB"));
    ReloadableType B = tr.addType("invokestatic.issue4.BBBBB", loadBytesForClass("invokestatic.issue4.BBBBB"));
    Result r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("Hello", r.returnValue);
    ReloadableType thesuper = B.getSuperRtype();
    thesuper = tr.getReloadableType("invokestatic/issue4/subpkg/AAAA");
    assertNull(thesuper);
    B.loadNewVersion(B.bytesInitial);
    r = runUnguarded(B.getClazz(), "getMessage");
    assertEquals("Hello", r.returnValue);
}
Also used : ReloadableType(org.springsource.loaded.ReloadableType) TypeRegistry(org.springsource.loaded.TypeRegistry) Result(org.springsource.loaded.test.infra.Result) Test(org.junit.Test)

Example 90 with TypeRegistry

use of org.springsource.loaded.TypeRegistry in project spring-loaded by spring-projects.

the class ReloadableTypeTests method serialization3.

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

Aggregations

TypeRegistry (org.springsource.loaded.TypeRegistry)322 Test (org.junit.Test)305 ReloadableType (org.springsource.loaded.ReloadableType)287 Result (org.springsource.loaded.test.infra.Result)97 TestClassloaderWithRewriting (org.springsource.loaded.test.infra.TestClassloaderWithRewriting)24 InvocationTargetException (java.lang.reflect.InvocationTargetException)20 TypeDescriptor (org.springsource.loaded.TypeDescriptor)20 Ignore (org.junit.Ignore)17 Method (java.lang.reflect.Method)13 TypeDescriptorExtractor (org.springsource.loaded.TypeDescriptorExtractor)13 MethodMember (org.springsource.loaded.MethodMember)10 IOException (java.io.IOException)5 Properties (java.util.Properties)5 ResultException (org.springsource.loaded.test.infra.ResultException)5 IncrementalTypeDescriptor (org.springsource.loaded.IncrementalTypeDescriptor)4 LoadtimeInstrumentationPlugin (org.springsource.loaded.LoadtimeInstrumentationPlugin)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 ZipEntry (java.util.zip.ZipEntry)3 ZipFile (java.util.zip.ZipFile)3