use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.
the class MockStore method getOne.
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
Buffer chunk = Buffer.buffer(RETURNED_CHUNK);
handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunk)));
}
use of io.georocket.util.io.DelegateChunkReadStream 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);
});
}
use of io.georocket.util.io.DelegateChunkReadStream 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);
}
use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.
the class AllSameStrategyTest method mergeFail.
/**
* Test if the merge method fails if it is called with an unexpected chunk
* @param context the test context
*/
@Test
public void mergeFail(TestContext context) {
XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("other")), 10, 20);
Async async = context.async();
MergeStrategy strategy = new AllSameStrategy();
BufferWriteStream bws = new BufferWriteStream();
strategy.init(cm).flatMap(v -> strategy.merge(new DelegateChunkReadStream(chunk2), cm2, bws)).subscribe(v -> context.fail(), err -> {
context.assertTrue(err instanceof IllegalArgumentException);
async.complete();
});
}
use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.
the class MemoryStore method getOne.
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
String finalPath = PathUtils.normalize(path);
getStore(ar -> {
if (ar.failed()) {
handler.handle(Future.failedFuture(ar.cause()));
} else {
ar.result().get(finalPath, gar -> {
if (gar.failed()) {
handler.handle(Future.failedFuture(gar.cause()));
} else {
Buffer chunk = gar.result();
if (chunk == null) {
handler.handle(Future.failedFuture(new FileNotFoundException("Could not find chunk: " + finalPath)));
return;
}
handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunk)));
}
});
}
});
}
Aggregations