77import static glide .api .GlideClient .buildConnectionManager ;
88import static glide .api .GlideClient .createClient ;
99import static org .junit .jupiter .api .Assertions .assertEquals ;
10- import static org .junit .jupiter .api .Assertions .assertThrows ;
1110import static org .mockito .ArgumentMatchers .any ;
1211import static org .mockito .ArgumentMatchers .eq ;
1312import static org .mockito .Mockito .mock ;
1413import static org .mockito .Mockito .mockStatic ;
1514import static org .mockito .Mockito .when ;
1615
1716import glide .api .models .configuration .GlideClientConfiguration ;
18- import glide .api .models .exceptions .ClosingException ;
1917import glide .connectors .handlers .ChannelHandler ;
2018import glide .connectors .handlers .MessageHandler ;
21- import glide .connectors .resources .ThreadPoolResource ;
22- import glide .connectors .resources .ThreadPoolResourceAllocator ;
2319import glide .managers .CommandManager ;
2420import glide .managers .ConnectionManager ;
2521import java .util .concurrent .CompletableFuture ;
26- import java .util .concurrent .ExecutionException ;
2722import lombok .SneakyThrows ;
2823import org .junit .jupiter .api .AfterEach ;
2924import org .junit .jupiter .api .BeforeEach ;
@@ -37,7 +32,6 @@ public class GlideClientCreateTest {
3732 private ConnectionManager connectionManager ;
3833 private CommandManager commandManager ;
3934 private MessageHandler messageHandler ;
40- private ThreadPoolResource threadPoolResource ;
4135
4236 @ BeforeEach
4337 public void init () {
@@ -47,19 +41,12 @@ public void init() {
4741 commandManager = mock (CommandManager .class );
4842 connectionManager = mock (ConnectionManager .class );
4943 messageHandler = mock (MessageHandler .class );
50- threadPoolResource = mock (ThreadPoolResource .class );
5144
5245 mockedClient .when (() -> buildChannelHandler (any (), any ())).thenReturn (channelHandler );
5346 mockedClient .when (() -> buildConnectionManager (channelHandler )).thenReturn (connectionManager );
5447 mockedClient .when (() -> buildCommandManager (channelHandler )).thenReturn (commandManager );
5548 mockedClient .when (() -> buildMessageHandler (any ())).thenReturn (messageHandler );
5649 mockedClient .when (() -> createClient (any (), any ())).thenCallRealMethod ();
57-
58- var threadPoolResource = ThreadPoolResourceAllocator .getOrCreate (() -> null );
59- if (threadPoolResource != null ) {
60- threadPoolResource .getEventLoopGroup ().shutdownGracefully ();
61- ThreadPoolResourceAllocator .getOrCreate (() -> null );
62- }
6350 }
6451
6552 @ AfterEach
@@ -86,46 +73,5 @@ public void createClient_with_default_config_successfully_returns_GlideClient()
8673 assertEquals (commandManager , client .commandManager );
8774 }
8875
89- @ Test
90- @ SneakyThrows
91- public void createClient_with_custom_config_successfully_returns_GlideClient () {
92- // setup
93- CompletableFuture <Void > connectToValkeyFuture = new CompletableFuture <>();
94- connectToValkeyFuture .complete (null );
95- GlideClientConfiguration config =
96- GlideClientConfiguration .builder ().threadPoolResource (threadPoolResource ).build ();
97-
98- when (connectionManager .connectToValkey (eq (config ))).thenReturn (connectToValkeyFuture );
99-
100- // exercise
101- CompletableFuture <GlideClient > result = createClient (config );
102- GlideClient client = result .get ();
103-
104- // verify
105- assertEquals (connectionManager , client .connectionManager );
106- assertEquals (commandManager , client .commandManager );
107- }
108-
109- @ SneakyThrows
110- @ Test
111- public void createClient_error_on_connection_throws_ExecutionException () {
112- // setup
113- CompletableFuture <Void > connectToValkeyFuture = new CompletableFuture <>();
114- ClosingException exception = new ClosingException ("disconnected" );
115- connectToValkeyFuture .completeExceptionally (exception );
116- GlideClientConfiguration config =
117- GlideClientConfiguration .builder ().threadPoolResource (threadPoolResource ).build ();
118-
119- when (connectionManager .connectToValkey (eq (config ))).thenReturn (connectToValkeyFuture );
120-
121- // exercise
122- CompletableFuture <GlideClient > result = createClient (config );
123-
124- ExecutionException executionException = assertThrows (ExecutionException .class , result ::get );
125-
126- // verify
127- assertEquals (exception , executionException .getCause ());
128- }
129-
13076 // TODO check message queue and subscriptionConfiguration
13177}
0 commit comments