Search in sources :

Example 1 with NetworkClientFactory

use of com.github.ambry.network.NetworkClientFactory in project ambry by linkedin.

the class NonBlockingRouterTest method testResponseWithNullRequestInfo.

/**
 * Test the case where request is timed out in the pending queue and network client returns response with null requestInfo
 * to mark node down via response handler.
 * @throws Exception
 */
@Test
public void testResponseWithNullRequestInfo() throws Exception {
    NonBlockingRouter testRouter = null;
    try {
        Properties props = getNonBlockingRouterProperties("DC1");
        VerifiableProperties verifiableProperties = new VerifiableProperties((props));
        RouterConfig routerConfig = new RouterConfig(verifiableProperties);
        routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
        NetworkClient mockNetworkClient = Mockito.mock(NetworkClient.class);
        Mockito.when(mockNetworkClient.warmUpConnections(anyList(), anyInt(), anyLong(), anyList())).thenReturn(1);
        doNothing().when(mockNetworkClient).close();
        List<ResponseInfo> responseInfoList = new ArrayList<>();
        MockDataNodeId testDataNode = (MockDataNodeId) mockClusterMap.getDataNodeIds().get(0);
        responseInfoList.add(new ResponseInfo(null, NetworkClientErrorCode.NetworkError, null, testDataNode));
        // By default, there are 1 operation controller and 1 background deleter thread. We set CountDownLatch to 3 so that
        // at least one thread has completed calling onResponse() and test node's state has been updated in ResponseHandler
        CountDownLatch invocationLatch = new CountDownLatch(3);
        doAnswer(invocation -> {
            invocationLatch.countDown();
            return responseInfoList;
        }).when(mockNetworkClient).sendAndPoll(anyList(), anySet(), anyInt());
        NetworkClientFactory networkClientFactory = Mockito.mock(NetworkClientFactory.class);
        Mockito.when(networkClientFactory.getNetworkClient()).thenReturn(mockNetworkClient);
        testRouter = new NonBlockingRouter(routerConfig, routerMetrics, networkClientFactory, new LoggingNotificationSystem(), mockClusterMap, kms, cryptoService, cryptoJobHandler, accountService, mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
        assertTrue("Invocation latch didn't count to 0 within 10 seconds", invocationLatch.await(10, TimeUnit.SECONDS));
        // verify the test node is considered timeout
        assertTrue("The node should be considered timeout", testDataNode.isTimedOut());
    } finally {
        if (testRouter != null) {
            testRouter.close();
        }
    }
}
Also used : ResponseInfo(com.github.ambry.network.ResponseInfo) VerifiableProperties(com.github.ambry.config.VerifiableProperties) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) ArrayList(java.util.ArrayList) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) CountDownLatch(java.util.concurrent.CountDownLatch) RouterConfig(com.github.ambry.config.RouterConfig) SocketNetworkClient(com.github.ambry.network.SocketNetworkClient) NetworkClient(com.github.ambry.network.NetworkClient) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Test(org.junit.Test)

Example 2 with NetworkClientFactory

use of com.github.ambry.network.NetworkClientFactory in project ambry by linkedin.

the class CloudRouterFactory method getCompositeNetworkClientFactory.

/**
 * @param requestHandlerPool the pool to connect to {@link LocalNetworkClientFactory}.
 * @return a {@link CompositeNetworkClientFactory} that can be used to talk to cloud managed services or ambry server
 *         nodes.
 */
private CompositeNetworkClientFactory getCompositeNetworkClientFactory(RequestHandlerPool requestHandlerPool) {
    NetworkClientFactory cloudNetworkClientFactory = new LocalNetworkClientFactory((LocalRequestResponseChannel) requestHandlerPool.getChannel(), networkConfig, networkMetrics, time);
    NetworkClientFactory diskNetworkClientFactory = null;
    if (routerConfig.routerEnableHttp2NetworkClient) {
        diskNetworkClientFactory = new Http2NetworkClientFactory(http2ClientMetrics, http2ClientConfig, sslFactory, time);
    } else {
        diskNetworkClientFactory = new SocketNetworkClientFactory(networkMetrics, networkConfig, sslFactory, routerConfig.routerScalingUnitMaxConnectionsPerPortPlainText, routerConfig.routerScalingUnitMaxConnectionsPerPortSsl, routerConfig.routerConnectionCheckoutTimeoutMs, time);
    }
    Map<ReplicaType, NetworkClientFactory> childFactories = new EnumMap<>(ReplicaType.class);
    childFactories.put(ReplicaType.CLOUD_BACKED, cloudNetworkClientFactory);
    childFactories.put(ReplicaType.DISK_BACKED, diskNetworkClientFactory);
    return new CompositeNetworkClientFactory(childFactories);
}
Also used : LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) SocketNetworkClientFactory(com.github.ambry.network.SocketNetworkClientFactory) ReplicaType(com.github.ambry.clustermap.ReplicaType) Http2NetworkClientFactory(com.github.ambry.network.http2.Http2NetworkClientFactory) LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) SocketNetworkClientFactory(com.github.ambry.network.SocketNetworkClientFactory) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) Http2NetworkClientFactory(com.github.ambry.network.http2.Http2NetworkClientFactory) EnumMap(java.util.EnumMap)

