MessageThrottleStage throttleStage = new MessageThrottleStage();
// test constraintSelection
// message1: hit contraintSelection rule1 and rule2
Message msg1 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-001",
"OFFLINE",
"SLAVE",
"TestDB",
"localhost_0");
Map<ConstraintAttribute, String> msgAttr =
ClusterConstraints.toConstraintAttributes(msg1);
Set<ConstraintItem> matches = constraint.match(msgAttr);
System.out.println(msg1 + " matches(" + matches.size() + "): " + matches);
Assert.assertEquals(matches.size(), 5);
Assert.assertTrue(containsConstraint(matches, constraint0));
Assert.assertTrue(containsConstraint(matches, constraint1));
Assert.assertTrue(containsConstraint(matches, constraint2));
Assert.assertTrue(containsConstraint(matches, constraint4));
Assert.assertTrue(containsConstraint(matches, constraint5));
matches = throttleStage.selectConstraints(matches, msgAttr);
System.out.println(msg1 + " matches(" + matches.size() + "): " + matches);
Assert.assertEquals(matches.size(), 2);
Assert.assertTrue(containsConstraint(matches, constraint1));
Assert.assertTrue(containsConstraint(matches, constraint5));
// message2: hit contraintSelection rule1, rule2, and rule3
Message msg2 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-002",
"OFFLINE",
"SLAVE",
"TestDB",
"localhost_1");
msgAttr = ClusterConstraints.toConstraintAttributes(msg2);
matches = constraint.match(msgAttr);
System.out.println(msg2 + " matches(" + matches.size() + "): " + matches);
Assert.assertEquals(matches.size(), 5);
Assert.assertTrue(containsConstraint(matches, constraint0));
Assert.assertTrue(containsConstraint(matches, constraint1));
Assert.assertTrue(containsConstraint(matches, constraint2));
Assert.assertTrue(containsConstraint(matches, constraint3));
Assert.assertTrue(containsConstraint(matches, constraint4));
matches = throttleStage.selectConstraints(matches, msgAttr);
System.out.println(msg2 + " matches(" + matches.size() + "): " + matches);
Assert.assertEquals(matches.size(), 2);
Assert.assertTrue(containsConstraint(matches, constraint1));
Assert.assertTrue(containsConstraint(matches, constraint3));
// test messageThrottleStage
ClusterEvent event = new ClusterEvent("testEvent");
event.addAttribute("helixmanager", manager);
Pipeline dataRefresh = new Pipeline();
dataRefresh.addStage(new ReadClusterDataStage());
runPipeline(event, dataRefresh);
runStage(event, new ResourceComputationStage());
MessageSelectionStageOutput msgSelectOutput = new MessageSelectionStageOutput();
Message msg3 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-003",
"OFFLINE",
"SLAVE",
"TestDB",
"localhost_0");
Message msg4 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-004",
"OFFLINE",
"SLAVE",
"TestDB",
"localhost_0");
Message msg5 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-005",
"OFFLINE",
"SLAVE",
"TestDB",
"localhost_0");
Message msg6 =
createMessage(MessageType.STATE_TRANSITION,
"msgId-006",
"OFFLINE",
"SLAVE",
"TestDB",