Search in sources :

Example 91 with XdmNodeReadTrx

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 });
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 92 with XdmNodeReadTrx

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[] {});
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 93 with XdmNodeReadTrx

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();
}
Also used : XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Iterator(java.util.Iterator) Test(org.junit.Test)

Example 94 with XdmNodeReadTrx

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());
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 95 with XdmNodeReadTrx

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());
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Instant(java.time.Instant) Test(org.junit.Test)

Aggregations

XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)150 Test (org.junit.Test)93 XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)48 QNm (org.brackit.xquery.atomic.QNm)20 DescendantAxis (org.sirix.axis.DescendantAxis)17 Iterator (java.util.Iterator)16 ResourceManager (org.sirix.api.ResourceManager)14 Axis (org.sirix.api.Axis)13 DBNode (org.sirix.xquery.node.DBNode)12 QueryException (org.brackit.xquery.QueryException)11 FilterAxis (org.sirix.axis.filter.FilterAxis)11 IndexController (org.sirix.access.IndexController)10 IndexDef (org.sirix.index.IndexDef)10 Item (org.brackit.xquery.xdm.Item)7 Database (org.sirix.api.Database)7 SirixException (org.sirix.exception.SirixException)6 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 Path (java.nio.file.Path)4 AbsAxisTest (org.sirix.axis.AbsAxisTest)4