Example 3 with NetworkClientFactory

use of com.github.ambry.network.NetworkClientFactory in project ambry by linkedin.

the class CloudRouterTest method setRouter.

/**
 * Initialize and set the router with the given {@link Properties} and {@link MockServerLayout}
 * @param props the {@link Properties}
 * @param notificationSystem the {@link NotificationSystem} to use.
 */
@Override
protected void setRouter(Properties props, MockServerLayout mockServerLayout, NotificationSystem notificationSystem) throws Exception {
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    RouterConfig routerConfig = new RouterConfig(verifiableProperties);
    routerMetrics = new NonBlockingRouterMetrics(mockClusterMap, routerConfig);
    CloudConfig cloudConfig = new CloudConfig(verifiableProperties);
    CloudDestinationFactory cloudDestinationFactory = Utils.getObj(cloudConfig.cloudDestinationFactoryClass, verifiableProperties, mockClusterMap.getMetricRegistry(), mockClusterMap);
    CloudDestination cloudDestination = cloudDestinationFactory.getCloudDestination();
    AccountService accountService = new InMemAccountService(false, true);
    CloudRouterFactory cloudRouterFactory = new CloudRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null, accountService);
    RequestHandlerPool requestHandlerPool = cloudRouterFactory.getRequestHandlerPool(verifiableProperties, mockClusterMap, cloudDestination, cloudConfig);
    Map<ReplicaType, NetworkClientFactory> childFactories = new EnumMap<>(ReplicaType.class);
    childFactories.put(ReplicaType.CLOUD_BACKED, new LocalNetworkClientFactory((LocalRequestResponseChannel) requestHandlerPool.getChannel(), new NetworkConfig(verifiableProperties), new NetworkMetrics(routerMetrics.getMetricRegistry()), mockTime));
    childFactories.put(ReplicaType.DISK_BACKED, new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, mockServerLayout, mockTime));
    NetworkClientFactory networkClientFactory = new CompositeNetworkClientFactory(childFactories);
    router = new NonBlockingRouter(routerConfig, routerMetrics, networkClientFactory, notificationSystem, mockClusterMap, kms, cryptoService, cryptoJobHandler, accountService, mockTime, MockClusterMap.DEFAULT_PARTITION_CLASS);
    router.addResourceToClose(requestHandlerPool);
}
Also used : LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) LocalRequestResponseChannel(com.github.ambry.network.LocalRequestResponseChannel) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LocalNetworkClientFactory(com.github.ambry.network.LocalNetworkClientFactory) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) NetworkMetrics(com.github.ambry.network.NetworkMetrics) CloudDestination(com.github.ambry.cloud.CloudDestination) CloudConfig(com.github.ambry.config.CloudConfig) NetworkConfig(com.github.ambry.config.NetworkConfig) CloudDestinationFactory(com.github.ambry.cloud.CloudDestinationFactory) LatchBasedInMemoryCloudDestinationFactory(com.github.ambry.cloud.LatchBasedInMemoryCloudDestinationFactory) RouterConfig(com.github.ambry.config.RouterConfig) CompositeNetworkClientFactory(com.github.ambry.network.CompositeNetworkClientFactory) InMemAccountService(com.github.ambry.account.InMemAccountService) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ReplicaType(com.github.ambry.clustermap.ReplicaType) RequestHandlerPool(com.github.ambry.protocol.RequestHandlerPool) AccountService(com.github.ambry.account.AccountService) InMemAccountService(com.github.ambry.account.InMemAccountService) EnumMap(java.util.EnumMap)

Example 4 with NetworkClientFactory

use of com.github.ambry.network.NetworkClientFactory in project ambry by linkedin.

the class QuotaAwareOperationControllerTest method setupMocks.

