@Test public void failed() { DecisionMakerService w = new DecisionMakerService(carrier, 10, 5); w.failed(new SwitchId(1), 10, 0); w.failed(new SwitchId(1), 10, 1); w.failed(new SwitchId(1), 10, 11); w.failed(new SwitchId(1), 10, 12); verify(carrier, times(2)).failed(eq(new SwitchId(1)), eq(10), anyLong()); w.discovered(new SwitchId(1), 10, new SwitchId(2), 20, 20); verify(carrier).discovered(new SwitchId(1), 10, new SwitchId(2), 20, 20); reset(carrier); w.failed(new SwitchId(1), 10, 21); w.failed(new SwitchId(1), 10, 23); w.failed(new SwitchId(1), 10, 24); verify(carrier, never()).failed(any(SwitchId.class), anyInt(), anyInt()); w.failed(new SwitchId(1), 10, 31); verify(carrier).failed(new SwitchId(1), 10, 31); }
void failed(SwitchId switchId, int portNo, long currentTime) { Endpoint endpoint = Endpoint.of(switchId, portNo); if (!lastDiscovery.containsKey(endpoint)) { lastDiscovery.put(endpoint, currentTime - awaitTime); } long timeWindow = lastDiscovery.get(endpoint) + failTimeout; if (currentTime >= timeWindow) { carrier.failed(switchId, portNo, currentTime); } }
DecisionMakerService { void failed(SwitchId switchId, int portNo, long currentTime) { Endpoint endpoint = Endpoint.of(switchId, portNo); if (!lastDiscovery.containsKey(endpoint)) { lastDiscovery.put(endpoint, currentTime - awaitTime); } long timeWindow = lastDiscovery.get(endpoint) + failTimeout; if (currentTime >= timeWindow) { carrier.failed(switchId, portNo, currentTime); } } }
DecisionMakerService { void failed(SwitchId switchId, int portNo, long currentTime) { Endpoint endpoint = Endpoint.of(switchId, portNo); if (!lastDiscovery.containsKey(endpoint)) { lastDiscovery.put(endpoint, currentTime - awaitTime); } long timeWindow = lastDiscovery.get(endpoint) + failTimeout; if (currentTime >= timeWindow) { carrier.failed(switchId, portNo, currentTime); } } DecisionMakerService(IDecisionMakerCarrier carrier, int failTimeout, int awaitTime); }
DecisionMakerService { void failed(SwitchId switchId, int portNo, long currentTime) { Endpoint endpoint = Endpoint.of(switchId, portNo); if (!lastDiscovery.containsKey(endpoint)) { lastDiscovery.put(endpoint, currentTime - awaitTime); } long timeWindow = lastDiscovery.get(endpoint) + failTimeout; if (currentTime >= timeWindow) { carrier.failed(switchId, portNo, currentTime); } } DecisionMakerService(IDecisionMakerCarrier carrier, int failTimeout, int awaitTime); HashMap<Endpoint, Long> getLastDiscovery(); }
DecisionMakerService { void failed(SwitchId switchId, int portNo, long currentTime) { Endpoint endpoint = Endpoint.of(switchId, portNo); if (!lastDiscovery.containsKey(endpoint)) { lastDiscovery.put(endpoint, currentTime - awaitTime); } long timeWindow = lastDiscovery.get(endpoint) + failTimeout; if (currentTime >= timeWindow) { carrier.failed(switchId, portNo, currentTime); } } DecisionMakerService(IDecisionMakerCarrier carrier, int failTimeout, int awaitTime); HashMap<Endpoint, Long> getLastDiscovery();  }