@Test
public void testHARoleChange() throws Exception {

    LinkDiscoveryManager topology = getTopology();
    IOFSwitch sw1 = createMockSwitch(1L);
    IOFSwitch sw2 = createMockSwitch(2L);
    replay(sw1, sw2);
    Link lt = new Link(1L, 2, 2L, 1);
    NodePortTuple srcNpt = new NodePortTuple(1L, 2);
    NodePortTuple dstNpt = new NodePortTuple(2L, 1);
    LinkInfo info = new LinkInfo(System.currentTimeMillis(),
                                 System.currentTimeMillis(), null,
                                 0, 0);
    topology.addOrUpdateLink(lt, info);
    // check invariants hold
    assertNotNull(topology.switchLinks.get(lt.getSrc()));
    assertTrue(topology.switchLinks.get(lt.getSrc()).contains(lt));
    assertNotNull(topology.portLinks.get(srcNpt));
    assertTrue(topology.portLinks.get(srcNpt).contains(lt));
    assertNotNull(topology.portLinks.get(dstNpt));
    assertTrue(topology.portLinks.get(dstNpt).contains(lt));
    assertTrue(topology.links.containsKey(lt));
    
    // check that it clears from memory
    getMockFloodlightProvider().dispatchRoleChanged(null, Role.SLAVE);
    assertTrue(topology.switchLinks.isEmpty());
    getMockFloodlightProvider().dispatchRoleChanged(Role.SLAVE, Role.MASTER);
    // check that lldps were sent
    assertTrue(ldm.isSendLLDPsCalled);
    assertTrue(ldm.isClearLinksCalled);
    ldm.reset();
}