use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.
the class MultiMergerTest method mixedMerge.
/**
* Test if the merger fails if chunks with a different type should be merged
* @param context the Vert.x test context
*/
@Test
public void mixedMerge(TestContext context) {
String strChunk1 = "{\"type\":\"Feature\"}";
String strChunk2 = XMLHEADER + "<root><test chunk=\"2\"></test></root>";
Buffer chunk1 = Buffer.buffer(strChunk1);
Buffer chunk2 = Buffer.buffer(strChunk2);
GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 6, chunk2.length() - 7);
MultiMerger m = new MultiMerger();
BufferWriteStream bws = new BufferWriteStream();
Async async = context.async();
m.init(cm1).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk1), cm1, bws)).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk2), cm2, bws)).subscribe(v -> {
context.fail();
}, err -> {
context.assertTrue(err instanceof IllegalStateException);
async.complete();
});
}
use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.
the class GeoJsonMergerTest method oneFeature.
/**
* Test if one feature is rendered directly
* @param context the Vert.x test context
*/
@Test
public void oneFeature(TestContext context) {
String strChunk1 = "{\"type\":\"Feature\"}";
Buffer chunk1 = Buffer.buffer(strChunk1);
GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
doMerge(context, Observable.just(chunk1), Observable.just(cm1), strChunk1);
}
use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.
the class GeoJsonMergerTest method doMerge.
private void doMerge(TestContext context, Observable<Buffer> chunks, Observable<GeoJsonChunkMeta> metas, String jsonContents) {
GeoJsonMerger m = new GeoJsonMerger();
BufferWriteStream bws = new BufferWriteStream();
Async async = context.async();
metas.flatMap(meta -> m.init(meta).map(v -> meta)).toList().flatMap(l -> chunks.map(DelegateChunkReadStream::new).<GeoJsonChunkMeta, Pair<ChunkReadStream, GeoJsonChunkMeta>>zipWith(l, Pair::of)).flatMap(p -> m.merge(p.getLeft(), p.getRight(), bws)).last().subscribe(v -> {
m.finish(bws);
context.assertEquals(jsonContents, bws.getBuffer().toString("utf-8"));
async.complete();
}, err -> {
context.fail(err);
});
}
use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.
the class GeoJsonMergerTest method enoughInits.
/**
* Test if the merger succeeds if {@link GeoJsonMerger#init(GeoJsonChunkMeta)} has
* not been called just often enough
* @param context the Vert.x test context
*/
@Test
public void enoughInits(TestContext context) {
String strChunk1 = "{\"type\":\"Feature\"}";
String strChunk2 = "{\"type\":\"Feature\",\"properties\":{}}";
String strChunk3 = "{\"type\":\"Polygon\"}";
Buffer chunk1 = Buffer.buffer(strChunk1);
Buffer chunk2 = Buffer.buffer(strChunk2);
Buffer chunk3 = Buffer.buffer(strChunk3);
GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
GeoJsonChunkMeta cm2 = new GeoJsonChunkMeta("Feature", "features", 0, chunk2.length());
GeoJsonChunkMeta cm3 = new GeoJsonChunkMeta("Polygon", "geometries", 0, chunk2.length());
String jsonContents = "{\"type\":\"FeatureCollection\",\"features\":[" + strChunk1 + "," + strChunk2 + ",{\"type\":\"Feature\",\"geometry\":" + strChunk3 + "}]}";
GeoJsonMerger m = new GeoJsonMerger();
BufferWriteStream bws = new BufferWriteStream();
Async async = context.async();
m.init(cm1).flatMap(v -> m.init(cm2)).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk1), cm1, bws)).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk2), cm2, bws)).flatMap(v -> m.merge(new DelegateChunkReadStream(chunk3), cm3, bws)).last().subscribe(v -> {
m.finish(bws);
context.assertEquals(jsonContents, bws.getBuffer().toString("utf-8"));
async.complete();
}, context::fail);
}
use of io.georocket.storage.GeoJsonChunkMeta in project georocket by georocket.
the class GeoJsonMergerTest method twoGeometriesAndAFeature.
/**
* Test if two geometries and a feature can be merged to a feature collection
* @param context the Vert.x test context
*/
@Test
public void twoGeometriesAndAFeature(TestContext context) {
String strChunk1 = "{\"type\":\"Polygon\"}";
String strChunk2 = "{\"type\":\"Point\"}";
String strChunk3 = "{\"type\":\"Feature\"}";
Buffer chunk1 = Buffer.buffer(strChunk1);
Buffer chunk2 = Buffer.buffer(strChunk2);
Buffer chunk3 = Buffer.buffer(strChunk3);
GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Polygon", "geometries", 0, chunk1.length());
GeoJsonChunkMeta cm2 = new GeoJsonChunkMeta("Point", "geometries", 0, chunk2.length());
GeoJsonChunkMeta cm3 = new GeoJsonChunkMeta("Feature", "features", 0, chunk3.length());
doMerge(context, Observable.just(chunk1, chunk2, chunk3), Observable.just(cm1, cm2, cm3), "{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":" + strChunk1 + "}," + "{\"type\":\"Feature\",\"geometry\":" + strChunk2 + "}," + strChunk3 + "]}");
}
Aggregations