View Javadoc

1   package org.apache.helix.tools;
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.logging.Level;
23  
24  import org.I0Itec.zkclient.ZkServer;
25  import org.apache.helix.TestHelper;
26  import org.apache.helix.manager.zk.ZNRecordSerializer;
27  import org.apache.helix.manager.zk.ZkClient;
28  import org.apache.helix.tools.ClusterSetup;
29  import org.apache.helix.tools.AdminTestHelper.AdminThread;
30  import org.apache.helix.util.ZKClientPool;
31  import org.apache.log4j.Logger;
32  import org.testng.AssertJUnit;
33  import org.testng.annotations.AfterSuite;
34  import org.testng.annotations.BeforeSuite;
35  
36  
37  public class AdminTestBase
38  {
39    private static Logger      LOG        = Logger.getLogger(AdminTestBase.class);
40    public static final String ZK_ADDR    = "localhost:2187";
41    protected final static int           ADMIN_PORT = 2202;
42  
43    protected static ZkServer  _zkServer;
44    protected static ZkClient  _gZkClient;
45    protected static ClusterSetup _gSetupTool;
46  
47    static AdminThread         _adminThread;
48  
49    @BeforeSuite
50    public void beforeSuite() throws Exception
51    {
52      // TODO: use logging.properties file to config java.util.logging.Logger levels
53      java.util.logging.Logger topJavaLogger = java.util.logging.Logger.getLogger("");
54      topJavaLogger.setLevel(Level.WARNING);
55  
56      // start zk
57      _zkServer = TestHelper.startZkServer(ZK_ADDR);
58      AssertJUnit.assertTrue(_zkServer != null);
59      ZKClientPool.reset();
60  
61      _gZkClient = new ZkClient(ZK_ADDR);
62      _gZkClient.setZkSerializer(new ZNRecordSerializer());
63      _gSetupTool = new ClusterSetup(ZK_ADDR);
64      
65      // start admin
66      _adminThread = new AdminThread(ZK_ADDR, ADMIN_PORT);
67      _adminThread.start();
68      
69      // wait for the web service to start
70      Thread.sleep(100);
71    }
72  
73    @AfterSuite
74    public void afterSuite()
75    {
76      // System.out.println("START AdminTestBase.afterSuite() at " + new Date(System.currentTimeMillis()));
77      // stop admin
78      _adminThread.stop();
79      
80      // stop zk
81      ZKClientPool.reset();
82      _gZkClient.close();
83  
84      TestHelper.stopZkServer(_zkServer);
85      // System.out.println("END AdminTestBase.afterSuite() at " + new Date(System.currentTimeMillis()));
86    }
87  
88  }