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.TestHelper;
25 import org.apache.helix.ZNRecord;
26 import org.apache.helix.PropertyKey.Builder;
27 import org.apache.helix.controller.HelixControllerMain;
28 import org.apache.helix.manager.zk.ZKHelixDataAccessor;
29 import org.apache.helix.manager.zk.ZkBaseDataAccessor;
30 import org.apache.helix.mock.participant.MockParticipant;
31 import org.apache.helix.model.IdealState;
32 import org.apache.helix.tools.ClusterStateVerifier;
33 import org.apache.helix.tools.ClusterStateVerifier.BestPossAndExtViewZkVerifier;
34 import org.apache.helix.tools.ClusterStateVerifier.MasterNbInExtViewVerifier;
35 import org.testng.Assert;
36 import org.testng.annotations.Test;
37
38
39 public class TestBucketizedResource extends ZkIntegrationTestBase
40 {
41 @Test()
42 public void testBucketizedResource() throws Exception
43 {
44
45 String className = TestHelper.getTestClassName();
46 String methodName = TestHelper.getTestMethodName();
47 String clusterName = className + "_" + methodName;
48
49 System.out.println("START " + clusterName + " at "
50 + new Date(System.currentTimeMillis()));
51
52
53 MockParticipant[] participants = new MockParticipant[5];
54
55
56 TestHelper.setupCluster(clusterName, ZK_ADDR, 12918,
57 "localhost",
58 "TestDB",
59 1,
60 10,
61 5,
62 3,
63 "MasterSlave",
64 true);
65
66 ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
67 ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
68
69 Builder keyBuilder = accessor.keyBuilder();
70 IdealState idealState = accessor.getProperty(keyBuilder.idealStates("TestDB0"));
71 idealState.setBucketSize(1);
72 accessor.setProperty(keyBuilder.idealStates("TestDB0"), idealState);
73
74 TestHelper.startController(clusterName,
75 "controller_0",
76 ZK_ADDR,
77 HelixControllerMain.STANDALONE);
78
79 for (int i = 0; i < 5; i++)
80 {
81 String instanceName = "localhost_" + (12918 + i);
82
83 participants[i] = new MockParticipant(clusterName, instanceName, ZK_ADDR, null);
84 participants[i].syncStart();
85 }
86
87 boolean result =
88 ClusterStateVerifier.verifyByZkCallback(new MasterNbInExtViewVerifier(ZK_ADDR,
89 clusterName));
90 Assert.assertTrue(result);
91
92 result =
93 ClusterStateVerifier.verifyByZkCallback(new BestPossAndExtViewZkVerifier(ZK_ADDR,
94 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 "
104 + new Date(System.currentTimeMillis()));
105 }
106 }