Search in sources :

Example 1 with StoreEvent

use of org.apache.sis.storage.event.StoreEvent in project geotoolkit by Geomatys.

the class WeakListenerTest method testWeakStorageListener.

/**
 * Test no memory leak in weak style listener
 */
@Test
public void testWeakStorageListener() throws DataStoreException {
    FeatureTypeBuilder ftb = new FeatureTypeBuilder();
    ftb.setName("test1");
    ftb.addAttribute(Integer.class).setName("att");
    final FeatureType type1 = ftb.build();
    ftb = new FeatureTypeBuilder();
    ftb.setName("test2");
    ftb.addAttribute(Integer.class).setName("att2");
    final FeatureType type2 = ftb.build();
    final AtomicInteger count = new AtomicInteger(0);
    final InMemoryAggregate store = new InMemoryAggregate();
    StoreListener listener = new StoreListener() {

        @Override
        public void eventOccured(StoreEvent event) {
            count.incrementAndGet();
        }
    };
    final StorageListener.Weak ref = new StorageListener.Weak(listener);
    ref.registerSource(store);
    store.add(new DefiningFeatureSet(type1, null));
    assertEquals(1, count.get());
    listener = null;
    System.gc();
    store.add(new DefiningFeatureSet(type2, null));
    // listener should have desapear now, so the event should not have been send
    assertEquals(1, count.get());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StorageListener(org.geotoolkit.storage.event.StorageListener) InMemoryAggregate(org.geotoolkit.storage.memory.InMemoryAggregate) StoreListener(org.apache.sis.storage.event.StoreListener) StoreEvent(org.apache.sis.storage.event.StoreEvent) DefiningFeatureSet(org.geotoolkit.storage.feature.DefiningFeatureSet) Test(org.junit.Test)

Example 2 with StoreEvent

use of org.apache.sis.storage.event.StoreEvent in project geotoolkit by Geomatys.

the class CachedTiledGridCoverageResourceTest method testUpdate.

/**
 * Test cache pyramid updates it's structure and clear it's cache on parent update.
 */
@Test
public void testUpdate() throws DataStoreException {
    final InMemoryTiledGridCoverageResource parent = new InMemoryTiledGridCoverageResource(Names.createLocalName(null, null, "test"));
    final CachedTiledGridCoverageResource r = new CachedTiledGridCoverageResource(parent, 30, 60, true);
    final List<StoreEvent> events = new ArrayList<>();
    r.addListener(StoreEvent.class, new StoreListener<StoreEvent>() {

        @Override
        public void eventOccured(StoreEvent event) {
            events.add(event);
        }
    });
    // change parent structure
    final TileMatrixSet tileMatrixSet = (TileMatrixSet) parent.createTileMatrixSet(TileMatrices.createWorldWGS84Template(1));
    Assert.assertEquals(1, events.size());
    events.clear();
    // write a new tile
    final TileMatrix tileMatrix = tileMatrixSet.getTileMatrices().iterator().next();
    final ImageTile it = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
    tileMatrix.writeTiles(Stream.of(it), null);
    Assert.assertEquals(1, events.size());
    events.clear();
    // update existing tile
    final ImageTile it2 = new DefaultImageTile(new BufferedImage(256, 256, BufferedImage.TYPE_INT_ARGB), 0, 0);
    tileMatrix.writeTiles(Stream.of(it2), null);
    Assert.assertEquals(1, events.size());
    events.clear();
}
Also used : TileMatrixSet(org.geotoolkit.storage.multires.TileMatrixSet) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) ImageTile(org.geotoolkit.storage.coverage.ImageTile) ArrayList(java.util.ArrayList) DefaultImageTile(org.geotoolkit.storage.coverage.DefaultImageTile) StoreEvent(org.apache.sis.storage.event.StoreEvent) TileMatrix(org.geotoolkit.storage.multires.TileMatrix) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Example 3 with StoreEvent

use of org.apache.sis.storage.event.StoreEvent in project geotoolkit by Geomatys.

the class WebMapTileClientTest method testUpdateSequence.

/**
 * Test update sequence updates child resources.
 */
@Test
public void testUpdateSequence() throws MalformedURLException, JAXBException, DataStoreException, FactoryException {
    Capabilities capa1 = WMTSBindingUtilities.unmarshall(WebMapTileClientTest.class.getResource("/org/geotoolkit/wmts/UpdateSequence1.xml"), WMTSVersion.v100);
    Capabilities capa2 = WMTSBindingUtilities.unmarshall(WebMapTileClientTest.class.getResource("/org/geotoolkit/wmts/UpdateSequence2.xml"), WMTSVersion.v100);
    final WebMapTileClient wmts = new WebMapTileClient(new URL("http://localhost:8080/wmts"), null, WMTSVersion.v100, capa1, true);
    final GridCoverageResource resource = (GridCoverageResource) wmts.findResource("PROFONDEUR_RGB_pyramid");
    final AtomicBoolean updated = new AtomicBoolean(false);
    resource.addListener(StoreEvent.class, new StoreListener<StoreEvent>() {

        @Override
        public void eventOccured(StoreEvent event) {
            updated.set(true);
        }
    });
    Assert.assertEquals(CommonCRS.WGS84.normalizedGeographic(), resource.getGridGeometry().getCoordinateReferenceSystem());
    Assert.assertEquals(false, updated.get());
    wmts.checkForUpdates(capa2);
    Assert.assertEquals(true, updated.get());
    Assert.assertEquals(CommonCRS.NAD83.normalizedGeographic(), resource.getGridGeometry().getCoordinateReferenceSystem());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Capabilities(org.geotoolkit.wmts.xml.v100.Capabilities) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) URL(java.net.URL) StoreEvent(org.apache.sis.storage.event.StoreEvent) Test(org.junit.Test)

Aggregations

StoreEvent (org.apache.sis.storage.event.StoreEvent)3 Test (org.junit.Test)3 BufferedImage (java.awt.image.BufferedImage)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)1 GridCoverageResource (org.apache.sis.storage.GridCoverageResource)1 StoreListener (org.apache.sis.storage.event.StoreListener)1 DefaultImageTile (org.geotoolkit.storage.coverage.DefaultImageTile)1 ImageTile (org.geotoolkit.storage.coverage.ImageTile)1 StorageListener (org.geotoolkit.storage.event.StorageListener)1 DefiningFeatureSet (org.geotoolkit.storage.feature.DefiningFeatureSet)1 InMemoryAggregate (org.geotoolkit.storage.memory.InMemoryAggregate)1 TileMatrix (org.geotoolkit.storage.multires.TileMatrix)1 TileMatrixSet (org.geotoolkit.storage.multires.TileMatrixSet)1 Capabilities (org.geotoolkit.wmts.xml.v100.Capabilities)1 FeatureType (org.opengis.feature.FeatureType)1