Package org.springsource.loaded

Examples of org.springsource.loaded.TypeRegistry


  }

  @Test
  public void descriptorsWithCatchers2() {
    // more complicated hierarchy
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    TypeDescriptor topDescriptor = typeRegistry.getDescriptorFor("catchers/Top");
    assertNotNull(topDescriptor);
    // Checking no toString() catcher because Top defines a toString()
    assertEquals(5, topDescriptor.getMethods().length);

    // if 'Top' is not considered reloadable we will get an entry for 'foo' that is inherited from it
    TypeDescriptor middleDescriptor = typeRegistry.getDescriptorFor("catchers/Middle");
    assertNotNull(middleDescriptor);
    assertEquals(5, middleDescriptor.getMethods().length);

    TypeDescriptor bottomDescriptor = typeRegistry.getDescriptorFor("catchers/Bottom");
    assertNotNull(bottomDescriptor);
    System.out.println(bottomDescriptor.toString());
    assertEquals(5, bottomDescriptor.getMethods().length);
  }
View Full Code Here


    assertEquals(5, bottomDescriptor.getMethods().length);
  }

  @Test
  public void includesExcludes() {
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    assertNotNull(typeRegistry);

    Properties p = new Properties();
    p.setProperty(TypeRegistry.Key_Inclusions, "com.foo.Bar");
    typeRegistry.configure(p);
    List<TypePattern> tps = typeRegistry.getInclusionPatterns();
    assertEquals(1, tps.size());
    assertEquals("text:com.foo.Bar", tps.get(0).toString());

    p.setProperty(TypeRegistry.Key_Inclusions, "com.foo.Bar,org.springsource..*");
    typeRegistry.configure(p);
    tps = typeRegistry.getInclusionPatterns();
    System.out.println(tps);
    assertEquals(2, tps.size());
    assertEquals("text:com.foo.Bar", tps.get(0).toString());
    assertEquals("text:org.springsource..*", tps.get(1).toString());
    assertTrue(typeRegistry.isReloadableTypeName("com/foo/Bar"));
    assertFalse(typeRegistry.isReloadableTypeName("com/foo/Garr"));
    assertTrue(typeRegistry.isReloadableTypeName("org/springsource/Garr"));
    assertTrue(typeRegistry.isReloadableTypeName("org/springsource/sub/Garr"));
    assertFalse(typeRegistry.isReloadableTypeName("Boo"));
  }
View Full Code Here

    assertFalse(typeRegistry.isReloadableTypeName("Boo"));
  }

  @Test
  public void includesExcludes2() {
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    assertNotNull(typeRegistry);

    Properties p = new Properties();
    p.setProperty(TypeRegistry.Key_Inclusions, "com.foo.Bar");
    typeRegistry.configure(p);
    List<TypePattern> tps = typeRegistry.getInclusionPatterns();
    assertEquals(1, tps.size());
    assertEquals("text:com.foo.Bar", tps.get(0).toString());
    assertFalse(tps.get(0).matches("com.foo.Gar"));
    assertTrue(tps.get(0).matches("com.foo.Bar"));

    p.setProperty(TypeRegistry.Key_Inclusions, "com.foo.Bar,org.springsource..*");
    typeRegistry.configure(p);
    tps = typeRegistry.getInclusionPatterns();
    assertEquals(2, tps.size());
    // exclude should be first
    assertEquals("text:com.foo.Bar", tps.get(0).toString());
    assertEquals("text:org.springsource..*", tps.get(1).toString());
    assertFalse(tps.get(0).matches("com.foo.Gar"));
    assertTrue(tps.get(0).matches("com.foo.Bar"));

    p.setProperty(TypeRegistry.Key_Inclusions, "com.foo..*");
    typeRegistry.configure(p);
    tps = typeRegistry.getInclusionPatterns();
    assertEquals(1, tps.size());
    assertFalse(tps.get(0).matches("com.goo.Bar"));
    assertTrue(tps.get(0).matches("com.foo.Bar"));
  }
View Full Code Here

    assertTrue(tps.get(0).matches("com.foo.Bar"));
  }

  @Test
  public void includesExcludes3() {
    TypeRegistry typeRegistry = TypeRegistry.getTypeRegistryFor(binLoader);
    assertNotNull(typeRegistry);

    Properties p = new Properties();
    p.setProperty(TypeRegistry.Key_Inclusions, "*");
    typeRegistry.configure(p);
    List<TypePattern> tps = typeRegistry.getInclusionPatterns();
    assertEquals(1, tps.size());
    assertEquals("text:*", tps.get(0).toString());
    assertTrue(tps.get(0).matches("wibble"));

    p.setProperty(TypeRegistry.Key_Exclusions, "*");
    typeRegistry.configure(p);
    tps = typeRegistry.getExclusionPatterns();
    assertEquals("text:*", tps.get(0).toString());
    assertTrue(tps.get(0).matches("wibble"));
  }
View Full Code Here

    assertTrue(tps.get(0).matches("wibble"));
  }

  @Test
  public void loadTypeBadNames() {
    TypeRegistry typeRegistry = getTypeRegistry("data.SimpleClass002");
    assertFalse(typeRegistry.isReloadableTypeName("data/SimpleClass"));
    assertFalse(typeRegistry.isReloadableTypeName("com/bar"));
  }
View Full Code Here

    assertFalse(typeRegistry.isReloadableTypeName("com/bar"));
  }

  @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

    assertNotNull(rtype);
  }

  @Test
  public void rebasePaths() {
    TypeRegistry typeRegistry = getTypeRegistry("data.SimpleClass");
    Properties p = new Properties();
    p.setProperty(TypeRegistry.Key_ReloadableRebase, "a/b/c=d/e/f,g/h=x/y");
    typeRegistry.configure(p);
    Map<String, String> rebases = typeRegistry.getRebasePaths();
    assertEquals(2, rebases.keySet().size());
    String value = rebases.get("a/b/c");
    assertEquals("d/e/f", value);
    assertEquals("x/y", rebases.get("g/h"));
  }
View Full Code Here

    String one = "basic.Basic";
    String two = "basic.BasicB";

    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()) {
View Full Code Here

  public void classloaderCounting() throws Exception {
    String one = "basic.Basic";
    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

  /**
   * Test extraction on a very simple class.
   */
  @Test
  public void simpleExtractor() {
    TypeRegistry tr = getTypeRegistry("");
    byte[] bytes = loadBytesForClass("data.SimpleClass");
    TypeDescriptor typeDescriptor = new TypeDescriptorExtractor(tr).extract(bytes, true);
    Assert.assertEquals("data/SimpleClass", typeDescriptor.getName());
    Assert.assertEquals("java/lang/Object", typeDescriptor.getSupertypeName());
    Assert.assertEquals(0, typeDescriptor.getSuperinterfacesName().length);
View Full Code Here

TOP

Related Classes of org.springsource.loaded.TypeRegistry

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.