1 package org.apache.helix.controller.stages;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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 }