Skip to content

Commit 12aa93f

Browse files
GH-2632 - Upgrade Java driver to 4.4.10.
Closes #2632 for 6.3 with the fixed driver 4.4.10.
1 parent 961bf87 commit 12aa93f

File tree

4 files changed

+225
-1
lines changed

4 files changed

+225
-1
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
<maven.compiler.target>${java.version}</maven.compiler.target>
103103
<mockito>${mockito.version}</mockito>
104104
<mockito.version>3.10.0</mockito.version>
105-
<neo4j-java-driver.version>4.4.9</neo4j-java-driver.version>
105+
<neo4j-java-driver.version>4.4.10</neo4j-java-driver.version>
106106
<neo4j.version>4.3.6</neo4j.version>
107107
<objenesis.version>3.0.1</objenesis.version>
108108
<project.build.docs>${project.build.directory}/docs</project.build.docs>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright 2011-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2632;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.core.schema.GeneratedValue;
21+
import org.springframework.data.neo4j.core.schema.Id;
22+
import org.springframework.data.neo4j.core.schema.Node;
23+
24+
/**
25+
* @author Michael J. Simons
26+
*/
27+
@Node
28+
public class Movie {
29+
30+
@Id @GeneratedValue
31+
private UUID id;
32+
33+
private String title;
34+
35+
public UUID getId() {
36+
return id;
37+
}
38+
39+
public String getTitle() {
40+
return title;
41+
}
42+
43+
public void setTitle(String title) {
44+
this.title = title;
45+
}
46+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright 2011-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2632;
17+
18+
import java.util.UUID;
19+
20+
import org.springframework.data.neo4j.repository.ReactiveNeo4jRepository;
21+
22+
/**
23+
* @author Michael J. Simons
24+
*/
25+
public interface MovieRepository extends ReactiveNeo4jRepository<Movie, UUID> {
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright 2011-2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.neo4j.integration.issues.gh2632;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
import java.util.Collections;
21+
import java.util.UUID;
22+
import java.util.concurrent.TimeUnit;
23+
24+
import org.junit.jupiter.api.Test;
25+
import org.neo4j.driver.Driver;
26+
import org.neo4j.driver.GraphDatabase;
27+
import org.neo4j.driver.Query;
28+
import org.neo4j.driver.Session;
29+
import org.neo4j.driver.reactive.RxResult;
30+
import org.neo4j.driver.reactive.RxSession;
31+
import org.neo4j.driver.reactive.RxTransaction;
32+
import org.springframework.beans.factory.annotation.Autowired;
33+
import org.springframework.context.annotation.Bean;
34+
import org.springframework.context.annotation.Configuration;
35+
import org.springframework.data.neo4j.config.AbstractReactiveNeo4jConfig;
36+
import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories;
37+
import org.springframework.data.neo4j.test.Neo4jExtension;
38+
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
39+
import org.springframework.transaction.annotation.EnableTransactionManagement;
40+
41+
import reactor.core.publisher.Flux;
42+
import reactor.core.publisher.Mono;
43+
import reactor.test.StepVerifier;
44+
45+
/**
46+
* @author Michael J. Simons
47+
*/
48+
@Neo4jIntegrationTest
49+
class ReactiveConnectionAcquisitionIT {
50+
51+
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport;
52+
53+
@Test // GH-2632
54+
void connectionAcquisitionAfterErrorViaSDNTxManagerShouldWork(@Autowired MovieRepository movieRepository, @Autowired Driver driver) {
55+
UUID id = UUID.randomUUID();
56+
Flux
57+
.range(1, 5)
58+
.flatMap(
59+
i -> movieRepository
60+
.findById(id)
61+
.switchIfEmpty(Mono.error(new RuntimeException()))
62+
)
63+
.then()
64+
.as(StepVerifier::create)
65+
.verifyError();
66+
67+
try (Session session = driver.session()) {
68+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
69+
assertThat(aNumber).isOne();
70+
}
71+
}
72+
73+
@Test // GH-2632
74+
void connectionAcquisitionAfterErrorViaImplicitTXShouldWork(@Autowired Driver driver) {
75+
Flux
76+
.range(1, 5)
77+
.flatMap(
78+
i -> {
79+
Query query = new Query("MATCH (p:Product) WHERE p.id = $id RETURN p.title", Collections.singletonMap("id", 0));
80+
return Flux.usingWhen(
81+
Mono.fromSupplier(driver::rxSession),
82+
session -> Mono.fromSupplier(() -> session.run(query))
83+
.flatMapMany(result -> Flux.from(result.records()))
84+
.map(record -> record.get(0).asString()),
85+
session -> Mono.fromDirect(session.close()))
86+
.switchIfEmpty(Mono.error(new RuntimeException()));
87+
}
88+
)
89+
.then()
90+
.as(StepVerifier::create)
91+
.verifyError();
92+
93+
try (Session session = driver.session()) {
94+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
95+
assertThat(aNumber).isOne();
96+
}
97+
}
98+
99+
private static class SessionAndTx {
100+
RxSession session;
101+
RxTransaction tx;
102+
103+
SessionAndTx(RxSession session, RxTransaction tx) {
104+
this.session = session;
105+
this.tx = tx;
106+
}
107+
}
108+
109+
@Test // GH-2632
110+
void connectionAcquisitionAfterErrorViaExplicitTXShouldWork(@Autowired Driver driver) {
111+
Flux
112+
.range(1, 5)
113+
.flatMap(
114+
i -> {
115+
Mono<SessionAndTx> f = Mono
116+
.just(driver.rxSession())
117+
.flatMap(s -> Mono.fromDirect(s.beginTransaction()).map(tx -> new SessionAndTx(s, tx)));
118+
return Flux.usingWhen(f,
119+
h -> Mono.fromSupplier(() -> h.tx.run("MATCH (n) WHERE false = true RETURN n")).flatMapMany(RxResult::records),
120+
h -> Mono.from(h.tx.commit()).then(Mono.from(h.session.close())),
121+
(h, e) -> Mono.from(h.tx.rollback()).then(Mono.from(h.session.close())),
122+
h -> Mono.from(h.tx.rollback()).then(Mono.from(h.session.close()))
123+
).switchIfEmpty(Mono.error(new RuntimeException()));
124+
}
125+
)
126+
.then()
127+
.as(StepVerifier::create)
128+
.verifyError();
129+
130+
try (Session session = driver.session()) {
131+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
132+
assertThat(aNumber).isOne();
133+
}
134+
}
135+
136+
@Configuration
137+
@EnableTransactionManagement
138+
@EnableReactiveNeo4jRepositories(considerNestedRepositories = true)
139+
static class Config extends AbstractReactiveNeo4jConfig {
140+
141+
@Bean
142+
public Driver driver() {
143+
org.neo4j.driver.Config config = org.neo4j.driver.Config.builder()
144+
.withMaxConnectionPoolSize(2)
145+
.withConnectionAcquisitionTimeout(20, TimeUnit.SECONDS)
146+
.withLeakedSessionsLogging()
147+
.build();
148+
return
149+
GraphDatabase.driver(neo4jConnectionSupport.url, neo4jConnectionSupport.authToken, config);
150+
}
151+
}
152+
}

0 commit comments

Comments
 (0)