use of com.github.ambry.clustermap.MockClusterMap in project ambry by linkedin.
the class RouterServerSSLTest method initializeTests.
@BeforeClass
public static void initializeTests() throws Exception {
File trustStoreFile = File.createTempFile("truststore", ".jks");
String sslEnabledDataCentersStr = "DC1,DC2,DC3";
Properties serverSSLProps = new Properties();
TestSSLUtils.addSSLProperties(serverSSLProps, sslEnabledDataCentersStr, SSLFactory.Mode.SERVER, trustStoreFile, "server");
TestSSLUtils.addHttp2Properties(serverSSLProps, SSLFactory.Mode.SERVER, true);
Properties routerProps = getRouterProperties("DC1");
TestSSLUtils.addSSLProperties(routerProps, sslEnabledDataCentersStr, SSLFactory.Mode.CLIENT, trustStoreFile, "router-client");
sslCluster = new MockCluster(serverSSLProps, false, SystemTime.getInstance());
MockNotificationSystem notificationSystem = new MockNotificationSystem(sslCluster.getClusterMap());
sslCluster.initializeServers(notificationSystem);
sslCluster.startServers();
MockClusterMap routerClusterMap = sslCluster.getClusterMap();
// MockClusterMap returns a new registry by default. This is to ensure that each node (server, router and so on,
// get a different registry. But at this point all server nodes have been initialized, and we want the router and
// its components, which are going to be created, to use the same registry.
routerClusterMap.createAndSetPermanentMetricRegistry();
testFramework = new RouterServerTestFramework(routerProps, routerClusterMap, notificationSystem);
routerMetricRegistry = routerClusterMap.getMetricRegistry();
}
use of com.github.ambry.clustermap.MockClusterMap in project ambry by linkedin.
the class UndeleteOperationTrackerTest method failureForInitialization.
/**
* Tests when there are not sufficient eligible hosts.
*/
@Test
public void failureForInitialization() {
assumeTrue(replicasStateEnabled);
List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
List<String> mountPaths = Collections.singletonList("mockMountPath");
datanodes = new ArrayList<>(Arrays.asList(new MockDataNodeId(portList, mountPaths, "dc-0"), new MockDataNodeId(portList, mountPaths, "dc-1"), new MockDataNodeId(portList, mountPaths, "dc-2"), new MockDataNodeId(portList, mountPaths, "dc-3")));
mockPartition = new MockPartitionId();
populateReplicaList(4, ReplicaState.STANDBY);
populateReplicaList(4, ReplicaState.INACTIVE);
populateReplicaList(4, ReplicaState.DROPPED);
localDcName = datanodes.get(0).getDatacenterName();
mockClusterMap = new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
try {
getOperationTracker(3);
fail("Should fail to create undelete operation tracker because of insufficient eligible hosts");
} catch (IllegalArgumentException e) {
}
}
use of com.github.ambry.clustermap.MockClusterMap in project ambry by linkedin.
the class UndeleteOperationTrackerTest method failureWithIneligibleNodesTest.
/**
* Tests when there are ineligible hosts.
*/
@Test
public void failureWithIneligibleNodesTest() {
assumeTrue(replicasStateEnabled);
List<Port> portList = Collections.singletonList(new Port(PORT, PortType.PLAINTEXT));
List<String> mountPaths = Collections.singletonList("mockMountPath");
datanodes = new ArrayList<>(Arrays.asList(new MockDataNodeId(portList, mountPaths, "dc-0"), new MockDataNodeId(portList, mountPaths, "dc-1"), new MockDataNodeId(portList, mountPaths, "dc-2"), new MockDataNodeId(portList, mountPaths, "dc-3")));
mockPartition = new MockPartitionId();
populateReplicaList(8, ReplicaState.STANDBY);
populateReplicaList(4, ReplicaState.INACTIVE);
localDcName = datanodes.get(0).getDatacenterName();
mockClusterMap = new MockClusterMap(false, datanodes, 1, Collections.singletonList(mockPartition), localDcName);
// Now any of the failure would fail the operation
UndeleteOperationTracker tracker = getOperationTracker(2);
sendRequests(tracker, 2);
tracker.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.SUCCESS);
assertFalse("Operation should not have failed", tracker.hasFailed());
assertFalse("Operation should not have succeeded", tracker.hasSucceeded());
assertFalse("Operation should not be done", tracker.isDone());
tracker.onResponse(inflightReplicas.poll(), TrackedRequestFinalState.FAILURE);
assertTrue("Operation should have failed", tracker.hasFailed());
assertFalse("Operation should not have succeeded", tracker.hasSucceeded());
assertTrue("Operation should be done", tracker.isDone());
}
use of com.github.ambry.clustermap.MockClusterMap in project ambry by linkedin.
the class CloudAndStoreReplicationTest method setup.
/**
* Create a cluster with one vcr node and two ambry server data nodes.
* @throws Exception on {@link Exception}
*/
@Before
public void setup() throws Exception {
String vcrMountPath = ClusterMapSnapshotConstants.CLOUD_REPLICA_MOUNT + "/1";
recoveryProperties = new Properties();
recoveryProperties.setProperty("replication.metadata.request.version", "2");
recoveryProperties.setProperty("replication.enabled.with.vcr.cluster", "true");
recoveryProperties.setProperty("clustermap.vcr.datacenter.name", cloudDc);
if (!vcrRecoveryPartitionConfig.isEmpty()) {
recoveryProperties.setProperty("vcr.recovery.partitions", vcrRecoveryPartitionConfig);
}
TestSSLUtils.addHttp2Properties(recoveryProperties, SSLFactory.Mode.SERVER, true);
// create vcr node
List<Port> vcrPortList = Arrays.asList(new Port(12310, PortType.PLAINTEXT), new Port(12410, PortType.SSL));
MockDataNodeId vcrNode = new MockDataNodeId("localhost", vcrPortList, Collections.singletonList(vcrMountPath), cloudDc);
// create ambry server recovery cluster
MockClusterMap serverClusterMap = new MockClusterMap(false, true, 2, 1, 1, true, false, null);
recoveryCluster = new MockCluster(serverClusterMap, Collections.singletonList(vcrNode), recoveryProperties);
partitionId = recoveryCluster.getClusterMap().getWritablePartitionIds(null).get(0);
allRecoveryNodes = serverClusterMap.getDataNodes();
// record ambry server node which will get partition leadership notification.
partitionLeaderRecoveryNode = allRecoveryNodes.get(0);
MockClusterAgentsFactory leaderMockClusterAgentsFactory = new MockClusterAgentsFactory(serverClusterMap, serverClusterMap.getAllPartitionIds(null).stream().map(PartitionId::toPathString).collect(Collectors.toList()));
// Start Helix Controller and ZK Server.
if (!zkInfo.isZkServerStarted()) {
zkInfo.startZkServer();
}
helixControllerManager = VcrTestUtil.populateZkInfoAndStartController(zkConnectString, vcrClusterName, recoveryCluster.getClusterMap());
Properties vcrProperties = VcrTestUtil.createVcrProperties(vcrNode.getDatacenterName(), vcrClusterName, zkConnectString, 12310, 12410, 12510, null);
vcrProperties.putAll(recoveryProperties);
MockNotificationSystem notificationSystem = new MockNotificationSystem(recoveryCluster.getClusterMap());
// Create blobs and data for upload to vcr.
int blobCount = 10;
cloudBlobIds = ServerTestUtil.createBlobIds(blobCount, recoveryCluster.getClusterMap(), accountId, containerId, partitionId);
serverBlobIds = ServerTestUtil.createBlobIds(blobCount, recoveryCluster.getClusterMap(), accountId, containerId, partitionId);
// Create cloud destination and start vcr server.
latchBasedInMemoryCloudDestination = new LatchBasedInMemoryCloudDestination(cloudBlobIds, recoveryCluster.getClusterMap());
CloudDestinationFactory cloudDestinationFactory = new LatchBasedInMemoryCloudDestinationFactory(latchBasedInMemoryCloudDestination);
vcrServer = VcrTestUtil.createVcrServer(new VerifiableProperties(vcrProperties), recoveryCluster.getClusterAgentsFactory(), notificationSystem, cloudDestinationFactory);
vcrServer.startup();
// initialize and start ambry servers
for (MockDataNodeId serverNode : allRecoveryNodes) {
AmbryServer server = recoveryCluster.initializeServer(serverNode, recoveryProperties, false, notificationSystem, SystemTime.getInstance(), serverNode.equals(partitionLeaderRecoveryNode) ? leaderMockClusterAgentsFactory : null);
recoveryCluster.addServer(server);
}
recoveryCluster.startServers();
}
use of com.github.ambry.clustermap.MockClusterMap in project ambry by linkedin.
the class RouterFactoryTest method testRouterFactory.
/**
* Tests the instantiation of a {@link Router} implementation through its {@link RouterFactory} implementation
* @throws IOException
*/
@Test
public void testRouterFactory() throws Exception {
VerifiableProperties verifiableProperties = getVerifiableProperties();
InMemAccountService accountService = new InMemAccountService(false, true);
List<FactoryAndRouter> factoryAndRouters = new ArrayList<FactoryAndRouter>();
factoryAndRouters.add(new FactoryAndRouter("com.github.ambry.router.NonBlockingRouterFactory", "com.github.ambry.router.NonBlockingRouter"));
factoryAndRouters.add(new FactoryAndRouter("com.github.ambry.router.CloudRouterFactory", "com.github.ambry.router.NonBlockingRouter"));
for (FactoryAndRouter factoryAndRouter : factoryAndRouters) {
RouterFactory routerFactory = Utils.getObj(factoryAndRouter.factoryStr, verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), null, accountService);
Router router = routerFactory.getRouter();
Assert.assertEquals("Did not receive expected Router instance", factoryAndRouter.routerStr, router.getClass().getCanonicalName());
router.close();
}
}
Aggregations