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());
}
}
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());
}
}
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());
}
}
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);
}
}
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();
}
Aggregations