Search in sources :

Example 1 with ChunkReadStream

use of io.georocket.storage.ChunkReadStream 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 2 with ChunkReadStream

use of io.georocket.storage.ChunkReadStream 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 3 with ChunkReadStream

use of io.georocket.storage.ChunkReadStream 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 4 with ChunkReadStream

use of io.georocket.storage.ChunkReadStream in project georocket by georocket.

the class FileStore method getOne.

@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
    String absolutePath = Paths.get(root, path).toString();
    // check if chunk exists
    FileSystem fs = vertx.fileSystem();
    ObservableFuture<Boolean> observable = RxHelper.observableFuture();
    fs.exists(absolutePath, observable.toHandler());
    observable.flatMap(exists -> {
        if (!exists) {
            return Observable.error(new FileNotFoundException("Could not find chunk: " + path));
        }
        return Observable.just(exists);
    }).flatMap(exists -> {
        // get chunk's size
        ObservableFuture<FileProps> propsObservable = RxHelper.observableFuture();
        fs.props(absolutePath, propsObservable.toHandler());
        return propsObservable;
    }).map(props -> props.size()).flatMap(size -> {
        // open chunk
        ObservableFuture<AsyncFile> openObservable = RxHelper.observableFuture();
        OpenOptions openOptions = new OpenOptions().setCreate(false).setWrite(false);
        fs.open(absolutePath, openOptions, openObservable.toHandler());
        return openObservable.map(f -> new FileChunkReadStream(size, f));
    }).subscribe(readStream -> {
        // send chunk to peer
        handler.handle(Future.succeededFuture(readStream));
    }, err -> {
        handler.handle(Future.failedFuture(err));
    });
}
Also used : PathUtils(io.georocket.util.PathUtils) AsyncFile(io.vertx.core.file.AsyncFile) OpenOptions(io.vertx.core.file.OpenOptions) ObservableFuture(io.vertx.rx.java.ObservableFuture) IndexedStore(io.georocket.storage.indexed.IndexedStore) Vertx(io.vertx.core.Vertx) Future(io.vertx.core.Future) FileNotFoundException(java.io.FileNotFoundException) FileProps(io.vertx.core.file.FileProps) Observable(rx.Observable) Buffer(io.vertx.core.buffer.Buffer) Paths(java.nio.file.Paths) FileSystem(io.vertx.core.file.FileSystem) RxHelper(io.vertx.rx.java.RxHelper) Preconditions(com.google.common.base.Preconditions) Queue(java.util.Queue) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) ChunkReadStream(io.georocket.storage.ChunkReadStream) ConfigConstants(io.georocket.constants.ConfigConstants) OpenOptions(io.vertx.core.file.OpenOptions) ObservableFuture(io.vertx.rx.java.ObservableFuture) FileSystem(io.vertx.core.file.FileSystem) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

ChunkReadStream (io.georocket.storage.ChunkReadStream)4 Buffer (io.vertx.core.buffer.Buffer)4 Observable (rx.Observable)4 BufferWriteStream (io.georocket.util.io.BufferWriteStream)3 DelegateChunkReadStream (io.georocket.util.io.DelegateChunkReadStream)3 Async (io.vertx.ext.unit.Async)3 TestContext (io.vertx.ext.unit.TestContext)3 RunTestOnContext (io.vertx.ext.unit.junit.RunTestOnContext)3 VertxUnitRunner (io.vertx.ext.unit.junit.VertxUnitRunner)3 Pair (org.apache.commons.lang3.tuple.Pair)3 Rule (org.junit.Rule)3 Test (org.junit.Test)3 RunWith (org.junit.runner.RunWith)3 GeoJsonChunkMeta (io.georocket.storage.GeoJsonChunkMeta)2 XMLChunkMeta (io.georocket.storage.XMLChunkMeta)2 XMLStartElement (io.georocket.util.XMLStartElement)2 Arrays (java.util.Arrays)2 Preconditions (com.google.common.base.Preconditions)1 ConfigConstants (io.georocket.constants.ConfigConstants)1 ChunkMeta (io.georocket.storage.ChunkMeta)1