Search in sources :

Example 1 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceFailureOnStaleGroupInfo.

@Test
public void testGetRootRangeServiceFailureOnStaleGroupInfo() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses3 = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses3);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // 
    // Complete the first response
    // 
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp1 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    locateResponses1.complete(Lists.newArrayList(oneResp1));
    // get the service
    StorageServerChannel rsChannel = rsChannelFuture.get();
    assertTrue(rsChannel == mockChannel);
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertEquals(mockChannel, channelManager.getChannel(endpoint));
    // 
    // Reset and complete the second response
    // 
    scClient.resetStorageServerChannelFuture();
    rsChannelFuture = scClient.getStorageContainerChannelFuture();
    OneStorageContainerEndpointResponse oneResp2 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(999L).setRwEndpoint(endpoint2).addRoEndpoint(endpoint2).build()).build();
    locateResponses2.complete(Lists.newArrayList(oneResp2));
    ensureCallbackExecuted();
    // verify storage container info : group info will not be updated
    scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // the future will not be completed
    assertFalse(rsChannelFuture.isDone());
    // 
    // complete the third response
    // 
    scClient.resetStorageServerChannelFuture();
    rsChannelFuture = scClient.getStorageContainerChannelFuture();
    OneStorageContainerEndpointResponse oneResp3 = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1001L).setRwEndpoint(endpoint3).addRoEndpoint(endpoint3).build()).build();
    locateResponses3.complete(Lists.newArrayList(oneResp3));
    ensureCallbackExecuted();
    StorageServerChannel rsChannel3 = rsChannelFuture.get();
    assertTrue(rsChannel3 == mockChannel3);
    // verify storage container info : group info will not be updated
    scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1001L, scInfo.getRevision());
    assertEquals(endpoint3, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint3, endpoint3), scInfo.getReadEndpoints());
    verify(locationClient, times(3)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.Test)

Example 2 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceSuccess.

@Test
public void testGetRootRangeServiceSuccess() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    locateResponses.complete(Lists.newArrayList(oneResp));
    // get the service
    StorageServerChannel rsChannel = rsChannelFuture.get();
    assertTrue(rsChannel == mockChannel);
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertEquals(mockChannel, channelManager.getChannel(endpoint));
    verify(locationClient, times(1)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) Test(org.junit.Test)

Example 3 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class TestStorageContainerChannel method testGetRootRangeServiceExceptionally.

@Test
public void testGetRootRangeServiceExceptionally() throws Exception {
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses1 = FutureUtils.createFuture();
    CompletableFuture<List<OneStorageContainerEndpointResponse>> locateResponses2 = FutureUtils.createFuture();
    when(locationClient.locateStorageContainers(anyList())).thenReturn(locateResponses1).thenReturn(locateResponses2);
    // the future is not set before #getRootRangeService
    assertNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    // call #getRootRangeService
    CompletableFuture<StorageServerChannel> rsChannelFuture = scClient.getStorageContainerChannelFuture();
    // the future is set and the locationClient#locateStorageContainers is called
    assertNotNull(scClient.getStorageServerChannelFuture());
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // if the request is outstanding, a second call will not call locationClient#locateStorageContainers
    CompletableFuture<StorageServerChannel> rsChannelFuture1 = scClient.getStorageContainerChannelFuture();
    assertTrue(rsChannelFuture == rsChannelFuture1);
    assertNull(scClient.getStorageContainerInfo());
    verify(locationClient, times(1)).locateStorageContainers(anyList());
    // prepare the result and complete the request
    OneStorageContainerEndpointResponse oneResp = OneStorageContainerEndpointResponse.newBuilder().setStatusCode(StatusCode.SUCCESS).setEndpoint(StorageContainerEndpoint.newBuilder().setStorageContainerId(ROOT_STORAGE_CONTAINER_ID).setRevision(1000L).setRwEndpoint(endpoint).addRoEndpoint(endpoint).build()).build();
    // complete exceptionally
    locateResponses1.completeExceptionally(new ClientException("test-exception"));
    ensureCallbackExecuted();
    // verify channel
    assertNull(channelManager.getChannel(endpoint));
    // verify storage container info
    assertNull(scClient.getStorageContainerInfo());
    // complete with right responses
    locateResponses2.complete(Lists.newArrayList(oneResp));
    // get the service
    StorageServerChannel rsChannel = rsChannelFuture.get();
    assertTrue(rsChannel == mockChannel);
    // verify storage container info
    StorageContainerInfo scInfo = scClient.getStorageContainerInfo();
    assertEquals(ROOT_STORAGE_CONTAINER_ID, scInfo.getGroupId());
    assertEquals(1000L, scInfo.getRevision());
    assertEquals(endpoint, scInfo.getWriteEndpoint());
    assertEquals(Lists.newArrayList(endpoint, endpoint), scInfo.getReadEndpoints());
    // verify channel
    assertEquals(mockChannel, channelManager.getChannel(endpoint));
    verify(locationClient, times(2)).locateStorageContainers(anyList());
}
Also used : OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) List(java.util.List) ClientException(org.apache.bookkeeper.clients.exceptions.ClientException) Test(org.junit.Test)

Example 4 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class RootRangeClientImplTestBase method testRequestFailure.

@Test
public void testRequestFailure() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    RootRangeServiceImplBase rootRangeService = createRootRangeServiceForRequestFailure();
    serviceRegistry.addService(rootRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    verifyRequestFailure(rootRangeClient);
}
Also used : StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) RootRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase) Test(org.junit.Test)

Example 5 with StorageServerChannel

use of org.apache.bookkeeper.clients.impl.channel.StorageServerChannel in project bookkeeper by apache.

the class RootRangeClientImplTestBase method testRequestSuccess.

@Test
public void testRequestSuccess() throws Exception {
    CompletableFuture<StorageServerChannel> serviceFuture = FutureUtils.createFuture();
    rootRangeClient.getStorageContainerClient().setStorageServerChannelFuture(serviceFuture);
    RootRangeServiceImplBase rootRangeService = createRootRangeServiceForSuccess();
    serviceRegistry.addService(rootRangeService.bindService());
    StorageServerChannel rsChannel = new StorageServerChannel(InProcessChannelBuilder.forName(serverName).directExecutor().build(), Optional.empty());
    serviceFuture.complete(rsChannel);
    verifySuccess(rootRangeClient);
}
Also used : StorageServerChannel(org.apache.bookkeeper.clients.impl.channel.StorageServerChannel) RootRangeServiceImplBase(org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase) Test(org.junit.Test)

Aggregations

StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)14 Test (org.junit.Test)11 OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)7 List (java.util.List)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 StreamObserver (io.grpc.stub.StreamObserver)4 RootRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.RootRangeServiceGrpc.RootRangeServiceImplBase)3 StorageContainerRequest (org.apache.bookkeeper.stream.proto.storage.StorageContainerRequest)3 ExecutionException (java.util.concurrent.ExecutionException)2 HashStreamRanges (org.apache.bookkeeper.clients.impl.internal.api.HashStreamRanges)2 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)2 MetaRangeServiceImplBase (org.apache.bookkeeper.stream.proto.storage.MetaRangeServiceGrpc.MetaRangeServiceImplBase)2 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)2 StorageContainerResponse (org.apache.bookkeeper.stream.proto.storage.StorageContainerResponse)2 Server (io.grpc.Server)1 StatusRuntimeException (io.grpc.StatusRuntimeException)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1