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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import neo4j.org.testkit.backend.holder.TransactionHolder;
import neo4j.org.testkit.backend.messages.requests.TestkitCallbackResult;
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
import org.neo4j.driver.exceptions.Neo4jException;
import org.neo4j.driver.internal.cluster.RoutingTableRegistry;
import reactor.core.publisher.Mono;

Expand Down Expand Up @@ -69,7 +68,7 @@ public class TestkitState {
private final Map<String, ReactiveTransactionHolder> transactionIdToReactiveTransactionHolder = new HashMap<>();

@Getter
private final Map<String, Neo4jException> errors = new HashMap<>();
private final Map<String, Exception> errors = new HashMap<>();

private final AtomicInteger idGenerator = new AtomicInteger(0);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.netty.channel.Channel;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.ChannelInboundHandlerAdapter;
import java.time.zone.ZoneRulesException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
import java.util.concurrent.CompletionStage;
Expand Down Expand Up @@ -86,7 +87,7 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) {
}
});
} catch (Throwable throwable) {
ctx.writeAndFlush(createErrorResponse(throwable));
exceptionCaught(ctx, throwable);
}
});
}
Expand All @@ -102,6 +103,11 @@ private static CompletionStage<TestkitResponse> wrapSyncRequest(
return result;
}

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
ctx.writeAndFlush(createErrorResponse(cause));
}

