View Javadoc

1   package org.apache.helix.integration;
2   
3   /*
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *   http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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      // Logger.getRootLogger().setLevel(Level.INFO);
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  //    ClusterSetup setupTool = new ClusterSetup(ZK_ADDR);
55  
56      TestHelper.setupCluster(clusterName, ZK_ADDR, 12918, // participant port
57                              "localhost", // participant name prefix
58                              "TestDB", // resource name prefix
59                              1, // resources
60                              10, // partitions per resource
61                              5, // number of nodes
62                              3, // replicas
63                              "MasterSlave",
64                              true); // do rebalance
65      
66      ZkBaseDataAccessor<ZNRecord> baseAccessor = new ZkBaseDataAccessor<ZNRecord>(_gZkClient);
67      ZKHelixDataAccessor accessor = new ZKHelixDataAccessor(clusterName, baseAccessor);
68      // String idealStatePath = PropertyPathConfig.getPath(PropertyType.IDEALSTATES, clusterName, "TestDB0");
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      // start participants
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      // clean up
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 }