use of org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest in project bookkeeper by apache.
the class StorageContainerImplTest method testCreateStream.
@Test
public void testCreateStream() throws Exception {
mockStorageContainer(SCID);
CreateStreamResponse expectedResp = CreateStreamResponse.getDefaultInstance();
when(rrStore.createStream(any(CreateStreamRequest.class))).thenReturn(FutureUtils.value(expectedResp));
CreateStreamRequest expectedReq = CreateStreamRequest.getDefaultInstance();
assertSame(expectedResp, FutureUtils.result(rrStore.createStream(expectedReq)));
verify(rrStore, times(1)).createStream(same(expectedReq));
}
use of org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateStreamFailure.
@Test
public void testCreateStreamFailure() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.INTERNAL_SERVER_ERROR).build();
CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
when(rangeService.createStream(createReq)).thenReturn(FutureUtils.exception(CAUSE));
AtomicReference<CreateStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateStreamResponse> streamObserver = new StreamObserver<CreateStreamResponse>() {
@Override
public void onNext(CreateStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createStream(CreateStreamRequest.newBuilder().setColName(nsName).setName(streamName).setStreamConf(DEFAULT_STREAM_CONF).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertEquals(createResp, resultHolder.get());
verify(rangeService, times(1)).createStream(createReq);
}
use of org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest in project bookkeeper by apache.
the class TestGrpcRootRangeService method testCreateStreamSuccess.
//
// Test Stream API
//
@Test
public void testCreateStreamSuccess() throws Exception {
RangeStoreImpl rangeService = mock(RangeStoreImpl.class);
GrpcRootRangeService grpcService = new GrpcRootRangeService(rangeService);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.SUCCESS).setStreamProps(streamProps).build();
CreateStreamRequest createReq = createCreateStreamRequest(nsName, streamName, DEFAULT_STREAM_CONF);
when(rangeService.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
AtomicReference<CreateStreamResponse> resultHolder = new AtomicReference<>();
AtomicReference<Throwable> exceptionHolder = new AtomicReference<>();
CountDownLatch latch = new CountDownLatch(1);
StreamObserver<CreateStreamResponse> streamObserver = new StreamObserver<CreateStreamResponse>() {
@Override
public void onNext(CreateStreamResponse resp) {
resultHolder.set(resp);
}
@Override
public void onError(Throwable t) {
exceptionHolder.set(t);
latch.countDown();
}
@Override
public void onCompleted() {
latch.countDown();
}
};
grpcService.createStream(CreateStreamRequest.newBuilder().setColName(nsName).setName(streamName).setStreamConf(DEFAULT_STREAM_CONF).build(), streamObserver);
latch.await();
assertNull(exceptionHolder.get());
assertNotNull(resultHolder.get());
assertTrue(createResp == resultHolder.get());
verify(rangeService, times(1)).createStream(createReq);
}
use of org.apache.bookkeeper.stream.proto.storage.CreateStreamRequest in project bookkeeper by apache.
the class TestRangeStoreImpl method testCreateStreamMockRootStorageContainerStore.
@Test
public void testCreateStreamMockRootStorageContainerStore() throws Exception {
String colName = "test-create-namespace-mock-root-storage-container-store";
String streamName = colName;
StorageContainer scStore = mock(StorageContainer.class);
when(scStore.stop()).thenReturn(FutureUtils.value(null));
rangeStore.getRegistry().setStorageContainer(ROOT_STORAGE_CONTAINER_ID, scStore);
CreateStreamResponse createResp = CreateStreamResponse.newBuilder().setCode(StatusCode.STREAM_EXISTS).build();
CreateStreamRequest createReq = createCreateStreamRequest(colName, streamName, DEFAULT_STREAM_CONF);
when(scStore.createStream(createReq)).thenReturn(CompletableFuture.completedFuture(createResp));
CompletableFuture<CreateStreamResponse> createRespFuture = rangeStore.createStream(createReq);
verify(scStore, times(1)).createStream(createReq);
assertTrue(createResp == createRespFuture.get());
}
Aggregations