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 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      // add a resource to be dropped
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      // add a resource to be dropped
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                                                             /* "localhost_12920", */"localhost_12921",
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 }