forked from valkey-io/valkey-glide
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for ThreadPoolResourceAllocator
Signed-off-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
0f5862c
commit 2807e82
Showing
6 changed files
with
55 additions
and
28 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
43 changes: 43 additions & 0 deletions
43
java/client/src/test/java/glide/connectors/resources/ThreadPoolResourceAllocatorTest.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,43 @@ | ||
package glide.connectors.resources; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import static org.mockito.internal.verification.VerificationModeFactory.times; | ||
|
||
import io.netty.channel.EventLoopGroup; | ||
import java.util.function.Supplier; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class ThreadPoolResourceAllocatorTest { | ||
|
||
ThreadPoolResourceAllocator service; | ||
|
||
@Test | ||
public void getOrCreateReturnsDefault() { | ||
(new ThreadPoolResourceAllocator.ShutdownHook()).run(); | ||
|
||
ThreadPoolResource mockedThreadPool = mock(ThreadPoolResource.class); | ||
Supplier<ThreadPoolResource> threadPoolSupplier = mock(Supplier.class); | ||
when(threadPoolSupplier.get()).thenReturn(mockedThreadPool); | ||
|
||
ThreadPoolResource theResource = service.getOrCreate(threadPoolSupplier); | ||
assertEquals(mockedThreadPool, theResource); | ||
|
||
ThreadPoolResource theSameResource = service.getOrCreate(threadPoolSupplier); | ||
assertEquals(mockedThreadPool, theSameResource); | ||
|
||
// and test that the supplier isn't used any longer once the default is set | ||
Supplier<ThreadPoolResource> notUsedSupplier = mock(Supplier.class); | ||
ThreadPoolResource firstResource = service.getOrCreate(notUsedSupplier); | ||
verify(notUsedSupplier, times(0)).get(); | ||
assertEquals(mockedThreadPool, firstResource); | ||
|
||
// teardown | ||
// remove the mocked resource | ||
EventLoopGroup mockedELG = mock(EventLoopGroup.class); | ||
when(mockedThreadPool.getEventLoopGroup()).thenReturn(mockedELG); | ||
(new ThreadPoolResourceAllocator.ShutdownHook()).run(); | ||
} | ||
} |