@Test
public void testSubmitRequest() throws Exception {

    LinkedList<OFSwitchImpl> switches = new LinkedList<OFSwitchImpl>();
    roleChanger.timeout = 500*1000*1000; // 500 ms
    
    // a switch that supports role requests
    OFSwitchImpl sw1 = EasyMock.createStrictMock(OFSwitchImpl.class);
    // No support for NX_ROLE
    expect(sw1.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE))
                    .andReturn(true); 
    expect(sw1.sendNxRoleRequest(EasyMock.same(Role.MASTER), EasyMock.anyLong()))
                   .andReturn(1);
    expect(sw1.getAttribute(IOFSwitch.SWITCH_SUPPORTS_NX_ROLE))
                    .andReturn(true); 
    expect(sw1.sendNxRoleRequest(EasyMock.same(Role.SLAVE), EasyMock.anyLong()))
                   .andReturn(1);
    // The following calls happen for timeout handling:
    expect(sw1.checkFirstPendingRoleRequestCookie(EasyMock.anyLong()))
                    .andReturn(false);
    expect(sw1.checkFirstPendingRoleRequestCookie(EasyMock.anyLong()))
                    .andReturn(false);
    switches.add(sw1);
    
    
    replay(sw1);
    roleChanger.submitRequest(switches, Role.MASTER);
    roleChanger.submitRequest(switches, Role.SLAVE);
    // Wait until role request has been sent. 
    // TODO: need to get rid of this sleep somehow
    Thread.sleep(100);
    // Now there should be exactly one timeout task pending
    assertEquals(2, roleChanger.pendingTasks.size());
    // Make sure it's indeed a timeout task
    assertSame(RoleChanger.RoleChangeTask.Type.TIMEOUT, 
                 roleChanger.pendingTasks.peek().type);
    // Check that RoleChanger indeed made a copy of switches collection
    assertNotSame(switches, roleChanger.pendingTasks.peek().switches);
    
    // Wait until the timeout triggers 
    // TODO: get rid of this sleep too.
    Thread.sleep(500);
    assertEquals(0, roleChanger.pendingTasks.size());
    verify(sw1);
    
}