Пример #1
0
  @Test
  public void testAttributeCache() throws Exception {
    final Catalog catalog = getCatalog();
    ResourcePool pool = ResourcePool.create(catalog);

    // clean up the lakes type
    FeatureTypeInfo oldInfo =
        catalog.getFeatureTypeByName(
            MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart());
    List<LayerInfo> layers = catalog.getLayers(oldInfo);
    for (LayerInfo layerInfo : layers) {
      catalog.remove(layerInfo);
    }
    catalog.remove(oldInfo);

    // rebuild as new
    CatalogBuilder builder = new CatalogBuilder(catalog);
    builder.setStore(
        catalog.getStoreByName(MockData.CITE_PREFIX, MockData.CITE_PREFIX, DataStoreInfo.class));
    FeatureTypeInfo info =
        builder.buildFeatureType(
            new NameImpl(MockData.LAKES.getNamespaceURI(), MockData.LAKES.getLocalPart()));

    // non persisted state, caching should not occurr
    List<AttributeTypeInfo> att1 = pool.getAttributes(info);
    List<AttributeTypeInfo> att2 = pool.getAttributes(info);
    assertNotSame(att1, att2);
    assertEquals(att1, att2);

    // save it, making it persistent
    catalog.add(info);

    // first check caching actually works against persisted type infos
    List<AttributeTypeInfo> att3 = pool.getAttributes(info);
    List<AttributeTypeInfo> att4 = pool.getAttributes(info);
    assertSame(att3, att4);
    assertNotSame(att1, att3);
    assertEquals(att1, att3);
  }
Пример #2
0
  <T extends StoreInfo> void initStore(
      T s, Class<T> clazz, String sId, String name, WorkspaceInfo ws) {
    expect(s.getId()).andReturn(sId).anyTimes();
    expect(s.getName()).andReturn(name).anyTimes();
    expect(s.getWorkspace()).andReturn(ws).anyTimes();
    expect(s.getCatalog()).andReturn(catalog).anyTimes();
    expect(s.isEnabled()).andReturn(true).anyTimes();

    expect(catalog.getStore(sId, clazz)).andReturn(s).anyTimes();
    expect(catalog.getStore(sId, StoreInfo.class)).andReturn(s).anyTimes();

    expect(catalog.getStoreByName(name, clazz)).andReturn(s).anyTimes();
    expect(catalog.getStoreByName(name, StoreInfo.class)).andReturn(s).anyTimes();

    expect(catalog.getStoreByName(ws.getName(), name, clazz)).andReturn(s).anyTimes();
    expect(catalog.getStoreByName(ws.getName(), name, StoreInfo.class)).andReturn(s).anyTimes();

    expect(catalog.getStoreByName(ws, name, clazz)).andReturn(s).anyTimes();
    expect(catalog.getStoreByName(ws, name, StoreInfo.class)).andReturn(s).anyTimes();
  }