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.
Signed-off-by: Andrew Carbonetto <[email protected]>
- Loading branch information
1 parent
b7b0975
commit cb1966e
Showing
1 changed file
with
69 additions
and
0 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
java/client/src/test/java/glide/handlers/ReadHandlerTest.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,69 @@ | ||
package glide.handlers; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import glide.connectors.handlers.CallbackDispatcher; | ||
import glide.connectors.handlers.ReadHandler; | ||
import io.netty.channel.embedded.EmbeddedChannel; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import response.ResponseOuterClass; | ||
|
||
public class ReadHandlerTest { | ||
|
||
EmbeddedChannel embeddedChannel; | ||
ReadHandler readHandler; | ||
CallbackDispatcher dispatcher; | ||
|
||
@BeforeEach | ||
public void init() { | ||
dispatcher = mock(CallbackDispatcher.class); | ||
readHandler = new ReadHandler(dispatcher); | ||
embeddedChannel = new EmbeddedChannel(readHandler); | ||
} | ||
|
||
@AfterEach | ||
public void teardown() { | ||
embeddedChannel.finishAndReleaseAll(); | ||
} | ||
|
||
@Test | ||
public void readHandlerRead_testInboundProtobufMessages() { | ||
ResponseOuterClass.Response msg = ResponseOuterClass.Response.newBuilder() | ||
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK) | ||
.build(); | ||
|
||
assertTrue(embeddedChannel.writeInbound(msg, msg, msg)); | ||
assertTrue(embeddedChannel.finish()); | ||
|
||
verify(dispatcher, times(3)).completeRequest(msg); | ||
} | ||
|
||
@Test | ||
public void readHandlerRead_testInboundProtobufMessages_invalidMessage() { | ||
|
||
String invalidMsg = "Invalid"; | ||
|
||
Exception e = assertThrows(Exception.class, () -> embeddedChannel.writeInbound(invalidMsg, invalidMsg, invalidMsg)); | ||
assertEquals("Unexpected message in socket", e.getMessage()); | ||
|
||
verify(dispatcher, times(0)).completeRequest(any()); | ||
|
||
ResponseOuterClass.Response msg = ResponseOuterClass.Response.newBuilder() | ||
.setConstantResponse(ResponseOuterClass.ConstantResponse.OK) | ||
.build(); | ||
assertTrue(embeddedChannel.writeInbound(msg)); | ||
assertTrue(embeddedChannel.finish()); | ||
|
||
verify(dispatcher, times(1)).completeRequest(msg); | ||
} | ||
|
||
|
||
} |