use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.
the class MergeNamespacesStrategyTest method mergeUninitialized.
/**
* Make sure that chunks that have not been passed to the initalize method cannot be merged
* @param context the test context
*/
@Test
public void mergeUninitialized(TestContext context) {
Async async = context.async();
MergeStrategy strategy = new MergeNamespacesStrategy();
BufferWriteStream bws = new BufferWriteStream();
strategy.init(META1).flatMap(v -> strategy.merge(new DelegateChunkReadStream(CHUNK1), META1, bws)).flatMap(v -> strategy.merge(new DelegateChunkReadStream(CHUNK2), META2, 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 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);
}
use of io.georocket.util.io.DelegateChunkReadStream 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);
}
use of io.georocket.util.io.DelegateChunkReadStream 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);
});
}
use of io.georocket.util.io.DelegateChunkReadStream in project georocket by georocket.
the class S3Store method getOne.
@Override
public void getOne(String path, Handler<AsyncResult<ChunkReadStream>> handler) {
String key = PathUtils.removeLeadingSlash(PathUtils.normalize(path));
vertx.<URL>executeBlocking(f -> {
f.complete(generatePresignedUrl(key, HttpMethod.GET));
}, ar -> {
if (ar.failed()) {
handler.handle(Future.failedFuture(ar.cause()));
return;
}
URL u = ar.result();
log.debug("GET " + u);
HttpClientRequest request = client.get(ar.result().getFile());
request.putHeader("Host", u.getHost());
request.exceptionHandler(t -> {
handler.handle(Future.failedFuture(t));
});
request.handler(response -> {
if (response.statusCode() == 200) {
String contentLength = response.getHeader("Content-Length");
long chunkSize = Long.parseLong(contentLength);
handler.handle(Future.succeededFuture(new DelegateChunkReadStream(chunkSize, response)));
} else {
Buffer errorBody = Buffer.buffer();
response.handler(buf -> {
errorBody.appendBuffer(buf);
});
response.endHandler(v -> {
log.error(errorBody);
handler.handle(Future.failedFuture(response.statusMessage()));
});
}
});
request.end();
});
}
Aggregations