use of org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse 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.CreateStreamResponse 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());
}
use of org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method testCreateStreamExists.
@Test
public void testCreateStreamExists() throws Exception {
String nsName = name.getMethodName();
String streamName = name.getMethodName();
CreateNamespaceResponse createResp = createNamespaceAndVerify(nsName, 0L);
createStreamAndVerify(nsName, streamName, MIN_DATA_STREAM_ID);
verifyStreamExists(createResp.getColProps().getNamespaceId(), streamName, MIN_DATA_STREAM_ID);
verifyStreamId(MIN_DATA_STREAM_ID);
// create the namespace with same name will fail
CreateStreamResponse response2 = FutureUtils.result(rootRangeStore.createStream(createCreateStreamRequest(nsName, streamName, streamConf)));
// TODO: change it later
assertEquals(StatusCode.INTERNAL_SERVER_ERROR, response2.getCode());
verifyStreamId(MIN_DATA_STREAM_ID);
}
use of org.apache.bookkeeper.stream.proto.storage.CreateStreamResponse in project bookkeeper by apache.
the class TestRootRangeStoreImpl method testCreateStreamNamespaceNotFound.
@Test
public void testCreateStreamNamespaceNotFound() throws Exception {
String nsName = name.getMethodName();
String streamName = name.getMethodName();
CompletableFuture<CreateStreamResponse> createFuture = rootRangeStore.createStream(createCreateStreamRequest(nsName, streamName, streamConf));
CreateStreamResponse response = FutureUtils.result(createFuture);
assertEquals(StatusCode.NAMESPACE_NOT_FOUND, response.getCode());
}
Aggregations