@Test public void testSlaveMasterIsAvailable() { // CASE 1: It is me who is available as master - i don't think so try { SLAVE.masterIsAvailable(context, myId, SampleUri); fail("Should have gotten an election result first"); } catch (RuntimeException e) { // outstanding } // CASE 2: It is someone else that is available as master and is not the master now - missed the // election, fail InstanceId masterInstanceId = new InstanceId(2); when(context.getElectedMasterId()).thenReturn(masterInstanceId); try { SLAVE.masterIsAvailable(context, new InstanceId(3), SampleUri); fail("Should have gotten an election result first"); } catch (RuntimeException e) { // outstanding } // CASE 3: It is the same master as now - it's ok, stay calm and carry on HighAvailabilityMemberState newState = SLAVE.masterIsAvailable(context, masterInstanceId, SampleUri); assertEquals(SLAVE, newState); }
@Test public void testSlaveMasterIsElected() { // CASE 1: It is me that got elected master - should switch to TO_MASTER HighAvailabilityMemberState newState = SLAVE.masterIsElected(context, myId); assertEquals(TO_MASTER, newState); InstanceId masterInstanceId = new InstanceId(2); when(context.getElectedMasterId()).thenReturn(masterInstanceId); // CASE 2: It is someone else that got elected master - should switch to PENDING HighAvailabilityMemberState newStateCase2 = SLAVE.masterIsElected(context, new InstanceId(3)); assertEquals(PENDING, newStateCase2); // CASE 3: It is the current master that got elected again - ignore HighAvailabilityMemberState newStateCase3 = SLAVE.masterIsElected(context, masterInstanceId); assertEquals(SLAVE, newStateCase3); }
@Test public void testSlaveSlaveIsAvailable() { // CASE 1 and only - always remain in SLAVE assertEquals( SLAVE, SLAVE.slaveIsAvailable( mock(HighAvailabilityMemberContext.class), mock(InstanceId.class), SampleUri)); }