@Override public void publishEvent(Object event) { if (event instanceof BrokerAvailabilityEvent) { this.availabilityEvents.add(((BrokerAvailabilityEvent) event).isBrokerAvailable()); } } }
@Override public String toString() { return "BrokerAvailabilityEvent[available=" + this.brokerAvailable + ", " + getSource() + "]"; }
private Runnable getUserRegistryTask() { BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this); this.handler.onApplicationEvent(event); ArgumentCaptor<? extends Runnable> captor = ArgumentCaptor.forClass(Runnable.class); verify(this.taskScheduler).scheduleWithFixedDelay(captor.capture(), eq(10000L)); return captor.getValue(); }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { if (event.isBrokerAvailable()) { long delay = getRegistryExpirationPeriod() / 2; this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(this.schedulerTask, delay); } else { ScheduledFuture<?> future = this.scheduledFuture; if (future != null ){ future.cancel(true); this.scheduledFuture = null; } } }
@Override public String toString() { return "BrokerAvailabilityEvent[available=" + this.brokerAvailable + ", " + getSource() + "]"; }
@SuppressWarnings("unchecked") @Test public void brokerUnavailableEvent() throws Exception { ScheduledFuture future = Mockito.mock(ScheduledFuture.class); when(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Long.class))).thenReturn(future); BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this); this.handler.onApplicationEvent(event); verifyNoMoreInteractions(future); event = new BrokerAvailabilityEvent(false, this); this.handler.onApplicationEvent(event); verify(future).cancel(true); }
public void expectBrokerAvailabilityEvent(boolean isBrokerAvailable) throws InterruptedException { BrokerAvailabilityEvent event = this.eventQueue.poll(20000, TimeUnit.MILLISECONDS); assertNotNull("Times out waiting for BrokerAvailabilityEvent[" + isBrokerAvailable + "]", event); assertEquals(isBrokerAvailable, event.isBrokerAvailable()); } }
@Override public String toString() { return "BrokerAvailabilityEvent[available=" + this.brokerAvailable + ", " + getSource() + "]"; }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { if (event.isBrokerAvailable()) { long delay = getRegistryExpirationPeriod() / 2; this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(this.schedulerTask, delay); } else { ScheduledFuture<?> future = this.scheduledFuture; if (future != null ){ future.cancel(true); this.scheduledFuture = null; } } }
@Override public String toString() { return "BrokerAvailabilityEvent[available=" + this.brokerAvailable + ", " + getSource() + "]"; }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { this.brokerAvailable.set(event.isBrokerAvailable()); }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { this.brokerAvailable.set(event.isBrokerAvailable()); }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { if (event.isBrokerAvailable()) { long delay = getRegistryExpirationPeriod() / 2; this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(this.schedulerTask, delay); } else { ScheduledFuture<?> future = this.scheduledFuture; if (future != null ){ future.cancel(true); this.scheduledFuture = null; } } }
@Override public void onApplicationEvent(BrokerAvailabilityEvent event) { if (event.isBrokerAvailable()) { long delay = getRegistryExpirationPeriod() / 2; this.scheduledFuture = this.scheduler.scheduleWithFixedDelay(this.schedulerTask, delay); } else { ScheduledFuture<?> future = this.scheduledFuture; if (future != null ){ future.cancel(true); this.scheduledFuture = null; } } }