Search in sources :

Example 6 with Snapshot

use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.

the class MaintenanceUnitTest method testWriteAfterClosed.

@Test(timeOut = 1000)
public void testWriteAfterClosed() throws IOException {
    Snapshot snapshot = maintenanceCli.snapshot();
    snapshot.close();
    OutputStream out = new ByteArrayOutputStream();
    assertThatThrownBy(() -> snapshot.write(out)).isInstanceOf(IOException.class).hasMessageContaining("Snapshot has closed");
}
Also used : Snapshot(com.coreos.jetcd.Maintenance.Snapshot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Example 7 with Snapshot

use of com.coreos.jetcd.Maintenance.Snapshot in project jetcd by coreos.

the class MaintenanceUnitTest method testInterruptWrite.

@Test(timeOut = 1000)
public void testInterruptWrite() throws ExecutionException, InterruptedException {
    Snapshot snapshot = maintenanceCli.snapshot();
    OutputStream out = new ByteArrayOutputStream();
    Future<?> done = executor.submit(() -> assertThatThrownBy(() -> snapshot.write(out)).isInstanceOf(IOException.class).hasMessageContaining("write is interrupted"));
    Thread.sleep(50);
    executor.shutdownNow();
    done.get();
}
Also used : Snapshot(com.coreos.jetcd.Maintenance.Snapshot) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest) AfterTest(org.testng.annotations.AfterTest)

Aggregations

Snapshot (com.coreos.jetcd.Maintenance.Snapshot)7 Test (org.testng.annotations.Test)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 AfterTest (org.testng.annotations.AfterTest)6 BeforeTest (org.testng.annotations.BeforeTest)6 IOException (java.io.IOException)5 OutputStream (java.io.OutputStream)5 AuthFailedException (com.coreos.jetcd.exception.AuthFailedException)2 ConnectException (com.coreos.jetcd.exception.ConnectException)2 ByteString (com.google.protobuf.ByteString)2 ExecutionException (java.util.concurrent.ExecutionException)2 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1