Search in sources :

Example 1 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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 OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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 OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse 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 OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.

the class TestProtocolInternalUtils method testCreateStorageContainerEndpointResponse.

@Test
public void testCreateStorageContainerEndpointResponse() {
    List<StorageContainerEndpoint> endpoints = Lists.newArrayList(StorageContainerEndpoint.newBuilder().setStorageContainerId(1L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(2L).build(), StorageContainerEndpoint.newBuilder().setStorageContainerId(3L).build());
    GetStorageContainerEndpointResponse response = createGetStorageContainerEndpointResponse(endpoints);
    assertEquals(3, response.getResponsesCount());
    int i = 0;
    for (OneStorageContainerEndpointResponse oneResp : response.getResponsesList()) {
        assertEquals(StatusCode.SUCCESS, oneResp.getStatusCode());
        assertTrue(endpoints.get(i) == oneResp.getEndpoint());
        ++i;
    }
}
Also used : StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) ProtoUtils.createGetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.protocol.util.ProtoUtils.createGetStorageContainerEndpointResponse) GetStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) StorageContainerEndpoint(org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint) Test(org.junit.Test)

Example 5 with OneStorageContainerEndpointResponse

use of org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse in project bookkeeper by apache.

the class TestStorageServerClientManagerImpl method testGetLocationClient.

@SuppressWarnings("unchecked")
@Test
public void testGetLocationClient() throws Exception {
    LocationClient lc = serverManager.getLocationClient();
    assertNotNull(lc);
    assertEquals(lc, serverManager.getLocationClient());
    List<OneStorageContainerEndpointResponse> responses = FutureUtils.result(lc.locateStorageContainers(Lists.newArrayList(Revisioned.of(123L, 456L))));
    assertEquals(1, responses.size());
    assertEquals(StatusCode.SUCCESS, responses.get(0).getStatusCode());
    assertEquals(ENDPOINT, responses.get(0).getEndpoint().getRwEndpoint());
    assertEquals(0, responses.get(0).getEndpoint().getRoEndpointCount());
}
Also used : LocationClient(org.apache.bookkeeper.clients.impl.internal.api.LocationClient) OneStorageContainerEndpointResponse(org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse) Test(org.junit.Test)

Aggregations

OneStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.OneStorageContainerEndpointResponse)10 Test (org.junit.Test)8 StorageServerChannel (org.apache.bookkeeper.clients.impl.channel.StorageServerChannel)7 List (java.util.List)5 ArgumentMatchers.anyList (org.mockito.ArgumentMatchers.anyList)5 Endpoint (org.apache.bookkeeper.stream.proto.common.Endpoint)3 StorageContainerEndpoint (org.apache.bookkeeper.stream.proto.storage.StorageContainerEndpoint)3 ObjectClosedException (org.apache.bookkeeper.common.exceptions.ObjectClosedException)2 GetStorageContainerEndpointResponse (org.apache.bookkeeper.stream.proto.storage.GetStorageContainerEndpointResponse)2 Server (io.grpc.Server)1 InProcessChannelBuilder (io.grpc.inprocess.InProcessChannelBuilder)1 InProcessServerBuilder (io.grpc.inprocess.InProcessServerBuilder)1 StreamObserver (io.grpc.stub.StreamObserver)1 MutableHandlerRegistry (io.grpc.util.MutableHandlerRegistry)1 Optional (java.util.Optional)1 ExecutionException (java.util.concurrent.ExecutionException)1 StorageClientSettings (org.apache.bookkeeper.clients.config.StorageClientSettings)1 ClientException (org.apache.bookkeeper.clients.exceptions.ClientException)1 StorageContainerException (org.apache.bookkeeper.clients.exceptions.StorageContainerException)1 StorageServerClientManagerImpl (org.apache.bookkeeper.clients.impl.internal.StorageServerClientManagerImpl)1