Search in sources :

Example 76 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx 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)

Example 77 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class XdmResourceManagerTest method testShreddedRevision.

@Test
public void testShreddedRevision() {
    try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
        DocumentCreater.create(wtx);
        assertEquals(1L, wtx.getRevisionNumber());
        wtx.commit();
    }
    try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx()) {
        assertEquals(1L, rtx.getRevisionNumber());
        rtx.moveTo(12L);
        assertEquals("bar", rtx.getValue());
        try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx()) {
            assertEquals(2L, wtx.getRevisionNumber());
            wtx.moveTo(12L);
            wtx.setValue("bar2");
            assertEquals("bar", rtx.getValue());
            assertEquals("bar2", wtx.getValue());
            wtx.rollback();
        }
    }
    try (final XdmNodeReadTrx rtx = holder.getResourceManager().beginNodeReadTrx()) {
        assertEquals(1L, rtx.getRevisionNumber());
        rtx.moveTo(12L);
        assertEquals("bar", rtx.getValue());
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Test(org.junit.Test)

Example 78 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class XdmResourceManagerTest method testAutoCommitWithNodeThreshold.

@Test
public void testAutoCommitWithNodeThreshold() {
    // After each bunch of 5 nodes commit.
    try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx(5)) {
        DocumentCreater.create(wtx);
        wtx.commit();
        assertEquals(4, wtx.getRevisionNumber());
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Test(org.junit.Test)

Example 79 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class XdmResourceManagerTest method testAutoCommitWithScheduler.

@Test
public void testAutoCommitWithScheduler() throws InterruptedException {
    // After 500 milliseconds commit.
    try (final XdmNodeWriteTrx wtx = holder.getResourceManager().beginNodeWriteTrx(TimeUnit.MILLISECONDS, 500)) {
        TimeUnit.MILLISECONDS.sleep(1500);
        assertTrue(wtx.getRevisionNumber() >= 3);
    }
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) Test(org.junit.Test)

Example 80 with XdmNodeWriteTrx

use of org.sirix.api.XdmNodeWriteTrx in project sirix by sirixdb.

the class XdmResourceManagerTest method testExisting.

@Test
public void testExisting() {
    final Database database = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final ResourceManager resource = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeWriteTrx wtx1 = resource.beginNodeWriteTrx();
    DocumentCreater.create(wtx1);
    assertEquals(1L, wtx1.getRevisionNumber());
    wtx1.commit();
    wtx1.close();
    resource.close();
    final ResourceManager resource2 = database.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeReadTrx rtx1 = resource2.beginNodeReadTrx();
    assertEquals(1L, rtx1.getRevisionNumber());
    rtx1.moveTo(12L);
    assertEquals("bar", rtx1.getValue());
    final XdmNodeWriteTrx wtx2 = resource2.beginNodeWriteTrx();
    assertEquals(2L, wtx2.getRevisionNumber());
    wtx2.moveTo(12L);
    wtx2.setValue("bar2");
    assertEquals("bar", rtx1.getValue());
    assertEquals("bar2", wtx2.getValue());
    rtx1.close();
    wtx2.commit();
    wtx2.close();
    final Database database2 = TestHelper.getDatabase(PATHS.PATH1.getFile());
    final ResourceManager resource3 = database2.getResourceManager(new ResourceManagerConfiguration.Builder(TestHelper.RESOURCE).build());
    final XdmNodeReadTrx rtx2 = resource3.beginNodeReadTrx();
    assertEquals(2L, rtx2.getRevisionNumber());
    rtx2.moveTo(12L);
    assertEquals("bar2", rtx2.getValue());
    rtx2.close();
    resource3.close();
}
Also used : XdmNodeWriteTrx(org.sirix.api.XdmNodeWriteTrx) XdmNodeReadTrx(org.sirix.api.XdmNodeReadTrx) Database(org.sirix.api.Database) ResourceManager(org.sirix.api.ResourceManager) Test(org.junit.Test)

Aggregations

XdmNodeWriteTrx (org.sirix.api.XdmNodeWriteTrx)101 Test (org.junit.Test)61 XdmNodeReadTrx (org.sirix.api.XdmNodeReadTrx)48 ResourceManager (org.sirix.api.ResourceManager)33 Database (org.sirix.api.Database)22 QNm (org.brackit.xquery.atomic.QNm)15 SirixException (org.sirix.exception.SirixException)15 Path (java.nio.file.Path)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 DocumentException (org.brackit.xquery.xdm.DocumentException)7 DatabaseConfiguration (org.sirix.access.conf.DatabaseConfiguration)7 DescendantAxis (org.sirix.axis.DescendantAxis)7 XMLSerializerBuilder (org.sirix.service.xml.serialize.XMLSerializer.XMLSerializerBuilder)7 IOException (java.io.IOException)5 NonStructuralWrapperAxis (org.sirix.axis.NonStructuralWrapperAxis)5 SirixIOException (org.sirix.exception.SirixIOException)5 SirixDeweyID (org.sirix.node.SirixDeweyID)5 DBNode (org.sirix.xquery.node.DBNode)5 XMLEventReader (javax.xml.stream.XMLEventReader)4 QueryException (org.brackit.xquery.QueryException)4