use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.
the class MaintenanceTest method Testsnapshot.
// TODO: find a better way to test snapshot.
@Test
public void Testsnapshot() throws IOException {
// create snapshot.db file current folder.
String dir = Paths.get("").toAbsolutePath().toString();
File snapfile = new File(dir, "snapshot.db");
// leverage try-with-resources
try (Snapshot snapshot = maintenance.snapshot();
FileOutputStream fop = new FileOutputStream(snapfile)) {
snapshot.write(fop);
} catch (Exception e) {
snapfile.delete();
}
}
use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.
the class MaintenanceUnitTest method testWrite.
@Test(timeOut = 1000)
void testWrite() throws IOException {
Snapshot snapshot = maintenanceCli.snapshot();
ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteString blob = ByteString.copyFromUtf8("blob");
responseObserverRef.get().onNext(SnapshotResponse.newBuilder().setBlob(blob).setRemainingBytes(0).build());
responseObserverRef.get().onCompleted();
snapshot.write(out);
assertThat(out.toByteArray()).isEqualTo(blob.toByteArray());
}
use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.
the class MaintenanceUnitTest method testWriteTwice.
@Test(timeOut = 1000)
public void testWriteTwice() throws IOException {
Snapshot snapshot = maintenanceCli.snapshot();
responseObserverRef.get().onCompleted();
OutputStream out = new ByteArrayOutputStream();
snapshot.write(out);
assertThatThrownBy(() -> snapshot.write(out)).isInstanceOf(IOException.class).hasMessageContaining("write is called more than once");
}
use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.
the class MaintenanceUnitTest method testConnectionError.
@Test(timeOut = 1000)
public void testConnectionError() throws IOException {
Snapshot snapshot = maintenanceCli.snapshot();
OutputStream out = new ByteArrayOutputStream();
executor.execute(() -> {
try {
Thread.sleep(50);
responseObserverRef.get().onError(Status.ABORTED.asRuntimeException());
} catch (InterruptedException e) {
Assert.fail("expect no exception, but got InterruptedException", e);
}
});
assertThatThrownBy(() -> snapshot.write(out)).isInstanceOf(IOException.class).hasMessageContaining("connection error");
}
use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.
the class MaintenanceUnitTest method testCloseWhenWrite.
@Test(timeOut = 1000)
public void testCloseWhenWrite() throws IOException {
Snapshot snapshot = maintenanceCli.snapshot();
OutputStream out = new ByteArrayOutputStream();
executor.execute(() -> {
try {
Thread.sleep(50);
snapshot.close();
} catch (Exception e) {
Assert.fail("don't expect any exception, but got", e);
}
});
assertThatThrownBy(() -> snapshot.write(out)).isInstanceOf(IOException.class);
}
Aggregations