Skip to content

Instantly share code, notes, and snippets.

@Jotschi
Created December 21, 2017 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jotschi/76ba42e7dc66a4a280b1323599152364 to your computer and use it in GitHub Desktop.
Save Jotschi/76ba42e7dc66a4a280b1323599152364 to your computer and use it in GitHub Desktop.
Vert.x 3.5.0 RxJava2 PumpTest
import static org.junit.Assert.assertEquals;
import java.io.File;
import java.io.IOException;
import org.apache.commons.io.FileUtils;
import org.junit.Test;
import io.reactivex.Observable;
import io.vertx.core.file.OpenOptions;
import io.vertx.reactivex.core.Vertx;
import io.vertx.reactivex.core.buffer.Buffer;
import io.vertx.reactivex.core.file.AsyncFile;
import io.vertx.reactivex.core.streams.Pump;
public class PumpTest {
@Test
public void testPump() throws IOException {
Vertx vertx = Vertx.vertx();
File file = new File("target/test");
file.delete();
Observable<Buffer> rs = Observable.just(Buffer.buffer("test123"));
vertx.fileSystem().rxOpen(file.getAbsolutePath(), new OpenOptions()).map(f -> {
Pump pump = Pump.pump(rs, f);
pump.start();
return f;
}).map(AsyncFile::flush).toCompletable().blockingAwait();
assertEquals("test123", FileUtils.readFileToString(file));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment