forked from lbovet/vertx-redisques
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement suggestions from code review.
Create a test in the different way. remove unnecessary code and imports Rollback private declarations
- Loading branch information
almeidast
committed
Sep 19, 2024
1 parent
f64f24d
commit 8ad5738
Showing
8 changed files
with
104 additions
and
243 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/test/java/org/swisspush/redisques/DequeueStatisticCollectorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package org.swisspush.redisques; | ||
|
||
import io.vertx.core.Future; | ||
import io.vertx.core.Vertx; | ||
import io.vertx.core.shareddata.AsyncMap; | ||
import io.vertx.core.shareddata.SharedData; | ||
import io.vertx.ext.unit.Async; | ||
import io.vertx.ext.unit.TestContext; | ||
import io.vertx.ext.unit.junit.VertxUnitRunner; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.swisspush.redisques.util.DequeueStatistic; | ||
import org.swisspush.redisques.util.DequeueStatisticCollector; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@RunWith(VertxUnitRunner.class) | ||
public class DequeueStatisticCollectorTest { | ||
|
||
private Vertx vertx; | ||
private SharedData sharedData; | ||
private AsyncMap<String, DequeueStatistic> asyncMap; | ||
private DequeueStatisticCollector dequeueStatisticCollectorEnabled; | ||
private DequeueStatisticCollector dequeueStatisticCollectorDisabled; | ||
|
||
@Before | ||
public void setUp() { | ||
vertx = mock(Vertx.class); | ||
sharedData = mock(SharedData.class); | ||
asyncMap = mock(AsyncMap.class); | ||
|
||
doAnswer(invocation -> { | ||
io.vertx.core.Handler<io.vertx.core.AsyncResult<AsyncMap<String, DequeueStatistic>>> handler = invocation.getArgument(1); | ||
handler.handle(Future.succeededFuture(asyncMap)); | ||
return null; | ||
}).when(sharedData).getAsyncMap(anyString(), any()); | ||
|
||
when(vertx.sharedData()).thenReturn(sharedData); | ||
|
||
// Set up the enabled and disabled DequeueStatisticCollector | ||
dequeueStatisticCollectorEnabled = new DequeueStatisticCollector(vertx, true); | ||
dequeueStatisticCollectorDisabled = new DequeueStatisticCollector(vertx, false); | ||
} | ||
|
||
@Test | ||
public void testGetAllDequeueStatisticsEnabled(TestContext context) { | ||
// Mocking asyncMap.entries() to return a non-empty map | ||
Map<String, DequeueStatistic> dequeueStats = new HashMap<>(); | ||
dequeueStats.put("queue1", new DequeueStatistic()); | ||
when(asyncMap.entries()).thenReturn(Future.succeededFuture(dequeueStats)); | ||
|
||
// Test for when dequeue statistics are enabled | ||
Async async = context.async(); | ||
dequeueStatisticCollectorEnabled.getAllDequeueStatistics().onComplete(result -> { | ||
context.assertTrue(result.succeeded()); | ||
context.assertEquals(1, result.result().size()); | ||
async.complete(); | ||
}); | ||
|
||
// Verify that sharedData and asyncMap were used correctly | ||
verify(sharedData, times(1)).getAsyncMap(anyString(), any()); | ||
verify(asyncMap, times(1)).entries(); | ||
} | ||
|
||
@Test | ||
public void testGetAllDequeueStatisticsDisabled(TestContext context) { | ||
// Test for when dequeue statistics are disabled | ||
Async async = context.async(); | ||
dequeueStatisticCollectorDisabled.getAllDequeueStatistics().onComplete(result -> { | ||
context.assertTrue(result.succeeded()); | ||
context.assertTrue(result.result().isEmpty()); | ||
async.complete(); | ||
}); | ||
|
||
// Verify that sharedData and asyncMap were NOT used | ||
verify(sharedData, never()).getAsyncMap(anyString(), any()); | ||
verify(asyncMap, never()).entries(); | ||
} | ||
} |
Oops, something went wrong.