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.ArrayList;
23 import java.util.Date;
24 import java.util.List;
25
26 import org.apache.helix.PropertyPathConfig;
27 import org.apache.helix.PropertyType;
28 import org.apache.helix.TestHelper;
29 import org.apache.helix.ZNRecord;
30 import org.apache.helix.controller.HelixControllerMain;
31 import org.apache.helix.mock.participant.MockParticipant;
32 import org.apache.helix.model.IdealState;
33 import org.apache.helix.tools.ClusterStateVerifier;
34 import org.apache.helix.tools.DefaultIdealStateCalculator;
35 import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
36 import org.testng.Assert;
37 import org.testng.annotations.Test;
38
39
40 public class TestAutoIsWithEmptyMap extends ZkIntegrationTestBase
41 {
42 @Test
43 public void testAutoIsWithEmptyMap() throws Exception
44 {
45 String className = TestHelper.getTestClassName();
46 String methodName = TestHelper.getTestMethodName();
47 String clusterName = className + "_" + methodName;
48 System.out.println("START " + clusterName + " at " + new Date(System.currentTimeMillis()));
49
50 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918,
51 "localhost",
52 "TestDB",
53 1,
54 10,
55 5,
56 3,
57 "LeaderStandby", false);
58
59
60 String idealPath = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, clusterName, "TestDB0");
61 ZNRecord curIdealState = _gZkClient.readData(idealPath);
62
63 List<String> instanceNames = new ArrayList<String>(5);
64 for (int i = 0; i < 5; i++)
65 {
66 int port = 12918 + i;
67 instanceNames.add("localhost_" + port);
68 }
69 ZNRecord idealState = DefaultIdealStateCalculator.calculateIdealState(instanceNames, 10,
70 2, "TestDB0", "LEADER", "STANDBY");
71
72
73
74 curIdealState.setSimpleField(IdealState.IdealStateProperty.REPLICAS.toString(), "3");
75
76 curIdealState.setListFields(idealState.getListFields());
77 _gZkClient.writeData(idealPath, curIdealState);
78
79
80 TestHelper
81 .startController(clusterName, "controller_0", ZK_ADDR, HelixControllerMain.STANDALONE);
82
83
84 MockParticipant[] participants = new MockParticipant[5];
85 for (int i = 0; i < 5; i++)
86 {
87 String instanceName = "localhost_" + (12918 + i);
88
89 participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
90 participants[i].syncStart();
91 }
92
93 boolean result = ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(
94 ZK_ADDR, clusterName));
95 Assert.assertTrue(result);
96
97
98 for (int i = 0; i < 5; i++)
99 {
100 participants[i].syncStop();
101 }
102
103 System.out.println("END " + clusterName + " at " + new Date(System.currentTimeMillis()));
104
105 }
106 }