*/
@Test
public void shouldBlockedItemUntilPatchsetIsReplicatedToSlave() {
PatchsetCreated patchsetCreated = Setup.createPatchsetCreated("someGerritServer", "someProject",
"refs/changes/1/1/1");
Item item = createItem(patchsetCreated, new String[] {"slaveA"});
//item is blocked
CauseOfBlockage cause = dispatcher.canRun(item);
assertNotNull("The item should be blocked", cause);
assertTrue("Should have returned a WaitingForReplication as CauseOfBlockage",
cause instanceof WaitingForReplication);
assertTrue(cause.getShortDescription().contains("slaveA"));
//send an unrelated event (not RefReplicated)
dispatcher.gerritEvent(new ChangeAbandoned());
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send an unrelated replication event (other server)
dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1",
"someOtherGerritServer", "slaveA", RefReplicated.SUCCEEDED_STATUS));
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send an unrelated replication event (other project)
dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someOtherProject", "refs/changes/1/1/1",
"someGerritServer", "slaveA", RefReplicated.SUCCEEDED_STATUS));
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send an unrelated replication event (other ref)
dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/2/2/2", "someGerritServer",
"slaveA", RefReplicated.SUCCEEDED_STATUS));
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send an unrelated replication event (other slave)
dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1", "someGerritServer",
"slaveB", RefReplicated.SUCCEEDED_STATUS));
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send a malformed replication event (missing provider)
RefReplicated refReplicated = Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1",
"someGerritServer", "slaveB", RefReplicated.SUCCEEDED_STATUS);
refReplicated.setProvider(null);
dispatcher.gerritEvent(refReplicated);
assertNotNull("the item should be blocked", dispatcher.canRun(item));
//send the proper replication event
dispatcher.gerritEvent(Setup.createRefReplicatedEvent("someProject", "refs/changes/1/1/1", "someGerritServer",
"slaveA", RefReplicated.SUCCEEDED_STATUS));
assertNull("Item should not be blocked", dispatcher.canRun(item));
assertNull("Item should not be tagged with replicationFailedAction",
item.getAction(ReplicationFailedAction.class));
verify(queueMock, times(1)).maintain();
}