Skip to content

Commit 072d9b9

Browse files
GH-2632 - Upgrade Java driver to 5.3.1.
Fixes #2632 on 7.0.x and main with the fixed driver 5.3.1.
1 parent fe34e72 commit 072d9b9

File tree

6 files changed

+232
-3
lines changed

6 files changed

+232
-3
lines changed

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<maven.compiler.release>${java.version}</maven.compiler.release>
102102
<mockito>${mockito.version}</mockito>
103103
<mockito.version>4.4.0</mockito.version>
104-
<neo4j-java-driver.version>5.2.0</neo4j-java-driver.version>
104+
<neo4j-java-driver.version>5.3.1</neo4j-java-driver.version>
105105
<neo4j-migrations.version>1.13.1</neo4j-migrations.version>
106106
<neo4j.version>4.4.8</neo4j.version>
107107
<objenesis.version>3.0.1</objenesis.version>

src/test/java/org/springframework/data/neo4j/integration/imperative/RepositoryWithADifferentUserIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void createTestDatabase() {
4747

4848
session.run("CREATE DATABASE $db", Values.parameters("db", TEST_DATABASE_NAME)).consume();
4949
session.run("CREATE USER $user SET PASSWORD $password CHANGE NOT REQUIRED SET HOME DATABASE $database",
50-
Values.parameters("user", TEST_USER, "password", TEST_USER, "database", TEST_DATABASE_NAME))
50+
Values.parameters("user", TEST_USER, "password", TEST_USER + "_password", "database", TEST_DATABASE_NAME))
5151
.consume();
5252
session.run("GRANT ROLE publisher TO $user", Values.parameters("user", TEST_USER)).consume();
5353
session.run("GRANT IMPERSONATE ($targetUser) ON DBMS TO admin", Values.parameters("targetUser", TEST_USER))
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,157 @@
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.BeforeAll;
25+
import org.junit.jupiter.api.Test;
26+
import org.neo4j.driver.Driver;
27+
import org.neo4j.driver.GraphDatabase;
28+
import org.neo4j.driver.Query;
29+
import org.neo4j.driver.Session;
30+
import org.neo4j.driver.Transaction;
31+
import org.neo4j.driver.reactivestreams.ReactiveResult;
32+
import org.neo4j.driver.reactivestreams.ReactiveSession;
33+
import org.neo4j.driver.reactivestreams.ReactiveTransaction;
34+
import org.springframework.beans.factory.annotation.Autowired;
35+
import org.springframework.context.annotation.Bean;
36+
import org.springframework.context.annotation.Configuration;
37+
import org.springframework.data.neo4j.config.AbstractReactiveNeo4jConfig;
38+
import org.springframework.data.neo4j.repository.config.EnableReactiveNeo4jRepositories;
39+
import org.springframework.data.neo4j.test.Neo4jExtension;
40+
import org.springframework.data.neo4j.test.Neo4jIntegrationTest;
41+
import org.springframework.transaction.annotation.EnableTransactionManagement;
42+
43+
import reactor.core.publisher.Flux;
44+
import reactor.core.publisher.Mono;
45+
import reactor.test.StepVerifier;
46+
47+
/**
48+
* @author Michael J. Simons
49+
*/
50+
@Neo4jIntegrationTest
51+
class ReactiveConnectionAcquisitionIT {
52+
53+
protected static Neo4jExtension.Neo4jConnectionSupport neo4jConnectionSupport;
54+
55+
@BeforeAll
56+
protected static void setupData(@Autowired Driver driver) {
57+
try (Session session = driver.session()) {
58+
try (Transaction transaction = session.beginTransaction()) {
59+
transaction.run("MATCH (n) detach delete n");
60+
transaction.run("""
61+
CREATE (m:Movie {title: "I don't want warnings", id: randomUUID()})
62+
"""
63+
).consume();
64+
transaction.commit();
65+
}
66+
}
67+
}
68+
69+
@Test
70+
// GH-2632
71+
void connectionAcquisitionAfterErrorViaSDNTxManagerShouldWork(@Autowired MovieRepository movieRepository, @Autowired Driver driver) {
72+
UUID id = UUID.randomUUID();
73+
Flux
74+
.range(1, 5)
75+
.flatMap(i -> movieRepository.findById(id).switchIfEmpty(Mono.error(new RuntimeException())))
76+
.then()
77+
.as(StepVerifier::create)
78+
.verifyError();
79+
80+
try (Session session = driver.session()) {
81+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
82+
assertThat(aNumber).isOne();
83+
}
84+
}
85+
86+
@Test // GH-2632
87+
void connectionAcquisitionAfterErrorViaImplicitTXShouldWork(@Autowired Driver driver) {
88+
Flux
89+
.range(1, 5)
90+
.flatMap(
91+
i -> {
92+
Query query = new Query("MATCH (p:Product) WHERE p.id = $id RETURN p.title", Collections.singletonMap("id", 0));
93+
return Flux.usingWhen(
94+
Mono.fromSupplier(() -> driver.session(ReactiveSession.class)),
95+
session -> Flux.from(session.run(query))
96+
.flatMap(result -> Flux.from(result.records()))
97+
.map(record -> record.get(0).asString()),
98+
session -> Mono.fromDirect(session.close())
99+
).switchIfEmpty(Mono.error(new RuntimeException()));
100+
}
101+
)
102+
.then()
103+
.as(StepVerifier::create)
104+
.verifyError();
105+
106+
try (Session session = driver.session()) {
107+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
108+
assertThat(aNumber).isOne();
109+
}
110+
}
111+
112+
record SessionAndTx(ReactiveSession session, ReactiveTransaction tx) {
113+
}
114+
115+
@Test // GH-2632
116+
void connectionAcquisitionAfterErrorViaExplicitTXShouldWork(@Autowired Driver driver) {
117+
Flux
118+
.range(1, 5)
119+
.flatMap(
120+
i -> {
121+
Mono<SessionAndTx> f = Mono
122+
.just(driver.session(ReactiveSession.class))
123+
.flatMap(s -> Mono.fromDirect(s.beginTransaction()).map(tx -> new SessionAndTx(s, tx)));
124+
return Flux.usingWhen(f,
125+
h -> Flux.from(h.tx.run("MATCH (n) WHERE false = true RETURN n")).flatMap(ReactiveResult::records),
126+
h -> Mono.from(h.tx.commit()).then(Mono.from(h.session.close())),
127+
(h, e) -> Mono.from(h.tx.rollback()).then(Mono.from(h.session.close())),
128+
h -> Mono.from(h.tx.rollback()).then(Mono.from(h.session.close()))
129+
).switchIfEmpty(Mono.error(new RuntimeException()));
130+
}
131+
)
132+
.then()
133+
.as(StepVerifier::create)
134+
.verifyError();
135+
136+
try (Session session = driver.session()) {
137+
long aNumber = session.run("RETURN 1").single().get(0).asLong();
138+
assertThat(aNumber).isOne();
139+
}
140+
}
141+
142+
@Configuration
143+
@EnableTransactionManagement
144+
@EnableReactiveNeo4jRepositories
145+
static class Config extends AbstractReactiveNeo4jConfig {
146+
147+
@Bean
148+
public Driver driver() {
149+
var config = org.neo4j.driver.Config.builder()
150+
.withMaxConnectionPoolSize(2)
151+
.withConnectionAcquisitionTimeout(2, TimeUnit.SECONDS)
152+
.withLeakedSessionsLogging()
153+
.build();
154+
return GraphDatabase.driver(neo4jConnectionSupport.url, neo4jConnectionSupport.authToken, config);
155+
}
156+
}
157+
}

src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveRepositoryWithADifferentUserIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ static void createTestDatabase() {
4747

4848
session.run("CREATE DATABASE $db", Values.parameters("db", TEST_DATABASE_NAME)).consume();
4949
session.run("CREATE USER $user SET PASSWORD $password CHANGE NOT REQUIRED SET HOME DATABASE $database",
50-
Values.parameters("user", TEST_USER, "password", TEST_USER, "database", TEST_DATABASE_NAME))
50+
Values.parameters("user", TEST_USER, "password", TEST_USER + "_password", "database", TEST_DATABASE_NAME))
5151
.consume();
5252
session.run("GRANT ROLE publisher TO $user", Values.parameters("user", TEST_USER)).consume();
5353
session.run("GRANT IMPERSONATE ($targetUser) ON DBMS TO admin", Values.parameters("targetUser", TEST_USER))

0 commit comments

Comments
 (0)