use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class ParentAxisTest method testIterate.
@Test
public void testIterate() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(5L);
AbsAxisTest.testIAxisConventions(new ParentAxis(rtx), new long[] { 1L });
rtx.moveTo(8L);
AbsAxisTest.testIAxisConventions(new ParentAxis(rtx), new long[] { 1L });
rtx.moveTo(10L);
AbsAxisTest.testIAxisConventions(new ParentAxis(rtx), new long[] { 9L });
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class PrecedingSiblingAxisTest method testAxisConventions.
@Test
public void testAxisConventions() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(12L);
AbsAxisTest.testIAxisConventions(new PrecedingSiblingAxis(rtx), new long[] { 11L });
rtx.moveTo(5L);
AbsAxisTest.testIAxisConventions(new PrecedingSiblingAxis(rtx), new long[] { 4L });
rtx.moveTo(13L);
AbsAxisTest.testIAxisConventions(new PrecedingSiblingAxis(rtx), new long[] { 4L, 5L, 8L, 9L });
rtx.moveTo(1L);
AbsAxisTest.testIAxisConventions(new PrecedingSiblingAxis(rtx), new long[] {});
rtx.moveTo(9L);
rtx.moveToAttribute(0);
AbsAxisTest.testIAxisConventions(new PrecedingSiblingAxis(rtx), new long[] {});
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class VisitorDescendantAxisTest method testIterateVisitor.
@Test
public void testIterateVisitor() throws SirixException {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveToDocumentRoot();
AbsAxisTest.testIAxisConventions(VisitorDescendantAxis.newBuilder(rtx).build(), new long[] { 1L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(1L, 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveToDocumentRoot();
return VisitorDescendantAxis.newBuilder(rtx).build();
}
}.test();
rtx.moveTo(1L);
AbsAxisTest.testIAxisConventions(VisitorDescendantAxis.newBuilder(rtx).build(), new long[] { 4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(4L, 5L, 6L, 7L, 8L, 9L, 11L, 12L, 13L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(1L);
return VisitorDescendantAxis.newBuilder(rtx).build();
}
}.test();
rtx.moveTo(9L);
AbsAxisTest.testIAxisConventions(VisitorDescendantAxis.newBuilder(rtx).build(), new long[] { 11L, 12L });
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, ImmutableList.of(11L, 12L), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(9L);
return VisitorDescendantAxis.newBuilder(rtx).build();
}
}.test();
rtx.moveTo(13L);
AbsAxisTest.testIAxisConventions(VisitorDescendantAxis.newBuilder(rtx).build(), new long[] {});
new IteratorTester<Long>(ITERATIONS, IteratorFeature.UNMODIFIABLE, Collections.emptyList(), null) {
@Override
protected Iterator<Long> newTargetIterator() {
final XdmNodeReadTrx rtx = holder.getReader();
rtx.moveTo(13L);
return VisitorDescendantAxis.newBuilder(rtx).build();
}
}.test();
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class XdmResourceManagerTest method testRevision.
@Test
public void testRevision() {
XdmNodeReadTrx rtx = holder.getReader();
assertEquals(0L, rtx.getRevisionNumber());
try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
assertEquals(1L, wtx.getRevisionNumber());
// Commit and check.
wtx.commit();
}
try {
rtx = holder.getResourceManager().beginNodeReadTrx(Constants.UBP_ROOT_REVISION_NUMBER);
assertEquals(Constants.UBP_ROOT_REVISION_NUMBER, rtx.getRevisionNumber());
} finally {
rtx.close();
}
try (final XdmNodeReadTrx rtx2 = holder.getResourceManager().beginNodeReadTrx()) {
assertEquals(1L, rtx2.getRevisionNumber());
}
}
use of org.sirix.api.XdmNodeReadTrx in project sirix by sirixdb.
the class XdmResourceManagerTest method testFetchingOfClosestRevisionToAGivenPointInTime.
@Test
public void testFetchingOfClosestRevisionToAGivenPointInTime() throws InterruptedException {
final Instant start = Instant.now();
final Instant afterAllCommits;
final Instant afterFirstCommit;
final Instant afterSecondCommit;
try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx(TimeUnit.MILLISECONDS, 1000)) {
TimeUnit.MILLISECONDS.sleep(1100);
afterFirstCommit = Instant.now();
TimeUnit.MILLISECONDS.sleep(1100);
afterSecondCommit = Instant.now();
TimeUnit.MILLISECONDS.sleep(1100);
assertTrue(wtx.getRevisionNumber() >= 3);
afterAllCommits = Instant.now();
}
try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx(start)) {
assertEquals(0, rtx.getRevisionNumber());
}
try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx(afterFirstCommit)) {
assertEquals(1, rtx.getRevisionNumber());
}
try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx(afterSecondCommit)) {
assertEquals(2, rtx.getRevisionNumber());
}
try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx(afterAllCommits)) {
assertEquals(holder.getResourceManager().getMostRecentRevisionNumber(), rtx.getRevisionNumber());
}
}
Aggregations