1
2 package org.apache.helix.integration;
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 import java.util.Date;
24
25 import org.apache.helix.PropertyPathConfig;
26 import org.apache.helix.PropertyType;
27 import org.apache.helix.TestHelper;
28 import org.apache.helix.ZNRecord;
29 import org.apache.helix.controller.HelixControllerMain;
30 import org.apache.helix.mock.participant.MockParticipant;
31 import org.apache.helix.tools.ClusterStateVerifier;
32 import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
33 import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier;
34 import org.testng.Assert;
35 import org.testng.annotations.Test;
36
37
38 public class TestCarryOverBadCurState extends ZkIntegrationTestBase
39 {
40 @Test
41 public void testCarryOverBadCurState() throws Exception
42 {
43 System.out.println("START testCarryOverBadCurState at "
44 + new Date(System.currentTimeMillis()));
45
46 String clusterName = getShortClassName();
47 MockParticipant[] participants = new MockParticipant[5];
48
49 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918,
50 "localhost",
51 "TestDB",
52 1,
53 10,
54 5,
55 3,
56 "MasterSlave",
57 true);
58
59
60 ZNRecord badCurState = new ZNRecord("TestDB0");
61 String path = PropertyPathConfig.getPath(PropertyType.CURRENTSTATES, clusterName, "localhost_12918", "session_0", "TestDB0");
62 _gZkClient.createPersistent(path, true);
63 _gZkClient.writeData(path, badCurState);
64
65
66 TestHelper.startController(clusterName,
67 "controller_0",
68 ZK_ADDR,
69 HelixControllerMain.STANDALONE);
70
71 for (int i = 0; i < 5; i++)
72 {
73 String instanceName = "localhost_" + (12918 + i);
74
75 participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
76 participants[i].syncStart();
77 }
78
79 boolean result =
80 ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
81 clusterName));
82 Assert.assertTrue(result);
83
84 result =
85 ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
86 clusterName));
87 Assert.assertTrue(result);
88
89 System.out.println("END testCarryOverBadCurState at "
90 + new Date(System.currentTimeMillis()));
91
92 }
93 }