private TestkitResponse createErrorResponse(Throwable throwable) {
if (throwable instanceof CompletionException) {
throwable = throwable.getCause();
Expand All @@ -120,8 +126,10 @@ private TestkitResponse createErrorResponse(Throwable throwable) {
.build();
} else if (isConnectionPoolClosedException(throwable)
|| throwable instanceof UntrustedServerException
|| throwable instanceof NoSuchRecordException) {
|| throwable instanceof NoSuchRecordException
|| throwable instanceof ZoneRulesException) {
String id = testkitState.newId();
testkitState.getErrors().put(id, (Exception) throwable);
return DriverError.builder()
.data(DriverError.DriverErrorBody.builder()
.id(id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
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;
Expand All @@ -32,14 +31,10 @@ 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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,33 +19,60 @@
package neo4j.org.testkit.backend.messages;

import com.fasterxml.jackson.databind.module.SimpleModule;
import java.time.ZonedDateTime;
import java.time.LocalDate;
import java.util.List;
import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherDateDeserializer;
import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherDateTimeDeserializer;
import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherDurationDeserializer;
import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitCypherTimeDeserializer;
import neo4j.org.testkit.backend.messages.requests.deserializer.TestkitListDeserializer;
import neo4j.org.testkit.backend.messages.requests.deserializer.types.CypherDateTime;
import neo4j.org.testkit.backend.messages.requests.deserializer.types.CypherTime;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitDateTimeValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitDateValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitDurationValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitListValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitLocalDateTimeValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitLocalTimeValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitMapValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitNodeValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitPathValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRecordSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitRelationshipValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitTimeValueSerializer;
import neo4j.org.testkit.backend.messages.responses.serializer.TestkitValueSerializer;
import org.neo4j.driver.Record;
import org.neo4j.driver.Value;
import org.neo4j.driver.internal.value.DateTimeValue;
import org.neo4j.driver.internal.value.DateValue;
import org.neo4j.driver.internal.value.DurationValue;
import org.neo4j.driver.internal.value.ListValue;
import org.neo4j.driver.internal.value.LocalDateTimeValue;
import org.neo4j.driver.internal.value.LocalTimeValue;
import org.neo4j.driver.internal.value.MapValue;
import org.neo4j.driver.internal.value.NodeValue;
import org.neo4j.driver.internal.value.PathValue;
import org.neo4j.driver.internal.value.RelationshipValue;
import org.neo4j.driver.internal.value.TimeValue;
import org.neo4j.driver.types.IsoDuration;

public class TestkitModule extends SimpleModule {
public TestkitModule() {
this.addDeserializer(List.class, new TestkitListDeserializer());
this.addDeserializer(ZonedDateTime.class, new TestkitCypherDateTimeDeserializer());
this.addDeserializer(CypherDateTime.class, new TestkitCypherDateTimeDeserializer());
this.addDeserializer(CypherTime.class, new TestkitCypherTimeDeserializer());
this.addDeserializer(IsoDuration.class, new TestkitCypherDurationDeserializer());
this.addDeserializer(LocalDate.class, new TestkitCypherDateDeserializer());

this.addSerializer(Value.class, new TestkitValueSerializer());
this.addSerializer(NodeValue.class, new TestkitNodeValueSerializer());
this.addSerializer(ListValue.class, new TestkitListValueSerializer());
this.addSerializer(DateTimeValue.class, new TestkitDateTimeValueSerializer());
this.addSerializer(DateValue.class, new TestkitDateValueSerializer());
this.addSerializer(DurationValue.class, new TestkitDurationValueSerializer());
this.addSerializer(LocalDateTimeValue.class, new TestkitLocalDateTimeValueSerializer());
this.addSerializer(LocalTimeValue.class, new TestkitLocalTimeValueSerializer());
this.addSerializer(TimeValue.class, new TestkitTimeValueSerializer());
this.addSerializer(Record.class, new TestkitRecordSerializer());
this.addSerializer(MapValue.class, new TestkitMapValueSerializer());
this.addSerializer(PathValue.class, new TestkitPathValueSerializer());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import java.util.concurrent.ExecutionException;
import lombok.Getter;
import lombok.Setter;
import neo4j.org.testkit.backend.FrontendError;
import neo4j.org.testkit.backend.ReactiveTransactionContextAdapter;
import neo4j.org.testkit.backend.TestkitState;
import neo4j.org.testkit.backend.holder.AsyncTransactionHolder;
Expand All @@ -38,7 +37,6 @@
import org.neo4j.driver.TransactionWork;
import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.async.AsyncTransactionWork;
import org.neo4j.driver.exceptions.Neo4jException;
import org.neo4j.driver.reactive.ReactiveTransactionCallback;
import org.neo4j.driver.reactive.RxTransactionWork;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -129,11 +127,8 @@ private TransactionWork<Void> handle(TestkitState testkitState, SessionHolder se
if (workThrowable instanceof ExecutionException) {
workThrowable = workThrowable.getCause();
}
if (workThrowable instanceof Neo4jException) {
throw (Neo4jException) workThrowable;
}
if (workThrowable instanceof FrontendError) {
throw (FrontendError) workThrowable;
if (workThrowable instanceof RuntimeException) {
throw (RuntimeException) workThrowable;
}
throw new RuntimeException("Unexpected exception occurred in transaction work function", workThrowable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.concurrent.ExecutionException;
import lombok.Getter;
import lombok.Setter;
import neo4j.org.testkit.backend.FrontendError;
import neo4j.org.testkit.backend.ReactiveTransactionContextAdapter;
import neo4j.org.testkit.backend.TestkitState;
import neo4j.org.testkit.backend.holder.AsyncTransactionHolder;
Expand All @@ -39,7 +38,6 @@
import org.neo4j.driver.TransactionWork;
import org.neo4j.driver.async.AsyncSession;
import org.neo4j.driver.async.AsyncTransactionWork;
import org.neo4j.driver.exceptions.Neo4jException;
import org.neo4j.driver.reactive.ReactiveTransactionCallback;
import org.neo4j.driver.reactive.RxTransactionWork;
import org.reactivestreams.Publisher;
Expand Down Expand Up @@ -130,11 +128,8 @@ private TransactionWork<Void> handle(TestkitState testkitState, SessionHolder se
if (workThrowable instanceof ExecutionException) {
workThrowable = workThrowable.getCause();
}
if (workThrowable instanceof Neo4jException) {
throw (Neo4jException) workThrowable;
}
if (workThrowable instanceof FrontendError) {
throw (FrontendError) workThrowable;
if (workThrowable instanceof RuntimeException) {
throw (RuntimeException) workThrowable;
}
throw new RuntimeException("Unexpected exception occurred in transaction work function", workThrowable);
}
Expand Down
Loading