fix: clear mqtt pending commands after startup
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
package org.dromara.mqtt;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.Tag;
|
||||
import org.springframework.boot.context.event.ApplicationReadyEvent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@Tag("dev")
|
||||
class MqttPendingCommandCleanupListenerTest {
|
||||
|
||||
@Test
|
||||
void onApplicationReadyClearsPendingCommands() {
|
||||
MqttCommandAckService service = mock(MqttCommandAckService.class);
|
||||
when(service.clearPendingCommands()).thenReturn(3);
|
||||
MqttPendingCommandCleanupListener listener = new MqttPendingCommandCleanupListener(service);
|
||||
|
||||
listener.onApplicationReady(mock(ApplicationReadyEvent.class));
|
||||
|
||||
verify(service).clearPendingCommands();
|
||||
}
|
||||
|
||||
@Test
|
||||
void onApplicationReadyDoesNotThrowWhenCleanupFails() {
|
||||
MqttCommandAckService service = mock(MqttCommandAckService.class);
|
||||
when(service.clearPendingCommands()).thenThrow(new IllegalStateException("redis unavailable"));
|
||||
MqttPendingCommandCleanupListener listener = new MqttPendingCommandCleanupListener(service);
|
||||
|
||||
assertThatCode(() -> listener.onApplicationReady(mock(ApplicationReadyEvent.class)))
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user