Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,21 @@ public void init() {
Mockito.when(this.queueB.getMaxNumberOfMessages()).thenReturn(20);
Mockito.when(this.queueB.getWaitTimeSeconds()).thenReturn(10);

Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);

Mockito.when(this.provider.getSqsQueue(UUID_B)).thenReturn(this.queueB);

this.scheduler = new SQSQueueMonitorSchedulerImpl(this.executor, this.provider, this.factory);
}

@Test
public void shouldNotThrowIfUnregisterNullListener() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
assertThat(this.scheduler.unregister(null)).isFalse();
}

@Test
public void shouldNotThrowIfUnregisterUnknownListener() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
final SQSQueueListener listener = Mockito.mock(SQSQueueListener.class);
Mockito.when(listener.getQueueUuid()).thenReturn("unknown");

Expand All @@ -100,6 +102,7 @@ public void shouldNotThrowIfUnregisterUnknownListener() {

@Test
public void shouldStartMonitorForFirstListener() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
final boolean result = this.scheduler.register(this.listenerA1);

assertThat(result).isTrue();
Expand All @@ -110,6 +113,7 @@ public void shouldStartMonitorForFirstListener() {

@Test
public void shouldUseSingleMonitorInstancePerQueue() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A);
Mockito.verify(this.factory).createMonitor(this.executor, this.queueA);
Expand All @@ -125,6 +129,7 @@ public void shouldUseSingleMonitorInstancePerQueue() {

@Test
public void shouldUseSeparateMonitorInstanceForEachQueue() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A);
Mockito.verify(this.factory).createMonitor(this.executor, this.queueA);
Expand All @@ -141,6 +146,7 @@ public void shouldUseSeparateMonitorInstanceForEachQueue() {

@Test
public void shouldReuseMonitorInstaceForListenerOfSameQueue() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
this.scheduler.register(this.listenerB1);
Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A);
Expand All @@ -162,6 +168,7 @@ public void shouldReuseMonitorInstaceForListenerOfSameQueue() {

@Test
public void shouldNotCreateMonitorForUnknownQueue() {
Mockito.when(this.provider.getSqsQueue("unknown")).thenReturn(null);
final SQSQueueListener listener = Mockito.mock(SQSQueueListener.class);
Mockito.when(listener.getQueueUuid()).thenReturn("unknown");

Expand All @@ -174,6 +181,7 @@ public void shouldNotCreateMonitorForUnknownQueue() {

@Test
public void shouldCreateNewMonitorAfterUnregisterLast() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
this.scheduler.unregister(this.listenerA1);
Mockito.verify(this.provider, times(1)).getSqsQueue(UUID_A);
Expand All @@ -191,6 +199,7 @@ public void shouldCreateNewMonitorAfterUnregisterLast() {

@Test
public void shouldNotCreateNewMonitorIfMoreListenersOnUnregister() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
this.scheduler.register(this.listenerA2);
this.scheduler.unregister(this.listenerA1);
Expand All @@ -208,6 +217,7 @@ public void shouldNotCreateNewMonitorIfMoreListenersOnUnregister() {

@Test
public void shouldDoNothingOnConfigurationChangedIfUnchanged() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
this.scheduler.register(this.listenerB1);
Mockito.verify(this.factory).createMonitor(this.executor, this.queueA);
Expand All @@ -228,6 +238,7 @@ public void shouldDoNothingOnConfigurationChangedIfUnchanged() {

@Test
public void shouldStartNewMonitorOnConfigurationChangedIfChanged() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
final SQSQueue queueA_ = Mockito.mock(SQSQueue.class);
final SQSQueueMonitor monitorA_ = Mockito.mock(SQSQueueMonitor.class);
this.scheduler.register(this.listenerA1);
Expand All @@ -251,6 +262,7 @@ public void shouldStartNewMonitorOnConfigurationChangedIfChanged() {

@Test
public void shouldDoNothingOnConfigurationChangedIfPropertiesEqual() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
final SQSQueue queueA_ = Mockito.mock(SQSQueue.class);
final SQSQueueMonitor monitorA_ = Mockito.mock(SQSQueueMonitor.class);
this.scheduler.register(this.listenerA1);
Expand All @@ -276,6 +288,7 @@ public void shouldDoNothingOnConfigurationChangedIfPropertiesEqual() {

@Test
public void shouldStopMonitorOnConfigurationChangedIfQueueRemoved() {
Mockito.when(this.provider.getSqsQueue(UUID_A)).thenReturn(this.queueA);
this.scheduler.register(this.listenerA1);
this.scheduler.register(this.listenerB1);
Mockito.verify(this.factory).createMonitor(this.executor, this.queueA);
Expand Down