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 org.apache.helix.TestHelper;
23 import org.apache.helix.TestHelper.StartCMResult;
24 import org.apache.helix.tools.ClusterSetup;
25 import org.apache.helix.tools.ClusterStateVerifier;
26 import org.testng.Assert;
27 import org.testng.annotations.Test;
28
29 public class TestDropResource extends ZkStandAloneCMTestBaseWithPropertyServerCheck
30 {
31 @Test()
32 public void testDropResource() throws Exception
33 {
34
35 _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB", 6, STATE_MODEL);
36 _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB", 3);
37
38 boolean result =
39 ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
40 CLUSTER_NAME));
41 Assert.assertTrue(result);
42
43 String command =
44 "-zkSvr " + ZK_ADDR + " -dropResource " + CLUSTER_NAME + " " + "MyDB";
45 ClusterSetup.processCommandLineArgs(command.split(" "));
46
47 TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView",
48 30 * 1000,
49 CLUSTER_NAME,
50 "MyDB",
51 TestHelper.<String> setOf("localhost_12918",
52 "localhost_12919",
53 "localhost_12920",
54 "localhost_12921",
55 "localhost_12922"),
56 ZK_ADDR);
57 }
58
59 @Test()
60 public void testDropResourceWhileNodeDead() throws Exception
61 {
62
63 _setupTool.addResourceToCluster(CLUSTER_NAME, "MyDB2", 16, STATE_MODEL);
64 _setupTool.rebalanceStorageCluster(CLUSTER_NAME, "MyDB2", 3);
65
66 boolean verifyResult =
67 ClusterStateVerifier.verifyByPolling(new ClusterStateVerifier.BestPossAndExtViewZkVerifier(ZK_ADDR,
68 CLUSTER_NAME));
69 Assert.assertTrue(verifyResult);
70
71 String hostToKill = "localhost_12920";
72
73 _startCMResultMap.get(hostToKill)._manager.disconnect();
74 Thread.sleep(1000);
75 _startCMResultMap.get(hostToKill)._thread.interrupt();
76
77 String command =
78 "-zkSvr " + ZK_ADDR + " -dropResource " + CLUSTER_NAME + " " + "MyDB2";
79 ClusterSetup.processCommandLineArgs(command.split(" "));
80
81 TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView",
82 30 * 1000,
83 CLUSTER_NAME,
84 "MyDB2",
85 TestHelper.<String> setOf("localhost_12918",
86 "localhost_12919",
87
88 "localhost_12922"),
89 ZK_ADDR);
90
91 StartCMResult result =
92 TestHelper.startDummyProcess(ZK_ADDR, CLUSTER_NAME, hostToKill);
93 _startCMResultMap.put(hostToKill, result);
94
95 TestHelper.verifyWithTimeout("verifyEmptyCurStateAndExtView",
96 30 * 1000,
97 CLUSTER_NAME,
98 "MyDB2",
99 TestHelper.<String> setOf("localhost_12918",
100 "localhost_12919",
101 "localhost_12920",
102 "localhost_12921",
103 "localhost_12922"),
104 ZK_ADDR);
105 }
106 }