View Javadoc

1   
2   package org.apache.helix.integration;
3   
4   /*
5    * Licensed to the Apache Software Foundation (ASF) under one
6    * or more contributor license agreements.  See the NOTICE file
7    * distributed with this work for additional information
8    * regarding copyright ownership.  The ASF licenses this file
9    * to you under the Apache License, Version 2.0 (the
10   * "License"); you may not use this file except in compliance
11   * with the License.  You may obtain a copy of the License at
12   *
13   *   http://www.apache.org/licenses/LICENSE-2.0
14   *
15   * Unless required by applicable law or agreed to in writing,
16   * software distributed under the License is distributed on an
17   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18   * KIND, either express or implied.  See the License for the
19   * specific language governing permissions and limitations
20   * under the License.
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, // participant port
50                              "localhost", // participant name prefix
51                              "TestDB", // resource name prefix
52                              1, // resources
53                              10, // partitions per resource
54                              5, // number of nodes
55                              3, // replicas
56                              "MasterSlave",
57                              true); // do rebalance
58  
59      // add a bad current state
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      // start participants
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  }