use of com.github.ambry.network.Port in project ambry by linkedin.
the class Http2NetworkClientTest method warmUpConnections.
@Test
public void warmUpConnections() throws Exception {
int connectionPerPort = 4;
SSLFactory sslFactory = new NettySslHttp2Factory(clientSSLConfig);
Properties properties = new Properties();
properties.setProperty(Http2ClientConfig.HTTP2_MIN_CONNECTION_PER_PORT, Integer.toString(connectionPerPort));
Http2ClientConfig http2ClientConfig = new Http2ClientConfig(new VerifiableProperties(properties));
Http2NetworkClient networkClient = new Http2NetworkClient(new Http2ClientMetrics(new MetricRegistry()), http2ClientConfig, sslFactory, eventLoopGroup);
MockClusterMap clusterMap = http2Cluster.getClusterMap();
assertEquals("Connection count is not expected", 0, networkClient.warmUpConnections(clusterMap.getDataNodeIds(), 0, 1000, new ArrayList<>()));
assertEquals("Connection count is not expected", clusterMap.getDataNodeIds().size() * connectionPerPort / 2, networkClient.warmUpConnections(clusterMap.getDataNodeIds(), 50, 1000, new ArrayList<>()));
assertEquals("Connection count is not expected", clusterMap.getDataNodeIds().size() * connectionPerPort, networkClient.warmUpConnections(clusterMap.getDataNodeIds(), 100, 1000, new ArrayList<>()));
// All connection should be failed. Connection refused exceptions will be in test log.
List<Port> ports = new ArrayList<>();
ports.add(new Port(79, PortType.HTTP2));
ports.add(new Port(78, PortType.PLAINTEXT));
assertEquals("Connection count is not expected", 0, networkClient.warmUpConnections(Collections.singletonList(new MockDataNodeId(ports, null, "DC1")), 100, 1000, new ArrayList<>()));
}
use of com.github.ambry.network.Port 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());
}
use of com.github.ambry.network.Port in project ambry by linkedin.
the class ServerPlaintextTokenTest method endToEndReplicationWithMultiNodeSinglePartitionTest.
@Test
public void endToEndReplicationWithMultiNodeSinglePartitionTest() {
DataNodeId dataNodeId = plaintextCluster.getClusterMap().getDataNodeIds().get(0);
ArrayList<String> dataCenterList = Utils.splitString("DC1,DC2,DC3", ",");
List<DataNodeId> dataNodes = plaintextCluster.getOneDataNodeFromEachDatacenter(dataCenterList);
ServerTestUtil.endToEndReplicationWithMultiNodeSinglePartitionTest("DC1", dataNodeId.getPort(), new Port(dataNodes.get(0).getPort(), PortType.PLAINTEXT), new Port(dataNodes.get(1).getPort(), PortType.PLAINTEXT), new Port(dataNodes.get(2).getPort(), PortType.PLAINTEXT), plaintextCluster, null, null, notificationSystem, routerProps, testEncryption);
}
use of com.github.ambry.network.Port in project ambry by linkedin.
the class ServerSSLTokenTest method endToEndSSLReplicationWithMultiNodeSinglePartitionTest.
@Test
public void endToEndSSLReplicationWithMultiNodeSinglePartitionTest() {
DataNodeId dataNodeId = sslCluster.getClusterMap().getDataNodeIds().get(0);
ArrayList<String> dataCenterList = new ArrayList<String>(Arrays.asList("DC1", "DC2", "DC3"));
List<DataNodeId> dataNodes = sslCluster.getOneDataNodeFromEachDatacenter(dataCenterList);
ServerTestUtil.endToEndReplicationWithMultiNodeSinglePartitionTest("DC1", dataNodeId.getPort(), new Port(dataNodes.get(0).getSSLPort(), PortType.SSL), new Port(dataNodes.get(1).getSSLPort(), PortType.SSL), new Port(dataNodes.get(2).getSSLPort(), PortType.SSL), sslCluster, clientSSLConfig, clientSSLSocketFactory, notificationSystem, routerProps, testEncryption);
}
use of com.github.ambry.network.Port in project ambry by linkedin.
the class OperationTrackerTest method useReplicaNotSucceededSendTest.
/**
* crossColoEnabled = true, successTarget = 1, parallelism = 2.
* Only 4 local replicas
*
* 1. Get 1st local replica to send request (and sent);
* 2. Get 2nd local replica to send request (and failed to send);
* 3. Get 3rd local replica to send request (and sent);
* 4. Receive 2 failed responses from the 1st and 3rd replicas;
* 5. Get again 2nd local replica to send request (and sent);
* 6. Get 4th local replica to send request (and failed to send);
* 7. Receive 1 failed responses from the 2nd replicas;
* 8. Get again 4th local replica to send request (and sent);
* 9. Receive 1 successful response from the 4th replica;
* 10. Operation succeeds.
*/
@Test
public void useReplicaNotSucceededSendTest() {
int replicaCount = 4;
List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
List<String> mountPaths = Collections.singletonList("mockMountPath");
datanodes = Collections.singletonList(new MockDataNodeId(portList, mountPaths, "dc-0"));
mockPartition = new MockPartitionId();
populateReplicaList(replicaCount, ReplicaState.STANDBY);
localDcName = datanodes.get(0).getDatacenterName();
mockClusterMap = new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
OperationTracker ot = getOperationTracker(true, 1, 2, RouterOperation.GetBlobOperation, true);
sendRequests(ot, 2, true);
ot.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.FAILURE);
ot.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.FAILURE);
assertFalse("Operation should not be done", ot.isDone());
sendRequests(ot, 1, true);
ot.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.FAILURE);
assertFalse("Operation should not be done", ot.isDone());
sendRequests(ot, 1, false);
ot.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.SUCCESS);
assertTrue("Operation should have succeeded", ot.hasSucceeded());
assertTrue("Operation should be done", ot.isDone());
}
Aggregations