Search in sources :

Example 1 with DelegateChunkReadStream

use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.

the class H2Store method getOne.

@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
    String finalPath = PathUtils.normalize(path);
    String chunkStr = getMap().get(finalPath);
    if (chunkStr == null) {
        handler.handle(Future.failedFuture(new FileNotFoundException("Could not find chunk: " + finalPath)));
        return;
    }
    Buffer chunk = Buffer.buffer(chunkStr);
    handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunk)));
}
Also used : Buffer(io.vertx.core.buffer.Buffer) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) FileNotFoundException(java.io.FileNotFoundException)

Example 2 with DelegateChunkReadStream

use of io.georocket.util.io.DelegateChunkReadStream 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 3 with DelegateChunkReadStream

use of io.georocket.util.io.DelegateChunkReadStream 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 4 with DelegateChunkReadStream

use of io.georocket.util.io.DelegateChunkReadStream 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 5 with DelegateChunkReadStream

use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.

the class GeoJsonMergerTest method notEnoughInits.

/**
 * Test if the merger fails if {@link GeoJsonMerger#init(GeoJsonChunkMeta)} has
 * not been called often enough
 * @param context the Vert.x test context
 */
@Test
public void notEnoughInits(TestContext context) {
    String strChunk1 = "{\"type\":\"Feature\"}";
    String strChunk2 = "{\"type\":\"Feature\",\"properties\":{}}";
    Buffer chunk1 = Buffer.buffer(strChunk1);
    Buffer chunk2 = Buffer.buffer(strChunk2);
    GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length());
    GeoJsonChunkMeta cm2 = new GeoJsonChunkMeta("Feature", "features", 0, chunk2.length());
    GeoJsonMerger m = new GeoJsonMerger();
    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)).last().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) 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)

Aggregations

DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)15 Buffer (io.vertx.core.buffer.Buffer)15 BufferWriteStream (io.georocket.util.io.BufferWriteStream)11 Async (io.vertx.ext.unit.Async)11 TestContext (io.vertx.ext.unit.TestContext)11 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)11 Test (org.junit.Test)11 RunWith (org.junit.runner.RunWith)11 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)8 XMLStartElement (io.georocket.util.XMLStartElement)8 Arrays (java.util.Arrays)8 ChunkReadStream (io.georocket.storage.ChunkReadStream)6 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)6 Pair (org.apache.commons.lang3.tuple.Pair)6 Rule (org.junit.Rule)6 Observable (rx.Observable)6 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)5 ChunkMeta (io.georocket.storage.ChunkMeta)2 FileNotFoundException (java.io.FileNotFoundException)2 HttpClientRequest (io.vertx.core.http.HttpClientRequest)1