use of io.vertx.core.streams.WriteStream in project georocket by georocket.
the class StoreClientImportTest method importCRS.
/**
* Test importing tags and properties
* @param context the test context
* @throws Exception if something goes wrong
*/
@Test
public void importCRS(TestContext context) throws Exception {
String url = "/store?fallbackCRS=test";
stubFor(post(urlEqualTo(url)).willReturn(aResponse().withStatus(202)));
Async async = context.async();
WriteStream<Buffer> w = client.getStore().startImport(null, null, null, Optional.empty(), "test", context.asyncAssertSuccess(v -> {
verifyPosted(url, XML, context);
async.complete();
}));
w.end(Buffer.buffer(XML));
}
use of io.vertx.core.streams.WriteStream in project georocket by georocket.
the class StoreClientImportTest method importTagsAndCRS.
/**
* Test importing tags and properties
* @param context the test context
* @throws Exception if something goes wrong
*/
@Test
public void importTagsAndCRS(TestContext context) throws Exception {
String url = "/store?tags=testTag%2CtestTag2&props=" + "hello%3Awo%5C%3Arld%2Challo2%3Aworld2&fallbackCRS=test";
stubFor(post(urlEqualTo(url)).willReturn(aResponse().withStatus(202)));
Async async = context.async();
WriteStream<Buffer> w = client.getStore().startImport(null, Arrays.asList("testTag", "testTag2"), Arrays.asList("hello:wo\\:rld", "hallo2:world2"), Optional.empty(), "test", context.asyncAssertSuccess(v -> {
verifyPosted(url, XML, context);
async.complete();
}));
w.end(Buffer.buffer(XML));
}
use of io.vertx.core.streams.WriteStream in project georocket by georocket.
the class StoreEndpoint method doMerge.
/**
* Perform a search and merge all retrieved chunks using the given merger
* @param merger the merger
* @param data Data to merge into the response
* @param out the response to write the merged chunks to
* @return a single that will emit one item when all chunks have been merged
*/
private Single<Void> doMerge(Merger<ChunkMeta> merger, Single<StoreCursor> data, WriteStream<Buffer> out) {
return data.map(RxStoreCursor::new).flatMapObservable(RxStoreCursor::toObservable).flatMap(p -> store.rxGetOne(p.getRight()).flatMapObservable(crs -> merger.merge(crs, p.getLeft(), out).map(// left: count, right: not_accepted
v -> Pair.of(1L, 0L)).onErrorResumeNext(t -> {
if (t instanceof IllegalStateException) {
// ignore it, but emit a warning later
return Observable.just(Pair.of(0L, 1L));
}
return Observable.error(t);
}).doOnTerminate(() -> {
// don't forget to close the chunk!
crs.close();
})), 1).defaultIfEmpty(Pair.of(0L, 0L)).reduce((p1, p2) -> Pair.of(p1.getLeft() + p2.getLeft(), p1.getRight() + p2.getRight())).flatMap(p -> {
long count = p.getLeft();
long notaccepted = p.getRight();
if (notaccepted > 0) {
log.warn("Could not merge " + notaccepted + " chunks " + "because the merger did not accept them. Most likely " + "these are new chunks that were added while the " + "merge was in progress. If this worries you, just " + "repeat the request.");
}
if (count > 0) {
merger.finish(out);
return Observable.just(null);
} else {
return Observable.error(new FileNotFoundException("Not Found"));
}
}).toSingle().map(v -> null);
}
use of io.vertx.core.streams.WriteStream in project vert.x by eclipse.
the class FileSystemTest method testPumpFileStreams.
@Test
@SuppressWarnings("unchecked")
public void testPumpFileStreams() throws Exception {
String fileName1 = "some-file.dat";
String fileName2 = "some-other-file.dat";
// Non integer multiple of buffer size
int fileSize = (int) (AsyncFileImpl.DEFAULT_READ_BUFFER_SIZE * 1000.3);
byte[] content = TestUtils.randomByteArray(fileSize);
createFile(fileName1, content);
vertx.fileSystem().open(testDir + pathSep + fileName1, new OpenOptions(), arr -> {
if (arr.succeeded()) {
ReadStream rs = arr.result();
// Open file for writing
vertx.fileSystem().open(testDir + pathSep + fileName2, new OpenOptions(), ar -> {
if (ar.succeeded()) {
WriteStream ws = ar.result();
Pump p = Pump.pump(rs, ws);
p.start();
rs.endHandler(v -> {
arr.result().close(car -> {
if (car.failed()) {
fail(ar.cause().getMessage());
} else {
ar.result().close(ar2 -> {
if (ar2.failed()) {
fail(ar2.cause().getMessage());
} else {
assertTrue(fileExists(fileName2));
byte[] readBytes;
try {
readBytes = Files.readAllBytes(Paths.get(testDir + pathSep + fileName2));
} catch (IOException e) {
fail(e.getMessage());
return;
}
assertEquals(Buffer.buffer(content), Buffer.buffer(readBytes));
testComplete();
}
});
}
});
});
} else {
fail(ar.cause().getMessage());
}
});
} else {
fail(arr.cause().getMessage());
}
});
await();
}
use of io.vertx.core.streams.WriteStream in project java-chassis by ServiceComb.
the class TestReadStreamPart method saveToWriteStream.
@Test
public void saveToWriteStream() throws InterruptedException, ExecutionException {
Buffer buf = Buffer.buffer();
WriteStream<Buffer> writeStream = new MockUp<WriteStream<Buffer>>() {
@Mock
WriteStream<Buffer> write(Buffer data) {
buf.appendBuffer(data);
return null;
}
}.getMockInstance();
part.saveToWriteStream(writeStream).get();
Assert.assertEquals(src, buf.toString());
}
Aggregations