List of usage examples for org.springframework.integration.mqtt.core ConsumerStopAction UNSUBSCRIBE_NEVER
ConsumerStopAction UNSUBSCRIBE_NEVER
To view the source code for org.springframework.integration.mqtt.core ConsumerStopAction UNSUBSCRIBE_NEVER.
Click Source Link
From source file:org.springframework.integration.mqtt.MqttAdapterTests.java
@Test public void testStopActionNever() throws Exception { final IMqttClient client = mock(IMqttClient.class); MqttPahoMessageDrivenChannelAdapter adapter = buildAdapter(client, null, ConsumerStopAction.UNSUBSCRIBE_NEVER); adapter.start();/*from w ww . j ava 2 s. com*/ adapter.stop(); verifyNotUnsubscribe(client); }
From source file:org.springframework.integration.mqtt.MqttAdapterTests.java
@Test public void testReconnect() throws Exception { final IMqttClient client = mock(IMqttClient.class); MqttPahoMessageDrivenChannelAdapter adapter = buildAdapter(client, null, ConsumerStopAction.UNSUBSCRIBE_NEVER); adapter.setRecoveryInterval(10);/* ww w . j a v a 2s.c o m*/ Log logger = spy(TestUtils.getPropertyValue(adapter, "logger", Log.class)); new DirectFieldAccessor(adapter).setPropertyValue("logger", logger); given(logger.isDebugEnabled()).willReturn(true); final AtomicInteger attemptingReconnectCount = new AtomicInteger(); willAnswer(i -> { if (attemptingReconnectCount.getAndIncrement() == 0) { adapter.connectionLost(new RuntimeException("while schedule running")); } i.callRealMethod(); return null; }).given(logger).debug("Attempting reconnect"); ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler(); taskScheduler.initialize(); adapter.setTaskScheduler(taskScheduler); adapter.start(); adapter.connectionLost(new RuntimeException("initial")); Thread.sleep(1000); // the following assertion should be equalTo, but leq to protect against a slow CI server assertThat(attemptingReconnectCount.get(), lessThanOrEqualTo(2)); adapter.stop(); taskScheduler.destroy(); }