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());
}
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();
}
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());
}
Aggregations