Search in sources :

Example 46 with Port

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<>()));
}
Also used : SSLFactory(com.github.ambry.commons.SSLFactory) Http2ClientMetrics(com.github.ambry.network.http2.Http2ClientMetrics) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MetricRegistry(com.codahale.metrics.MetricRegistry) Port(com.github.ambry.network.Port) ArrayList(java.util.ArrayList) Http2ClientConfig(com.github.ambry.config.Http2ClientConfig) NettySslHttp2Factory(com.github.ambry.commons.NettySslHttp2Factory) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) Http2NetworkClient(com.github.ambry.network.http2.Http2NetworkClient) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 47 with Port

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

Example 48 with Port

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);
}
Also used : Port(com.github.ambry.network.Port) DataNodeId(com.github.ambry.clustermap.DataNodeId) Test(org.junit.Test)

Example 49 with Port

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);
}
Also used : Port(com.github.ambry.network.Port) ArrayList(java.util.ArrayList) DataNodeId(com.github.ambry.clustermap.DataNodeId) Test(org.junit.Test)

Example 50 with Port

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());
}
Also used : MockPartitionId(com.github.ambry.clustermap.MockPartitionId) Port(com.github.ambry.network.Port) MockDataNodeId(com.github.ambry.clustermap.MockDataNodeId) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Aggregations

Port (com.github.ambry.network.Port)64 Test (org.junit.Test)33 MockDataNodeId (com.github.ambry.clustermap.MockDataNodeId)29 ArrayList (java.util.ArrayList)28 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)27 MockPartitionId (com.github.ambry.clustermap.MockPartitionId)23 DataNodeId (com.github.ambry.clustermap.DataNodeId)22 ReplicaId (com.github.ambry.clustermap.ReplicaId)17 BlobId (com.github.ambry.commons.BlobId)15 VerifiableProperties (com.github.ambry.config.VerifiableProperties)15 BlobProperties (com.github.ambry.messageformat.BlobProperties)15 Properties (java.util.Properties)15 MetricRegistry (com.codahale.metrics.MetricRegistry)12 PartitionId (com.github.ambry.clustermap.PartitionId)12 ConnectedChannel (com.github.ambry.network.ConnectedChannel)12 PartitionRequestInfo (com.github.ambry.protocol.PartitionRequestInfo)10 MockReplicaId (com.github.ambry.clustermap.MockReplicaId)9 ClusterMapConfig (com.github.ambry.config.ClusterMapConfig)9 GetResponse (com.github.ambry.protocol.GetResponse)9 DataInputStream (java.io.DataInputStream)9