use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class ReplicationTest method replicationPauseTest.
/**
* Tests pausing replication for all and individual partitions.
* @throws Exception
*/
@Test
public void replicationPauseTest() throws Exception {
MockClusterMap clusterMap = new MockClusterMap();
Host localHost = new Host(clusterMap.getDataNodeIds().get(0), clusterMap);
Host remoteHost = new Host(clusterMap.getDataNodeIds().get(1), clusterMap);
List<PartitionId> partitionIds = clusterMap.getAllPartitionIds();
for (PartitionId partitionId : partitionIds) {
// add 10 messages to the remote host only
addPutMessagesToReplicasOfPartition(partitionId, Collections.singletonList(remoteHost), 10);
}
Properties properties = new Properties();
properties.put("replication.wait.time.between.replicas.ms", "0");
ReplicationConfig config = new ReplicationConfig(new VerifiableProperties(properties));
ReplicationMetrics replicationMetrics = new ReplicationMetrics(new MetricRegistry(), clusterMap.getReplicaIds(localHost.dataNodeId));
replicationMetrics.populatePerColoMetrics(Collections.singleton(remoteHost.dataNodeId.getDatacenterName()));
StoreKeyFactory storeKeyFactory = Utils.getObj("com.github.ambry.commons.BlobIdFactory", clusterMap);
Map<DataNodeId, List<RemoteReplicaInfo>> replicasToReplicate = new HashMap<>();
replicasToReplicate.put(remoteHost.dataNodeId, localHost.getRemoteReplicaInfos(remoteHost, null));
Map<DataNodeId, Host> hosts = new HashMap<>();
hosts.put(remoteHost.dataNodeId, remoteHost);
int batchSize = 4;
MockConnectionPool connectionPool = new MockConnectionPool(hosts, clusterMap, batchSize);
ReplicaThread replicaThread = new ReplicaThread("threadtest", replicasToReplicate, new MockFindTokenFactory(), clusterMap, new AtomicInteger(0), localHost.dataNodeId, connectionPool, config, replicationMetrics, null, storeKeyFactory, true, clusterMap.getMetricRegistry(), false, localHost.dataNodeId.getDatacenterName(), new ResponseHandler(clusterMap));
Map<PartitionId, Integer> progressTracker = new HashMap<>();
PartitionId idToLeaveOut = clusterMap.getAllPartitionIds().get(0);
boolean allStopped = false;
boolean onlyOneResumed = false;
boolean allReenabled = false;
Set<PartitionId> expectedPaused = new HashSet<>();
assertEquals("There should be no disabled partitions", expectedPaused, replicaThread.getReplicationDisabledPartitions());
while (true) {
replicaThread.replicate(new ArrayList<>(replicasToReplicate.values()));
boolean replicationDone = true;
for (RemoteReplicaInfo replicaInfo : replicasToReplicate.get(remoteHost.dataNodeId)) {
PartitionId id = replicaInfo.getReplicaId().getPartitionId();
MockFindToken token = (MockFindToken) replicaInfo.getToken();
int lastProgress = progressTracker.computeIfAbsent(id, id1 -> 0);
int currentProgress = token.getIndex();
boolean partDone = currentProgress + 1 == remoteHost.infosByPartition.get(id).size();
if (allStopped || (onlyOneResumed && !id.equals(idToLeaveOut))) {
assertEquals("There should have been no progress", lastProgress, currentProgress);
} else if (!partDone) {
assertTrue("There has been no progress", currentProgress > lastProgress);
progressTracker.put(id, currentProgress);
}
replicationDone = replicationDone && partDone;
}
if (!allStopped && !onlyOneResumed && !allReenabled) {
replicaThread.controlReplicationForPartitions(clusterMap.getAllPartitionIds(), false);
expectedPaused.addAll(clusterMap.getAllPartitionIds());
assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
allStopped = true;
} else if (!onlyOneResumed && !allReenabled) {
// resume replication for first partition
replicaThread.controlReplicationForPartitions(Collections.singletonList(partitionIds.get(0)), true);
expectedPaused.remove(partitionIds.get(0));
assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
allStopped = false;
onlyOneResumed = true;
} else if (!allReenabled) {
// not removing the first partition
replicaThread.controlReplicationForPartitions(clusterMap.getAllPartitionIds(), true);
onlyOneResumed = false;
allReenabled = true;
expectedPaused.clear();
assertEquals("Disabled partitions sets do not match", expectedPaused, replicaThread.getReplicationDisabledPartitions());
}
if (replicationDone) {
break;
}
}
Map<PartitionId, List<MessageInfo>> missingInfos = remoteHost.getMissingInfos(localHost.infosByPartition);
for (Map.Entry<PartitionId, List<MessageInfo>> entry : missingInfos.entrySet()) {
assertEquals("No infos should be missing", 0, entry.getValue().size());
}
Map<PartitionId, List<ByteBuffer>> missingBuffers = remoteHost.getMissingBuffers(localHost.buffersByPartition);
for (Map.Entry<PartitionId, List<ByteBuffer>> entry : missingBuffers.entrySet()) {
assertEquals("No buffers should be missing", 0, entry.getValue().size());
}
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class RestServerMain method main.
public static void main(String[] args) {
final RestServer restServer;
int exitCode = 0;
ClusterMap clusterMap = null;
try {
InvocationOptions options = new InvocationOptions(args);
Properties properties = Utils.loadProps(options.serverPropsFilePath);
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
ClusterMapConfig clusterMapConfig = new ClusterMapConfig(verifiableProperties);
ClusterAgentsFactory clusterAgentsFactory = Utils.getObj(clusterMapConfig.clusterMapClusterAgentsFactory, clusterMapConfig, options.hardwareLayoutFilePath, options.partitionLayoutFilePath);
clusterMap = clusterAgentsFactory.getClusterMap();
SSLFactory sslFactory = getSSLFactoryIfRequired(verifiableProperties);
logger.info("Bootstrapping RestServer");
restServer = new RestServer(verifiableProperties, clusterMap, new LoggingNotificationSystem(), sslFactory);
// attach shutdown handler to catch control-c
Runtime.getRuntime().addShutdownHook(new Thread() {
public void run() {
logger.info("Received shutdown signal. Shutting down RestServer");
restServer.shutdown();
}
});
restServer.start();
restServer.awaitShutdown();
} catch (Exception e) {
logger.error("Exception during bootstrap of RestServer", e);
exitCode = 1;
} finally {
if (clusterMap != null) {
clusterMap.close();
}
}
logger.info("Exiting RestServerMain");
System.exit(exitCode);
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class AsyncRequestResponseHandlerFactoryTest method getAsyncRequestResponseHandlerTest.
/**
* Tests the instantiation of an {@link AsyncRequestResponseHandler} instance through the
* {@link AsyncRequestResponseHandlerFactory}.
* @throws InstantiationException
*/
@Test
public void getAsyncRequestResponseHandlerTest() throws InstantiationException, IOException {
Properties properties = new Properties();
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
Router router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
// Get response handler.
AsyncRequestResponseHandlerFactory responseHandlerFactory = new AsyncRequestResponseHandlerFactory(1, METRIC_REGISTRY);
RestResponseHandler restResponseHandler = responseHandlerFactory.getRestResponseHandler();
assertNotNull("No RestResponseHandler returned", restResponseHandler);
assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restResponseHandler.getClass().getCanonicalName());
BlobStorageService blobStorageService = new MockBlobStorageService(verifiableProperties, restResponseHandler, router);
// Get request handler.
AsyncRequestResponseHandlerFactory requestHandlerFactory = new AsyncRequestResponseHandlerFactory(1, METRIC_REGISTRY, blobStorageService);
RestRequestHandler restRequestHandler = requestHandlerFactory.getRestRequestHandler();
assertNotNull("No RestRequestHandler returned", restRequestHandler);
assertEquals("Did not receive an AsyncRequestResponseHandler instance", AsyncRequestResponseHandler.class.getCanonicalName(), restRequestHandler.getClass().getCanonicalName());
// make sure they are same instance
assertEquals("Instances of AsyncRequestResponseHandler are not the same", restResponseHandler, restRequestHandler);
// make sure the instance starts and shuts down OK.
restRequestHandler.start();
restRequestHandler.shutdown();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class BadRestRequest method startRequestResponseHandler.
/**
* Sets up all the tests by providing a started {@link AsyncRequestResponseHandler} for their use.
* @throws InstantiationException
* @throws IOException
*/
@BeforeClass
public static void startRequestResponseHandler() throws InstantiationException, IOException {
verifiableProperties = new VerifiableProperties(new Properties());
router = new InMemoryRouter(verifiableProperties, new MockClusterMap());
asyncRequestResponseHandler = getAsyncRequestResponseHandler(5);
blobStorageService.start();
asyncRequestResponseHandler.start();
}
use of com.github.ambry.config.VerifiableProperties in project ambry by linkedin.
the class NettyServerFactoryTest method getNettyServerFactoryWithBadInputTest.
/**
* Tests instantiation of {@link NettyServerFactory} with bad input.
*/
@Test
public void getNettyServerFactoryWithBadInputTest() {
Properties properties = new Properties();
properties.setProperty("netty.server.enable.ssl", "true");
VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
MetricRegistry metricRegistry = new MetricRegistry();
doConstructionFailureTest(null, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
doConstructionFailureTest(verifiableProperties, null, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
doConstructionFailureTest(verifiableProperties, metricRegistry, null, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, SSL_FACTORY);
doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, null, REST_SERVER_STATE, SSL_FACTORY);
doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, null, SSL_FACTORY);
doConstructionFailureTest(verifiableProperties, metricRegistry, REST_REQUEST_HANDLER, PUBLIC_ACCESS_LOGGER, REST_SERVER_STATE, null);
}
Aggregations