示例#1
0
  /** Test other setRole cases: re-setting role to the current role, setting role to equal, etc. */
  @Test
  public void testSetRoleOthercases() throws Exception {
    doSetUp(HARole.STANDBY);

    // Create and add the HA listener
    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    replay(listener);
    controller.addHAListener(listener);

    // Set role to slave again. Nothing should happen
    controller.setRole(HARole.STANDBY, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);

    reset(listener);
    expect(listener.getName()).andReturn("foo").anyTimes();
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
  }
示例#2
0
  /**
   * Start as SLAVE then set role to MASTER Tests normal role change transition. Check that
   * connected channels receive a setRole request
   */
  @Test
  public void testSetRole() throws Exception {
    doSetUp(HARole.STANDBY);
    RoleInfo info = controller.getRoleInfo();
    assertEquals(HARole.STANDBY, info.getRole());
    assertEquals(HARole.STANDBY, controller.getRole());

    OFSwitchHandshakeHandler h = createMock(OFSwitchHandshakeHandler.class);

    // Reassert the role.
    reset(h);
    h.sendRoleRequestIfNotPending(OFControllerRole.ROLE_SLAVE);
    replay(h);
    controller.reassertRole(h, HARole.STANDBY);
    verify(h);

    // reassert a different role: no-op
    reset(h);
    replay(h);
    controller.reassertRole(h, HARole.ACTIVE);
    verify(h);

    IHAListener listener = createMock(IHAListener.class);
    expect(listener.getName()).andReturn("foo").anyTimes();
    setupListenerOrdering(listener);
    listener.transitionToActive();
    expectLastCall().once();
    replay(listener);
    controller.addHAListener(listener);
    controller.setRole(HARole.ACTIVE, "FooBar");
    controller.processUpdateQueueForTesting();
    verify(listener);
    info = controller.getRoleInfo();
    assertEquals(HARole.ACTIVE, info.getRole());
    assertEquals("FooBar", info.getRoleChangeDescription());
    assertEquals(HARole.ACTIVE, controller.getRole());
  }