Skip to content

Commit 47462e0

Browse files
authored
JCR-5229: LockedWrapperTest.testSequenceWithSessionRefresh() may fail due to race conditions (#338)
Added synchronization.
1 parent d855181 commit 47462e0

1 file changed

Lines changed: 16 additions & 13 deletions

File tree

jackrabbit-core/src/test/java/org/apache/jackrabbit/core/LockedWrapperTest.java

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -305,22 +305,25 @@ public Long call() throws RepositoryException, InterruptedException {
305305
}
306306
Node n = s.getNode(counterPath);
307307

308-
long value = new LockedWrapper<Long>() {
308+
long value = 0;
309+
synchronized (counter) {
310+
value = new LockedWrapper<Long>() {
309311

310-
@Override
311-
protected Long run(Node node)
312-
throws RepositoryException {
312+
@Override
313+
protected Long run(Node node)
314+
throws RepositoryException {
313315

314-
Property seqProp = node.getProperty("value");
315-
long value = seqProp.getLong();
316-
seqProp.setValue(++value);
317-
s.save();
318-
return value;
319-
}
320-
}.with(n, false);
316+
Property seqProp = node.getProperty("value");
317+
long value = seqProp.getLong();
318+
seqProp.setValue(++value);
319+
s.save();
320+
return value;
321+
}
322+
}.with(n, false);
321323

322-
// check that the sequence is ok
323-
assertEquals(counter.getAndIncrement(), value);
324+
// check that the sequence is ok
325+
assertEquals(counter.getAndIncrement(), value);
326+
}
324327

325328
// do a random wait
326329
Thread.sleep(random.nextInt(100));

0 commit comments

Comments
 (0)