3939import java .util .List ;
4040import java .util .Map ;
4141import java .util .Map .Entry ;
42- import java .util .concurrent .TimeUnit ;
4342
4443import org .junit .jupiter .api .BeforeEach ;
4544import org .junit .jupiter .api .Disabled ;
4948import org .mockito .MockedStatic ;
5049import org .mockito .Mockito ;
5150
52- import org .springframework .dao .InvalidDataAccessApiUsageException ;
5351import org .springframework .dao .InvalidDataAccessResourceUsageException ;
5452import org .springframework .dao .QueryTimeoutException ;
5553import org .springframework .data .redis .connection .AbstractConnectionUnitTestBase ;
6664import org .springframework .test .util .ReflectionTestUtils ;
6765
6866/**
67+ * Unit tests for {@link LettuceConnection}.
68+ *
6969 * @author Christoph Strobl
7070 * @author Mark Paluch
7171 */
@@ -101,7 +101,7 @@ public void setUp() throws InvocationTargetException, IllegalAccessException {
101101
102102 when (statefulConnectionMock .async ()).thenReturn (asyncCommandsMock );
103103 when (statefulConnectionMock .sync ()).thenReturn (commandsMock );
104- connection = new LettuceConnection (0 , clientMock );
104+ connection = new LettuceConnection (1 , clientMock );
105105 }
106106
107107 @ Nested
@@ -433,21 +433,25 @@ protected void setOutput(ByteBuffer bytes) {
433433 }
434434
435435 @ Nested
436- class ClosePipelineUnitTests {
436+ class LettucePipelineConnectionUnitTests extends BasicUnitTests {
437+
438+ @ BeforeEach
439+ public void setUp () throws InvocationTargetException , IllegalAccessException {
440+ connection .openPipeline ();
441+ }
437442
438443 @ Test // GH-3346
439444 void closePipelineShouldNotDoubleWrapTimeoutException () {
440445
446+ Command <?, ?, ?> cmd = new Command <>(CommandType .SET , new StatusOutput <>(ByteArrayCodec .INSTANCE ));
447+ AsyncCommand <?, ?, ?> future = new AsyncCommand <>(cmd );
448+
449+ when (asyncCommandsMock .set (any (byte [].class ), any (byte [].class ))).thenReturn ((RedisFuture ) future );
441450 connection .openPipeline ();
442451 connection .set ("foo" .getBytes (), "bar" .getBytes ());
443452
444- try (MockedStatic <LettuceFutures > lf = Mockito .mockStatic (LettuceFutures .class )) {
445- lf .when (() -> LettuceFutures .awaitAll (anyLong (), any (TimeUnit .class ), any ())).thenReturn (false );
446-
447- assertThatThrownBy (() -> connection .closePipeline ())
448- .isInstanceOf (RedisPipelineException .class )
449- .hasCauseInstanceOf (QueryTimeoutException .class );
450- }
453+ assertThatThrownBy (() -> connection .closePipeline ()).isInstanceOf (RedisPipelineException .class )
454+ .hasCauseInstanceOf (QueryTimeoutException .class );
451455 }
452456
453457 @ SuppressWarnings ({ "rawtypes" , "unchecked" })
@@ -463,22 +467,8 @@ void closePipelineShouldNotDoubleWrapCommandException() {
463467 connection .openPipeline ();
464468 connection .set ("foo" .getBytes (), "bar" .getBytes ());
465469
466- try (MockedStatic <LettuceFutures > lf = Mockito .mockStatic (LettuceFutures .class )) {
467- lf .when (() -> LettuceFutures .awaitAll (anyLong (), any (TimeUnit .class ), any ())).thenReturn (true );
468-
469- assertThatThrownBy (() -> connection .closePipeline ())
470- .isInstanceOf (RedisPipelineException .class )
471- .hasCauseInstanceOf (InvalidDataAccessApiUsageException .class );
472- }
473- }
474- }
475-
476- @ Nested
477- class LettucePipelineConnectionUnitTests extends BasicUnitTests {
478-
479- @ BeforeEach
480- public void setUp () throws InvocationTargetException , IllegalAccessException {
481- connection .openPipeline ();
470+ assertThatThrownBy (() -> connection .closePipeline ()).isInstanceOf (RedisPipelineException .class )
471+ .hasCauseExactlyInstanceOf (RedisException .class );
482472 }
483473
484474 @ Test // DATAREDIS-528
0 commit comments