Skip to content

Commit a6fa0a2

Browse files
author
haiyang.zhou
committed
test: add parallel execution mode tests
Verify that processCommand() works correctly in parallel mode (serialExecution=false): command executes synchronously on the calling thread, response is published to the session, and exceptions are handled without publishing a response. Made-with: Cursor
1 parent 0bb4732 commit a6fa0a2

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/test/java/com/github/tonivade/resp/RespServerContextTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,34 @@ public void requireCallback() {
159159
assertThrows(IllegalArgumentException.class, () -> new RespServerContext(HOST, PORT, null));
160160
}
161161

162+
@Test
163+
public void processCommandParallelMode() {
164+
var parallelContext = new RespServerContext(HOST, PORT, commands,
165+
SessionListener.nullListener(), false);
166+
Request request = new DefaultRequest(parallelContext, session, safeString("test"), Collections.emptyList());
167+
when(commands.getCommand(request.getCommand())).thenReturn(respCommand);
168+
when(respCommand.execute(request)).thenReturn(nullString());
169+
170+
parallelContext.processCommand(request);
171+
172+
verify(respCommand).execute(request);
173+
verify(session).publish(nullString());
174+
}
175+
176+
@Test
177+
public void processCommandParallelModeException() {
178+
var parallelContext = new RespServerContext(HOST, PORT, commands,
179+
SessionListener.nullListener(), false);
180+
Request request = new DefaultRequest(parallelContext, session, safeString("test"), Collections.emptyList());
181+
when(commands.getCommand(request.getCommand())).thenReturn(respCommand);
182+
doThrow(RuntimeException.class).when(respCommand).execute(request);
183+
184+
parallelContext.processCommand(request);
185+
186+
verify(respCommand).execute(request);
187+
verify(session, times(0)).publish(any());
188+
}
189+
162190
private Request newRequest(String command) {
163191
return new DefaultRequest(serverContext, session, safeString(command), Collections.emptyList());
164192
}

0 commit comments

Comments
 (0)