Search in sources :

Example 6 with BufferWriteStream

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

the class AllSameStrategyTest method mergeUninitialized.

/**
 * Test if chunks that have not been passed to the initalize method can be merged
 * @param context the test context
 */
@Test
public void mergeUninitialized(TestContext context) {
    Async async = context.async();
    MergeStrategy strategy = new AllSameStrategy();
    BufferWriteStream bws = new BufferWriteStream();
    strategy.init(cm).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk1), cm, bws)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk2), cm, bws)).doOnNext(v -> strategy.finish(bws)).subscribe(v -> {
        context.assertEquals(XMLHEADER + "<root><test chunk=\"1\"></test><test chunk=\"2\"></test></root>", bws.getBuffer().toString("utf-8"));
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) 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) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Async(io.vertx.ext.unit.Async) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 7 with BufferWriteStream

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

the class AllSameStrategyTest method simple.

/**
 * Test a simple merge
 * @param context the test context
 */
@Test
public void simple(TestContext context) {
    Async async = context.async();
    MergeStrategy strategy = new AllSameStrategy();
    BufferWriteStream bws = new BufferWriteStream();
    strategy.init(cm).flatMap(v -> strategy.init(cm)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk1), cm, bws)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk2), cm, bws)).doOnNext(v -> strategy.finish(bws)).subscribe(v -> {
        context.assertEquals(XMLHEADER + "<root><test chunk=\"1\"></test><test chunk=\"2\"></test></root>", bws.getBuffer().toString("utf-8"));
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) 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) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Async(io.vertx.ext.unit.Async) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Example 8 with BufferWriteStream

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

the class XMLMergerTest method doMerge.

private void doMerge(TestContext context, Observable<Buffer> chunks, Observable<XMLChunkMeta> metas, String xmlContents) {
    XMLMerger m = new XMLMerger();
    BufferWriteStream bws = new BufferWriteStream();
    Async async = context.async();
    metas.flatMap(meta -> m.init(meta).map(v -> meta)).toList().flatMap(l -> chunks.map(DelegateChunkReadStream::new).<XMLChunkMeta, Pair<ChunkReadStream, XMLChunkMeta>>zipWith(l, Pair::of)).flatMap(p -> m.merge(p.getLeft(), p.getRight(), bws)).last().subscribe(v -> {
        m.finish(bws);
        context.assertEquals(XMLHEADER + xmlContents, 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) Arrays(java.util.Arrays) 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) 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) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Pair(org.apache.commons.lang3.tuple.Pair)

Example 9 with BufferWriteStream

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

the class MultiMergerTest method doMerge.

private void doMerge(TestContext context, Observable<Buffer> chunks, Observable<ChunkMeta> metas, String jsonContents) {
    MultiMerger m = new MultiMerger();
    BufferWriteStream bws = new BufferWriteStream();
    Async async = context.async();
    metas.flatMap(meta -> m.init(meta).map(v -> meta)).toList().flatMap(l -> chunks.map(DelegateChunkReadStream::new).<ChunkMeta, Pair<ChunkReadStream, ChunkMeta>>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) 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) Async(io.vertx.ext.unit.Async) BufferWriteStream(io.georocket.util.io.BufferWriteStream) GeoJsonChunkMeta(io.georocket.storage.GeoJsonChunkMeta) XMLChunkMeta(io.georocket.storage.XMLChunkMeta) ChunkMeta(io.georocket.storage.ChunkMeta) Pair(org.apache.commons.lang3.tuple.Pair)

Example 10 with BufferWriteStream

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

the class MergeNamespacesStrategyTest method simple.

/**
 * Test a simple merge
 * @param context the test context
 */
@Test
public void simple(TestContext context) {
    Async async = context.async();
    MergeStrategy strategy = new MergeNamespacesStrategy();
    BufferWriteStream bws = new BufferWriteStream();
    strategy.init(META1).flatMap(v -> strategy.init(META2)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(CHUNK1), META1, bws)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(CHUNK2), META2, bws)).doOnNext(v -> strategy.finish(bws)).subscribe(v -> {
        context.assertEquals(XMLHEADER + EXPECTEDROOT + CONTENTS1 + CONTENTS2 + "</" + EXPECTEDROOT.getName() + ">", bws.getBuffer().toString("utf-8"));
        async.complete();
    }, context::fail);
}
Also used : TestContext(io.vertx.ext.unit.TestContext) Async(io.vertx.ext.unit.Async) Arrays(java.util.Arrays) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Buffer(io.vertx.core.buffer.Buffer) BufferWriteStream(io.georocket.util.io.BufferWriteStream) 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) DelegateChunkReadStream(io.georocket.util.io.DelegateChunkReadStream) Async(io.vertx.ext.unit.Async) BufferWriteStream(io.georocket.util.io.BufferWriteStream) Test(org.junit.Test)

Aggregations

BufferWriteStream (io.georocket.util.io.BufferWriteStream)11 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)11 Buffer (io.vertx.core.buffer.Buffer)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