### Question:
SwitchReadWriteConnectMonitor extends SwitchConnectMonitor { @Override protected boolean isReadWriteMode() { return true; } SwitchReadWriteConnectMonitor(SwitchMonitorCarrier carrier, Clock clock, SwitchId switchId);   }### Answer:
@Test public void multipleConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); verify(carrier, times(1)) .switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_A, subject.isReadWriteMode()))); subject.handleSwitchStatusNotification(connectEvent, REGION_B); verify(carrier, times(1)) .switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier, never()).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_B, subject.isReadWriteMode()))); }
@Test public void disconnectOneOfOneConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); verify(carrier).switchStatusUpdateNotification(eq(connectEvent.getSwitchId()), eq(connectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(connectEvent.getSwitchId(), REGION_A, subject.isReadWriteMode()))); Instant now = clock.adjust(Duration.ofSeconds(1)); Assert.assertTrue(subject.isAvailable()); SwitchInfoData disconnectEvent = makeDisconnectNotification(connectEvent.getSwitchId()); subject.handleSwitchStatusNotification(disconnectEvent, REGION_A); verify(carrier).switchStatusUpdateNotification( eq(disconnectEvent.getSwitchId()), ArgumentMatchers.eq(disconnectEvent)); Assert.assertFalse(subject.isAvailable()); Assert.assertEquals(now, subject.getBecomeUnavailableAt()); }
@Test public void disconnectTwoOfTwoConnections() { SwitchReadWriteConnectMonitor subject = makeSubject(SWITCH_ALPHA); SwitchInfoData connectEvent = makeConnectNotification(SWITCH_ALPHA); subject.handleSwitchStatusNotification(connectEvent, REGION_A); subject.handleSwitchStatusNotification(connectEvent, REGION_B); Assert.assertTrue(subject.isAvailable()); SwitchInfoData disconnectEvent = makeDisconnectNotification(connectEvent.getSwitchId()); clock.adjust(Duration.ofSeconds(1)); subject.handleSwitchStatusNotification(disconnectEvent, REGION_A); verify(carrier).regionUpdateNotification( eq(new RegionMappingSet(disconnectEvent.getSwitchId(), REGION_B, subject.isReadWriteMode()))); reset(carrier); Instant failedAt = clock.adjust(Duration.ofSeconds(1)); subject.handleSwitchStatusNotification(disconnectEvent, REGION_B); Assert.assertFalse(subject.isAvailable()); Assert.assertEquals(failedAt, subject.getBecomeUnavailableAt()); verify(carrier).switchStatusUpdateNotification(eq(disconnectEvent.getSwitchId()), eq(disconnectEvent)); verify(carrier).regionUpdateNotification( eq(new RegionMappingRemove(disconnectEvent.getSwitchId(), null, subject.isReadWriteMode()))); verifyNoMoreInteractions(carrier); }