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.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
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 }