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.Arrays;
23  import java.util.Date;
24  import java.util.HashMap;
25  import java.util.Map;
26  import java.util.Set;
27  
28  import org.apache.helix.TestHelper;
29  import org.apache.helix.manager.zk.ZKHelixAdmin;
30  import org.apache.helix.tools.ClusterSetup;
31  import org.apache.helix.tools.ClusterStateVerifier;
32  import org.apache.log4j.Logger;
33  import org.testng.Assert;
34  import org.testng.annotations.Test;
35  
36  
37  public class TestDisablePartition extends ZkStandAloneCMTestBaseWithPropertyServerCheck
38  {
39    private static Logger LOG = Logger.getLogger(TestDisablePartition.class);
40  
41    @Test()
42    public void testDisablePartition() throws Exception
43    {
44      LOG.info("START testDisablePartition() at " + new Date(System.currentTimeMillis()));
45  
46      // localhost_12919 is MASTER for TestDB_0
47      String command = "--zkSvr " + ZK_ADDR +" --enablePartition false " + CLUSTER_NAME +
48          " localhost_12919 TestDB TestDB_0 TestDB_9";
49      ClusterSetup.processCommandLineArgs(command.split("\\s+"));
50      Map<String, Set<String>> map = new HashMap<String, Set<String>>();
51      map.put("TestDB_0", TestHelper.setOf("localhost_12919"));
52      map.put("TestDB_9", TestHelper.setOf("localhost_12919"));
53  
54      boolean result = ClusterStateVerifier.verifyByPolling(
55          new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
56      Assert.assertTrue(result);
57  
58      TestHelper.verifyState(CLUSTER_NAME, ZK_ADDR, map, "OFFLINE");
59  
60      ZKHelixAdmin tool = new ZKHelixAdmin(_zkClient);
61      tool.enablePartition(true, CLUSTER_NAME, "localhost_12919", "TestDB", Arrays.asList("TestDB_9"));
62  
63      result = ClusterStateVerifier.verifyByPolling(
64          new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR, CLUSTER_NAME));
65      Assert.assertTrue(result);
66  
67      map.clear();
68      map.put("TestDB_0", TestHelper.setOf("localhost_12919"));
69      TestHelper.verifyState(CLUSTER_NAME, ZK_ADDR, map, "OFFLINE");
70  
71      map.clear();
72      map.put("TestDB_9", TestHelper.setOf("localhost_12919"));
73      TestHelper.verifyState(CLUSTER_NAME, ZK_ADDR, map, "MASTER");
74  
75      LOG.info("STOP testDisablePartition() at " + new Date(System.currentTimeMillis()));
76  
77    }
78  
79  }