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)));
}
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();
});
}
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);
});
}
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);
}
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();
});
}
Aggregations