1 package org.apache.helix.integration;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Date;
23
24 import org.apache.helix.PropertyPathConfig;
25 import org.apache.helix.PropertyType;
26 import org.apache.helix.TestHelper;
27 import org.apache.helix.ZkTestHelper;
28 import org.apache.helix.mock.controller.ClusterController;
29 import org.apache.helix.model.IdealState.IdealStateModeProperty;
30 import org.apache.log4j.Level;
31 import org.apache.log4j.Logger;
32 import org.testng.Assert;
33 import org.testng.annotations.Test;
34
35 public class TestStartMultipleControllersWithSameName extends ZkIntegrationTestBase {
36 @Test
37 public void test() throws Exception {
38 Logger.getRootLogger().setLevel(Level.WARN);
39 String className = TestHelper.getTestClassName();
40 String methodName = TestHelper.getTestMethodName();
41 String clusterName = className + "_" + methodName;
42 final int n = 3;
43
44 System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
45
46 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918,
47 "localhost",
48 "TestDB",
49 1,
50 10,
51 n,
52 1,
53 "OnlineOffline", IdealStateModeProperty.AUTO_REBALANCE, true);
54
55
56
57 ClusterController[] controllers = new ClusterController[4];
58 for (int i = 0; i < 4; i++) {
59 controllers[i] = new ClusterController(clusterName, "controller_0", ZK_ADDR);
60 controllers[i].start();
61 }
62
63 Thread.sleep(500);
64 String liPath = PropertyPathConfig.getPath(PropertyType.LIVEINSTANCES, clusterName);
65 int listenerNb = ZkTestHelper.numberOfListeners(ZK_ADDR, liPath);
66
67 Assert.assertEquals(listenerNb, 1, "Only one controller should succeed in becoming leader");
68
69
70
71 for (int i = 0; i < 4; i++) {
72 controllers[i].syncStop();
73 Thread.sleep(1000);
74 }
75
76 System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
77
78 }
79
80 }