@Before
public void setupMocks() throws Exception {
    NetworkClientFactory networkClientFactory = mock(NetworkClientFactory.class);
    NetworkClient networkClient = mock(NetworkClient.class);
    when(networkClientFactory.getNetworkClient()).thenReturn(networkClient);
    ClusterMap clusterMap = mock(ClusterMap.class);
    when(clusterMap.getLocalDatacenterId()).thenReturn((byte) 1);
    when(clusterMap.getDatacenterName((byte) 1)).thenReturn("test");
    when(clusterMap.getMetricRegistry()).thenReturn(new MetricRegistry());
    MockDataNodeId mockDataNodeId = new MockDataNodeId(Collections.singletonList(new Port(80, PortType.PLAINTEXT)), Collections.singletonList("/a/b"), "test");
    List<MockDataNodeId> dataNodeIds = new ArrayList<>();
    dataNodeIds.add(mockDataNodeId);
    doReturn(dataNodeIds).when(clusterMap).getDataNodeIds();
    when(networkClient.warmUpConnections(anyList(), anyByte(), anyLong(), anyList())).thenReturn(1);
    Properties properties = new Properties();
    properties.setProperty(RouterConfig.ROUTER_DATACENTER_NAME, "test");
    properties.setProperty(RouterConfig.ROUTER_HOSTNAME, "test");
    RouterConfig routerConfig = new RouterConfig(new VerifiableProperties(properties));
    NonBlockingRouterMetrics routerMetrics = new NonBlockingRouterMetrics(clusterMap, routerConfig);
    quotaAwareOperationController = new QuotaAwareOperationController(null, null, null, networkClientFactory, clusterMap, routerConfig, null, null, routerMetrics, null, null, null, null, nonBlockingRouter);
    // closing existing put manager before setting mock to clean up the threads.
    quotaAwareOperationController.putManager.close();
    FieldSetter.setField(quotaAwareOperationController, quotaAwareOperationController.getClass().getSuperclass().getDeclaredField("putManager"), putManager);
    FieldSetter.setField(quotaAwareOperationController, quotaAwareOperationController.getClass().getSuperclass().getDeclaredField("getManager"), getManager);
    FieldSetter.setField(quotaAwareOperationController, quotaAwareOperationController.getClass().getSuperclass().getDeclaredField("deleteManager"), deleteManager);
    FieldSetter.setField(quotaAwareOperationController, quotaAwareOperationController.getClass().getSuperclass().getDeclaredField("undeleteManager"), undeleteManager);
    FieldSetter.setField(quotaAwareOperationController, quotaAwareOperationController.getClass().getSuperclass().getDeclaredField("ttlUpdateManager"), ttlUpdateManager);
    doNothing().when(getManager).poll(requestsToSend, requestsToDrop);
    doNothing().when(deleteManager).poll(requestsToSend, requestsToDrop);
    doNothing().when(ttlUpdateManager).poll(requestsToSend, requestsToDrop);
    doNothing().when(nonBlockingRouter).initiateBackgroundDeletes(anyList());
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) VerifiableProperties(com.github.ambry.config.VerifiableProperties) NetworkClientFactory(com.github.ambry.network.NetworkClientFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Port(com.github.ambry.network.Port) ArrayList(java.util.ArrayList) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig) NetworkClient(com.github.ambry.network.NetworkClient) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Before(org.junit.Before)

Aggregations

NetworkClientFactory (com.github.ambry.network.NetworkClientFactory)4 RouterConfig (com.github.ambry.config.RouterConfig)3 VerifiableProperties (com.github.ambry.config.VerifiableProperties)3 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)2 ReplicaType (com.github.ambry.clustermap.ReplicaType)2 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)2 CompositeNetworkClientFactory (com.github.ambry.network.CompositeNetworkClientFactory)2 LocalNetworkClientFactory (com.github.ambry.network.LocalNetworkClientFactory)2 NetworkClient (com.github.ambry.network.NetworkClient)2 ArrayList (java.util.ArrayList)2 EnumMap (java.util.EnumMap)2 Properties (java.util.Properties)2 MetricRegistry (com.codahale.metrics.MetricRegistry)1 AccountService (com.github.ambry.account.AccountService)1 InMemAccountService (com.github.ambry.account.InMemAccountService)1 CloudDestination (com.github.ambry.cloud.CloudDestination)1 CloudDestinationFactory (com.github.ambry.cloud.CloudDestinationFactory)1 LatchBasedInMemoryCloudDestinationFactory (com.github.ambry.cloud.LatchBasedInMemoryCloudDestinationFactory)1 ClusterMap (com.github.ambry.clustermap.ClusterMap)1 CloudConfig (com.github.ambry.config.CloudConfig)1