View Javadoc

1   package org.apache.helix.controller.stages;
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.Date;
23  import java.util.Map;
24  
25  import org.apache.helix.controller.stages.AttributeName;
26  import org.apache.helix.controller.stages.BestPossibleStateCalcStage;
27  import org.apache.helix.controller.stages.BestPossibleStateOutput;
28  import org.apache.helix.controller.stages.CurrentStateOutput;
29  import org.apache.helix.controller.stages.ReadClusterDataStage;
30  import org.apache.helix.model.Partition;
31  import org.apache.helix.model.Resource;
32  import org.testng.AssertJUnit;
33  import org.testng.annotations.Test;
34  
35  
36  public class TestBestPossibleStateCalcStage extends BaseStageTest
37  {
38    @Test
39    public void testSimple()
40    {
41    	System.out.println("START TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
42  //    List<IdealState> idealStates = new ArrayList<IdealState>();
43  
44      String[] resources = new String[]{ "testResourceName" };
45      setupIdealState(5, resources, 10, 1);
46      setupLiveInstances(5);
47      setupStateModel();
48  
49      Map<String, Resource> resourceMap = getResourceMap();
50      CurrentStateOutput currentStateOutput = new CurrentStateOutput();
51      event.addAttribute(AttributeName.RESOURCES.toString(),
52          resourceMap);
53      event.addAttribute(AttributeName.CURRENT_STATE.toString(),
54          currentStateOutput);
55  
56      ReadClusterDataStage stage1 = new ReadClusterDataStage();
57      runStage(event, stage1);
58      BestPossibleStateCalcStage stage2 = new BestPossibleStateCalcStage();
59      runStage(event, stage2);
60  
61      BestPossibleStateOutput output = event
62          .getAttribute(AttributeName.BEST_POSSIBLE_STATE.toString());
63      for (int p = 0; p < 5; p++)
64      {
65        Partition resource = new Partition("testResourceName_" + p);
66        AssertJUnit.assertEquals(
67            "MASTER",
68            output.getInstanceStateMap("testResourceName", resource).get(
69                "localhost_" + (p + 1) % 5));
70      }
71      System.out.println("END TestBestPossibleStateCalcStage at " + new Date(System.currentTimeMillis()));
72    }
73  }