Skip to content

Commit 5127b6f

Browse files
committed
GH-2191 - Add failing test.
1 parent b56f8e8 commit 5127b6f

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

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

+34
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import static org.assertj.core.api.Assertions.assertThat;
1919
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
2020

21+
import java.util.ArrayList;
2122
import java.util.Arrays;
2223
import java.util.Collections;
2324
import java.util.List;
@@ -307,6 +308,39 @@ void shouldDoThings(@Autowired VersionedThingRepository repository) {
307308
}
308309
}
309310

311+
@Test // GH-2191
312+
void shouldNotTraverseToBidiRelatedThingsWithOldVersion(@Autowired VersionedThingRepository repository) {
313+
VersionedThing thing1 = new VersionedThing("Thing1");
314+
VersionedThing thing2 = new VersionedThing("Thing2");
315+
VersionedThing thing3 = new VersionedThing("Thing3");
316+
VersionedThing thing4 = new VersionedThing("Thing4");
317+
318+
List<VersionedThing> thing1Relationships = new ArrayList<>();
319+
thing1Relationships.add(thing2);
320+
thing1Relationships.add(thing3);
321+
thing1Relationships.add(thing4);
322+
thing1.setOtherVersionedThings(thing1Relationships);
323+
repository.save(thing1);
324+
// Initially creates:
325+
// Thing1-[:HAS]->Thing2
326+
// Thing1-[:HAS]->Thing3
327+
// Thing1-[:HAS]->Thing4
328+
329+
thing1 = repository.findById(thing1.getId()).get();
330+
thing3 = repository.findById(thing3.getId()).get();
331+
thing3.setOtherVersionedThings(Collections.singletonList(thing1));
332+
repository.save(thing3);
333+
// adds
334+
// Thing3-[:HAS]->Thing1
335+
336+
try (Session session = driver.session()) {
337+
Long relationshipCount = session
338+
.run("MATCH (:VersionedThing)-[r:HAS]->(:VersionedThing) return count(r) as relationshipCount")
339+
.single().get("relationshipCount").asLong();
340+
assertThat(relationshipCount).isEqualTo(4);
341+
}
342+
}
343+
310344
interface VersionedThingRepository extends Neo4jRepository<VersionedThing, Long> {}
311345

312346
interface VersionedThingWithAssignedIdRepository extends Neo4jRepository<VersionedThingWithAssignedId, Long> {}

0 commit comments

Comments
 (0)