View Javadoc

1   package org.apache.helix.manager.zk;
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.HelixDataAccessor;
23  import org.apache.helix.TestHelper;
24  import org.apache.helix.TestHelper.StartCMResult;
25  import org.apache.helix.controller.HelixControllerMain;
26  import org.apache.helix.controller.restlet.ZKPropertyTransferServer;
27  import org.apache.helix.integration.ZkStandAloneCMTestBaseWithPropertyServerCheck;
28  import org.apache.helix.manager.zk.ZKHelixDataAccessor;
29  import org.apache.log4j.Logger;
30  import org.testng.Assert;
31  import org.testng.annotations.Test;
32  
33  
34  public class TestZKPropertyTransferServer extends ZkStandAloneCMTestBaseWithPropertyServerCheck
35  {
36    private static Logger LOG =
37        Logger.getLogger(TestZKPropertyTransferServer.class);
38  
39    @Test
40    public void TestControllerChange() throws Exception
41    {
42      String controllerName = CONTROLLER_PREFIX + "_0";
43      _startCMResultMap.get(controllerName)._manager.disconnect();
44      
45      Thread.sleep(1000);
46      
47      // kill controller, participant should not know about the svc url
48      for (int i = 0; i < NODE_NR; i++)
49      {
50        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
51        HelixDataAccessor accessor = _startCMResultMap.get(instanceName)._manager.getHelixDataAccessor();
52        ZKHelixDataAccessor zkAccessor = (ZKHelixDataAccessor) accessor;
53        Assert.assertTrue(zkAccessor._zkPropertyTransferSvcUrl == null || zkAccessor._zkPropertyTransferSvcUrl.equals(""));
54      }
55      _startCMResultMap.get(controllerName)._thread.interrupt();
56      _startCMResultMap.remove(controllerName);
57      
58      StartCMResult startResult =
59          TestHelper.startController(CLUSTER_NAME,
60                                     controllerName,
61                                     ZK_ADDR,
62                                     HelixControllerMain.STANDALONE);
63      _startCMResultMap.put(controllerName, startResult);
64      
65      Thread.sleep(1000);
66      
67      // create controller again, the svc url is notified to the participants
68      for (int i = 0; i < NODE_NR; i++)
69      {
70        String instanceName = PARTICIPANT_PREFIX + "_" + (START_PORT + i);
71        HelixDataAccessor accessor = _startCMResultMap.get(instanceName)._manager.getHelixDataAccessor();
72        ZKHelixDataAccessor zkAccessor = (ZKHelixDataAccessor) accessor;
73        Assert.assertTrue(zkAccessor._zkPropertyTransferSvcUrl.equals(ZKPropertyTransferServer.getInstance().getWebserviceUrl()));
74      }
75    }
76    
77  
78  }