Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestKit backend: add full support for temporal types #1257

Merged
Merged
Prev Previous commit
Next Next commit
Make backend handle (de-)serialization Exceptions gracefully
  • Loading branch information
robsdedude committed Jul 5, 2022
commit 1ce7a0b5f3d29a3efee6a89cf406cad33241fe8d
Original file line number Diff line number Diff line change
@@ -18,28 +18,24 @@
*/
package neo4j.org.testkit.backend.channel.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelPromise;
import neo4j.org.testkit.backend.messages.TestkitModule;
import neo4j.org.testkit.backend.messages.requests.TestkitRequest;
import neo4j.org.testkit.backend.messages.responses.BackendError;
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;

public class TestkitRequestResponseMapperHandler extends ChannelDuplexHandler {
private final ObjectMapper objectMapper = newObjectMapper();

@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
String testkitMessage = (String) msg;
TestkitRequest testkitRequest;
try {
testkitRequest = objectMapper.readValue(testkitMessage, TestkitRequest.class);
} catch (JsonProcessingException e) {
throw new RuntimeException("Failed to deserialize Testkit message", e);
}
testkitRequest = objectMapper.readValue(testkitMessage, TestkitRequest.class);
ctx.fireChannelRead(testkitRequest);
}

@@ -50,6 +46,16 @@ public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise)
ctx.writeAndFlush(responseStr, promise);
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
robsdedude marked this conversation as resolved.
Show resolved Hide resolved
TestkitResponse response = BackendError.builder()
.data(BackendError.BackendErrorBody.builder()
.msg(cause.toString())
.build())
.build();
ctx.writeAndFlush(objectMapper.writeValueAsString(response));
}

public static ObjectMapper newObjectMapper() {
ObjectMapper objectMapper = new ObjectMapper();
TestkitModule testkitModule = new TestkitModule();