Skip to content

Commit e7ad6c7

Browse files
gjmwoodsinjectivesbigmontz
authored
4.2 teskit cherry pick (#900)
* Transaction Rollback (#887) * Implement backend driver feature list (#889) * testkit-backend: fix TestkitListDeserializer (#893) Enabling `list of maps` deserialization by adding a special case for treating this data type. The extras `nextToken` calls were removed because this was making the deserializer leaves the parent object, this way breaking the `map of lists` deserialization. Co-authored-by: Dmitriy Tverdiakov <[email protected]> Co-authored-by: Antonio Barcélos <[email protected]>
1 parent 9441e56 commit e7ad6c7

File tree

5 files changed

+161
-4
lines changed

5 files changed

+161
-4
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.requests;
20+
21+
import lombok.Getter;
22+
import lombok.NoArgsConstructor;
23+
import lombok.Setter;
24+
import neo4j.org.testkit.backend.TestkitState;
25+
import neo4j.org.testkit.backend.messages.responses.FeatureList;
26+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
27+
28+
import java.util.HashSet;
29+
import java.util.Set;
30+
31+
@Setter
32+
@Getter
33+
@NoArgsConstructor
34+
public class GetFeatures implements TestkitRequest
35+
{
36+
private static final Set<String> FEATURES = new HashSet<>();
37+
38+
@Override
39+
public TestkitResponse process( TestkitState testkitState )
40+
{
41+
return FeatureList.builder().data( FeatureList.FeatureListBody.builder().features( FEATURES ).build() ).build();
42+
}
43+
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitRequest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@
3434
@JsonSubTypes.Type( SessionBeginTransaction.class ), @JsonSubTypes.Type( TransactionCommit.class ),
3535
@JsonSubTypes.Type( SessionLastBookmarks.class ), @JsonSubTypes.Type( SessionWriteTransaction.class ),
3636
@JsonSubTypes.Type( ResolverResolutionCompleted.class ), @JsonSubTypes.Type( CheckMultiDBSupport.class ),
37-
@JsonSubTypes.Type( DomainNameResolutionCompleted.class ), @JsonSubTypes.Type( StartTest.class )
37+
@JsonSubTypes.Type( DomainNameResolutionCompleted.class ), @JsonSubTypes.Type( StartTest.class ),
38+
@JsonSubTypes.Type( TransactionRollback.class ), @JsonSubTypes.Type( GetFeatures.class )
3839
} )
3940
public interface TestkitRequest
4041
{
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.requests;
20+
21+
import lombok.Getter;
22+
import lombok.NoArgsConstructor;
23+
import lombok.Setter;
24+
import neo4j.org.testkit.backend.TestkitState;
25+
import neo4j.org.testkit.backend.messages.responses.TestkitResponse;
26+
import neo4j.org.testkit.backend.messages.responses.Transaction;
27+
28+
import java.util.Optional;
29+
30+
@Getter
31+
@NoArgsConstructor
32+
@Setter
33+
public class TransactionRollback implements TestkitRequest
34+
{
35+
private TransactionRollbackBody data;
36+
37+
@Override
38+
public TestkitResponse process( TestkitState testkitState )
39+
{
40+
return Optional.ofNullable( testkitState.getTransactions().get( data.txId ) )
41+
.map( tx ->
42+
{
43+
tx.rollback();
44+
return transaction( data.txId );
45+
} )
46+
.orElseThrow( () -> new RuntimeException( "Could not find transaction" ) );
47+
}
48+
49+
private Transaction transaction( String txId )
50+
{
51+
return Transaction.builder().data( Transaction.TransactionBody.builder().id( txId ).build() ).build();
52+
}
53+
54+
@Getter
55+
@NoArgsConstructor
56+
@Setter
57+
public static class TransactionRollbackBody
58+
{
59+
private String txId;
60+
}
61+
}

testkit-backend/src/main/java/neo4j/org/testkit/backend/messages/requests/deserializer/TestkitListDeserializer.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,12 @@
3232

3333
public class TestkitListDeserializer extends StdDeserializer<List<?>>
3434
{
35+
private final TestkitCypherParamDeserializer mapDeserializer;
3536

3637
public TestkitListDeserializer()
3738
{
3839
super( List.class );
40+
mapDeserializer = new TestkitCypherParamDeserializer();
3941
}
4042

4143
@Override
@@ -88,14 +90,17 @@ public List<?> deserialize( JsonParser p, DeserializationContext ctxt ) throws I
8890
}
8991
else
9092
{
91-
result.add( p.readValueAs( mapValueType ) );
93+
if ( paramType.equals( "CypherMap" ) ) // special recursive case for maps
94+
{
95+
result.add( mapDeserializer.deserialize( p, ctxt ) );
96+
} else {
97+
result.add( p.readValueAs( mapValueType ) );
98+
}
9299
}
93100
}
94101
}
95102
nextToken = p.nextToken();
96103
}
97-
p.nextToken();
98-
p.nextToken();
99104
return result;
100105
}
101106
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) "Neo4j"
3+
* Neo4j Sweden AB [http://neo4j.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package neo4j.org.testkit.backend.messages.responses;
20+
21+
import lombok.Builder;
22+
import lombok.Getter;
23+
import lombok.Setter;
24+
25+
import java.util.Set;
26+
27+
@Setter
28+
@Getter
29+
@Builder
30+
public class FeatureList implements TestkitResponse
31+
{
32+
private final FeatureListBody data;
33+
34+
@Override
35+
public String testkitName()
36+
{
37+
return "FeatureList";
38+
}
39+
40+
@Setter
41+
@Getter
42+
@Builder
43+
public static class FeatureListBody
44+
{
45+
private final Set<String> features;
46+
}
47+
}

0 commit comments

Comments
 (0)