use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestResourceThreadpoolSize method TestPerStateTransitionTypeThreadPool.
@Test
public void TestPerStateTransitionTypeThreadPool() throws InterruptedException {
String MASTER_SLAVE = "MasterSlave";
int customizedPoolSize = 22;
for (MockParticipantManager participant : _participants) {
participant.getStateMachineEngine().registerStateModelFactory(MASTER_SLAVE, new TestMasterSlaveStateModelFactory(customizedPoolSize), TEST_FACTORY);
}
// add db with customized thread pool
IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "4").setStateModel(MASTER_SLAVE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "4", 1);
Thread.sleep(2000);
// Verify OFFLINE -> SLAVE and SLAVE -> MASTER have different threadpool size.
for (int i = 0; i < NODE_NR; i++) {
DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executorOfflineToSlave = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + OFFLINE_TO_SLAVE));
Assert.assertEquals(customizedPoolSize, executorOfflineToSlave.getMaximumPoolSize());
ThreadPoolExecutor executorSlaveToMaster = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "4" + "." + SLAVE_TO_MASTER));
Assert.assertEquals(customizedPoolSize + 5, executorSlaveToMaster.getMaximumPoolSize());
}
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestResourceThreadpoolSize method TestCustomizedResourceThreadPool.
@Test
public void TestCustomizedResourceThreadPool() {
int customizedPoolSize = 7;
int configuredPoolSize = 9;
for (MockParticipantManager participant : _participants) {
participant.getStateMachineEngine().registerStateModelFactory(ONLINE_OFFLINE, new TestOnlineOfflineStateModelFactory(customizedPoolSize, 0), TEST_FACTORY);
}
// add db with default thread pool
_setupTool.addResourceToCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 64, STATE_MODEL);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "1", 3);
// add db with customized thread pool
IdealState idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "2").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", idealState);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "2", 1);
// add db with configured pool size
idealState = new FullAutoModeISBuilder(WorkflowGenerator.DEFAULT_TGT_DB + "3").setStateModel(ONLINE_OFFLINE).setStateModelFactoryName(TEST_FACTORY).setNumPartitions(10).setNumReplica(1).build();
_setupTool.getClusterManagementTool().addResource(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", idealState);
setResourceThreadPoolSize(WorkflowGenerator.DEFAULT_TGT_DB + "3", configuredPoolSize);
_setupTool.rebalanceStorageCluster(CLUSTER_NAME, WorkflowGenerator.DEFAULT_TGT_DB + "3", 1);
boolean result = ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
Assert.assertTrue(result);
for (int i = 0; i < NODE_NR; i++) {
DefaultMessagingService svc = (DefaultMessagingService) (_participants[i].getMessagingService());
HelixTaskExecutor helixExecutor = svc.getExecutor();
ThreadPoolExecutor executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "1"));
Assert.assertNull(executor);
executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "2"));
Assert.assertEquals(customizedPoolSize, executor.getMaximumPoolSize());
executor = (ThreadPoolExecutor) (helixExecutor._executorMap.get(MessageType.STATE_TRANSITION + "." + WorkflowGenerator.DEFAULT_TGT_DB + "3"));
Assert.assertEquals(configuredPoolSize, executor.getMaximumPoolSize());
}
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestDropResourceMetricsReset method testBasic.
@Test
public void testBasic() throws Exception {
final int NUM_PARTICIPANTS = 4;
final int NUM_PARTITIONS = 64;
final int NUM_REPLICAS = 1;
final String RESOURCE_NAME = "TestDB0";
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
ParticipantMonitorListener listener = new ParticipantMonitorListener("ClusterStatus", clusterName, RESOURCE_NAME);
// Set up cluster
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
NUM_PARTITIONS, // number of nodes
NUM_PARTICIPANTS, // replicas
NUM_REPLICAS, // use FULL_AUTO mode to test node tagging
"MasterSlave", // use FULL_AUTO mode to test node tagging
RebalanceMode.FULL_AUTO, // do rebalance
true);
// Start participants and controller
ClusterSetup setupTool = new ClusterSetup(_gZkClient);
MockParticipantManager[] participants = new MockParticipantManager[NUM_PARTICIPANTS];
for (int i = 0; i < NUM_PARTICIPANTS; i++) {
participants[i] = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_" + (12918 + i));
participants[i].syncStart();
}
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// Verify that the bean was created
boolean noTimeout = _registerLatch.await(30000, TimeUnit.MILLISECONDS);
Assert.assertTrue(noTimeout);
// Drop the resource
setupTool.dropResourceFromCluster(clusterName, RESOURCE_NAME);
// Verify that the bean was removed
noTimeout = _unregisterLatch.await(30000, TimeUnit.MILLISECONDS);
Assert.assertTrue(noTimeout);
// Clean up
listener.disconnect();
controller.syncStop();
for (MockParticipantManager participant : participants) {
participant.syncStop();
}
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestResetClusterMetrics method testControllerDisconnect.
/**
* Ensure cluster status lifecycle is tied to controller leader status
*/
@Test
public void testControllerDisconnect() throws Exception {
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
// Set up a cluster with one of everything
TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, "localhost", "Resource", 1, 1, 1, 1, "OnlineOffline", RebalanceMode.FULL_AUTO, true);
// Add a participant
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participant.syncStart();
// Add a controller
ClusterControllerManager controller = new ClusterControllerManager(ZK_ADDR, clusterName, "controller_0");
controller.syncStart();
// Make sure everything gets assigned
Thread.sleep(1000);
boolean result = ClusterStateVerifier.verifyByZkCallback(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, clusterName));
Assert.assertTrue(result);
// Check the metrics
Assert.assertTrue(metricsExist(clusterName, participant.getInstanceName()));
// Stop the controller
controller.syncStop();
// Check the metrics
Thread.sleep(1000);
Assert.assertFalse(metricsExist(clusterName, participant.getInstanceName()));
}
use of org.apache.helix.integration.manager.MockParticipantManager in project helix by apache.
the class TestHandleNewSession method testHandleNewSession.
@Test
public void testHandleNewSession() throws Exception {
// Logger.getRootLogger().setLevel(Level.INFO);
String className = TestHelper.getTestClassName();
String methodName = TestHelper.getTestMethodName();
String clusterName = className + "_" + methodName;
System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
// participant port
TestHelper.setupCluster(// participant port
clusterName, // participant port
ZK_ADDR, // participant port
12918, // participant name prefix
"localhost", // resource name prefix
"TestDB", // resources
1, // partitions per resource
10, // number of nodes
5, // replicas
3, "MasterSlave", // do rebalance
true);
MockParticipantManager participant = new MockParticipantManager(ZK_ADDR, clusterName, "localhost_12918");
participant.syncStart();
// Logger.getRootLogger().setLevel(Level.INFO);
String lastSessionId = participant.getSessionId();
for (int i = 0; i < 3; i++) {
// System.err.println("curSessionId: " + lastSessionId);
ZkTestHelper.expireSession(participant.getZkClient());
String sessionId = participant.getSessionId();
Assert.assertTrue(sessionId.compareTo(lastSessionId) > 0, "Session id should be increased after expiry");
lastSessionId = sessionId;
// make sure session id is not 0
Assert.assertFalse(sessionId.equals("0"), "Hit race condition in zhclient.handleNewSession(). sessionId is not returned yet.");
// TODO: need to test session expiry during handleNewSession()
}
// Logger.getRootLogger().setLevel(Level.INFO);
System.out.println("Disconnecting ...");
participant.syncStop();
System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
}
Aggregations