Search in sources :

Example 6 with GeoJsonChunkMeta

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();
    });
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) RunWith(org.junit.runner.RunWith) XMLStartElement(io.georocket.util.XMLStartElement) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) ChunkMeta(io.georocket.storage.ChunkMeta) Observable(rx.Observable) Rule(org.junit.Rule) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Pair(org.apache.commons.lang3.tuple.Pair) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ChunkReadStream(io.georocket.storage.ChunkReadStream) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) XMLStartElement(io.georocket.util.XMLStartElement) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 7 with GeoJsonChunkMeta

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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) Test(org.junit.Test)

Example 8 with GeoJsonChunkMeta

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);
    });
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Observable(rx.Observable) Rule(org.junit.Rule) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Pair(org.apache.commons.lang3.tuple.Pair) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ChunkReadStream(io.georocket.storage.ChunkReadStream) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Pair(org.apache.commons.lang3.tuple.Pair)

Example 9 with GeoJsonChunkMeta

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);
}
Also used : Buffer(io.vertx.core.buffer.Buffer) TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) RunWith(org.junit.runner.RunWith) Test(org.junit.Test) VertxUnitRunner(io.vertx.ext.unit.junit.VertxUnitRunner) Observable(rx.Observable) Rule(org.junit.Rule) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Pair(org.apache.commons.lang3.tuple.Pair) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) RunTestOnContext(io.vertx.ext.unit.junit.RunTestOnContext) ChunkReadStream(io.georocket.storage.ChunkReadStream) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Async(io.vertx.ext.unit.Async) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 10 with GeoJsonChunkMeta

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 + "]}");
}
Also used : Buffer(io.vertx.core.buffer.Buffer) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) Test(org.junit.Test)

Aggregations

GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)28 Test (org.junit.Test)27 Buffer (io.vertx.core.buffer.Buffer)17 JsonObject (io.vertx.core.json.JsonObject)11 Tuple2 (org.jooq.lambda.tuple.Tuple2)11 ChunkReadStream (io.georocket.storage.ChunkReadStream)5 BufferWriteStream (io.georocket.util.io.BufferWriteStream)5 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)5 Async (io.vertx.ext.unit.Async)5 TestContext (io.vertx.ext.unit.TestContext)5 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)5 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)5 Pair (org.apache.commons.lang3.tuple.Pair)5 Rule (org.junit.Rule)5 RunWith (org.junit.runner.RunWith)5 Observable (rx.Observable)5 ChunkMeta (io.georocket.storage.ChunkMeta)2 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)2 XMLStartElement (io.georocket.util.XMLStartElement)2 Arrays (java.util.Arrays)2