use of org.onosproject.cluster.Leader in project onos by opennetworkinglab.
the class SimpleLeadershipManager method runForLeadership.
@Override
public Leadership runForLeadership(String path) {
elections.put(path, true);
Leadership leadership = new Leadership(path, new Leader(localNodeId, 0, 0), Arrays.asList(localNodeId));
for (LeadershipEventListener listener : listeners) {
listener.event(new LeadershipEvent(Type.LEADER_AND_CANDIDATES_CHANGED, leadership));
}
return leadership;
}
use of org.onosproject.cluster.Leader in project onos by opennetworkinglab.
the class VplsOperationManagerTest method testLeadershipEvent.
/**
* Sends leadership event to the manager and checks if the manager is
* leader or not.
*/
@Test
public void testLeadershipEvent() {
vplsOperationManager.isLeader = false;
vplsOperationManager.localNodeId = NODE_ID_1;
// leader changed to self
Leader leader = new Leader(NODE_ID_1, 0, 0);
Leadership leadership = new Leadership(APP_NAME, leader, ImmutableList.of());
LeadershipEvent event = new LeadershipEvent(LeadershipEvent.Type.LEADER_CHANGED, leadership);
((TestLeadershipService) vplsOperationManager.leadershipService).sendEvent(event);
assertTrue(vplsOperationManager.isLeader);
// leader changed to other
leader = new Leader(NODE_ID_2, 0, 0);
leadership = new Leadership(APP_NAME, leader, ImmutableList.of());
event = new LeadershipEvent(LeadershipEvent.Type.LEADER_CHANGED, leadership);
((TestLeadershipService) vplsOperationManager.leadershipService).sendEvent(event);
assertFalse(vplsOperationManager.isLeader);
}
Aggregations