use of com.github.ambry.network.NetworkClient 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.NetworkClient 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