コード例 #1
0
  @Test
  public void testMasterMasterIsElected() {
    // CASE 1: Got MasterIsElected for me. Should remain master.
    HighAvailabilityMemberState newState = MASTER.masterIsElected(context, myId);
    assertEquals(MASTER, newState);

    // CASE 2: Got MasterIsElected for someone else. Should switch to pending.
    HighAvailabilityMemberState newStateCase2 = MASTER.masterIsElected(context, new InstanceId(2));
    assertEquals(PENDING, newStateCase2);
  }
コード例 #2
0
  @Test
  public void testMasterMasterIsAvailable() {
    // CASE 1: Got MasterIsAvailable for someone else - should fail.
    try {
      MASTER.masterIsAvailable(context, new InstanceId(2), SampleUri);
      fail("Should not allow master switch with missing masterIsElected");
    } catch (RuntimeException e) {
      // wonderful
    }

    // CASE 2: Got MasterIsAvailable for us - it's ok, should pass
    HighAvailabilityMemberState newState = MASTER.masterIsAvailable(context, myId, SampleUri);
    assertEquals(MASTER, newState);
  }
コード例 #3
0
  @Test
  public void testMasterSlaveIsAvailable() {
    // CASE 1: Got SlaveIsAvailable for me - should fail.
    try {
      MASTER.slaveIsAvailable(context, myId, SampleUri);
      fail("MASTER to SLAVE is not allowed");
    } catch (RuntimeException e) {
      // awesome
    }

    // CASE 2: Got SlaveIsAvailable for someone else - who cares? Should succeed.
    HighAvailabilityMemberState newState =
        MASTER.slaveIsAvailable(context, new InstanceId(2), SampleUri);
    assertEquals(MASTER, newState);
  }