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();
}
}
}
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);
}
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);
}
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());
}
Aggregations