Search in sources :

Example 1 with SnapshotResponse

use of io.etcd.jetcd.api.SnapshotResponse in project jetcd by etcd-io.

the class MaintenanceUnitTest method setUp.

@BeforeEach
public void setUp() throws IOException, URISyntaxException {
    observerQueue = new LinkedBlockingQueue<>();
    executor = Executors.newFixedThreadPool(2);
    serviceRegistry = new MutableHandlerRegistry();
    serviceRegistry.addService(new MaintenanceImplBase() {

        @Override
        public void snapshot(SnapshotRequest request, StreamObserver<SnapshotResponse> observer) {
            try {
                observerQueue.put(observer);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    fakeServer = NettyServerBuilder.forPort(TestUtil.findNextAvailablePort()).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    client = Client.builder().endpoints(new URI("http://127.0.0.1:" + fakeServer.getPort())).build();
    maintenance = client.getMaintenanceClient();
}
Also used : MaintenanceImplBase(io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase) SnapshotResponse(io.etcd.jetcd.api.SnapshotResponse) SnapshotRequest(io.etcd.jetcd.api.SnapshotRequest) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with SnapshotResponse

use of io.etcd.jetcd.api.SnapshotResponse in project jetcd by coreos.

the class MaintenanceUnitTest method testWrite.

@Test
public void testWrite() throws Exception {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteString blob = ByteString.copyFromUtf8("blob");
    final CompletableFuture<Long> answer = maintenance.snapshot(out);
    StreamObserver<SnapshotResponse> observer = observerQueue.take();
    observer.onNext(SnapshotResponse.newBuilder().setBlob(blob).setRemainingBytes(0).build());
    observer.onCompleted();
    answer.get();
    assertThat(out.toByteArray()).isEqualTo(blob.toByteArray());
}
Also used : SnapshotResponse(io.etcd.jetcd.api.SnapshotResponse) ByteString(com.google.protobuf.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 3 with SnapshotResponse

use of io.etcd.jetcd.api.SnapshotResponse in project jetcd by coreos.

the class MaintenanceUnitTest method setUp.

@BeforeEach
public void setUp() throws IOException, URISyntaxException {
    observerQueue = new LinkedBlockingQueue<>();
    executor = Executors.newFixedThreadPool(2);
    serviceRegistry = new MutableHandlerRegistry();
    serviceRegistry.addService(new MaintenanceImplBase() {

        @Override
        public void snapshot(SnapshotRequest request, StreamObserver<SnapshotResponse> observer) {
            try {
                observerQueue.put(observer);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        }
    });
    fakeServer = NettyServerBuilder.forPort(TestUtil.findNextAvailablePort()).fallbackHandlerRegistry(serviceRegistry).directExecutor().build().start();
    client = Client.builder().endpoints(new URI("http://127.0.0.1:" + fakeServer.getPort())).build();
    maintenance = client.getMaintenanceClient();
}
Also used : MaintenanceImplBase(io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase) SnapshotResponse(io.etcd.jetcd.api.SnapshotResponse) SnapshotRequest(io.etcd.jetcd.api.SnapshotRequest) MutableHandlerRegistry(io.grpc.util.MutableHandlerRegistry) URI(java.net.URI) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with SnapshotResponse

use of io.etcd.jetcd.api.SnapshotResponse in project jetcd by etcd-io.

the class MaintenanceUnitTest method testWrite.

@Test
public void testWrite() throws Exception {
    final ByteArrayOutputStream out = new ByteArrayOutputStream();
    final ByteString blob = ByteString.copyFromUtf8("blob");
    final CompletableFuture<Long> answer = maintenance.snapshot(out);
    StreamObserver<SnapshotResponse> observer = observerQueue.take();
    observer.onNext(SnapshotResponse.newBuilder().setBlob(blob).setRemainingBytes(0).build());
    observer.onCompleted();
    answer.get();
    assertThat(out.toByteArray()).isEqualTo(blob.toByteArray());
}
Also used : SnapshotResponse(io.etcd.jetcd.api.SnapshotResponse) ByteString(com.google.protobuf.ByteString) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

SnapshotResponse (io.etcd.jetcd.api.SnapshotResponse)4 ByteString (com.google.protobuf.ByteString)2 MaintenanceImplBase (io.etcd.jetcd.api.MaintenanceGrpc.MaintenanceImplBase)2 SnapshotRequest (io.etcd.jetcd.api.SnapshotRequest)2 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 URI (java.net.URI)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 Test (org.junit.jupiter.api.Test)2