use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class FileStoreIT method nonBlockingROStore.
@Test
public void nonBlockingROStore() throws Exception {
FileStore store = fileStoreBuilder(getFileStoreFolder()).withMaxFileSize(1).withMemoryMapping(false).build();
// first 1kB
store.flush();
SegmentNodeState base = store.getHead();
SegmentNodeBuilder builder = base.builder();
builder.setProperty("step", "a");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
// second 1kB
store.flush();
ReadOnlyFileStore ro = null;
try {
ro = fileStoreBuilder(getFileStoreFolder()).buildReadOnly();
assertEquals(store.getRevisions().getHead(), ro.getRevisions().getHead());
} finally {
if (ro != null) {
ro.close();
}
store.close();
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class FileStoreIT method setRevisionTest.
@Test
public void setRevisionTest() throws Exception {
try (FileStore store = fileStoreBuilder(getFileStoreFolder()).build()) {
RecordId id1 = store.getRevisions().getHead();
SegmentNodeState base = store.getHead();
SegmentNodeBuilder builder = base.builder();
builder.setProperty("step", "a");
store.getRevisions().setHead(base.getRecordId(), builder.getNodeState().getRecordId());
RecordId id2 = store.getRevisions().getHead();
store.flush();
try (ReadOnlyFileStore roStore = fileStoreBuilder(getFileStoreFolder()).buildReadOnly()) {
assertEquals(id2, roStore.getRevisions().getHead());
roStore.setRevision(id1.toString());
assertEquals(id1, roStore.getRevisions().getHead());
roStore.setRevision(id2.toString());
assertEquals(id2, roStore.getRevisions().getHead());
}
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class TarRevisionsTest method setHead.
@Test
public void setHead() throws IOException {
RecordId headId = revisions.getHead();
SegmentNodeState newRoot = addChild(reader.readNode(headId), "a");
assertTrue(revisions.setHead(headId, newRoot.getRecordId()));
store.flush();
try (JournalReader reader = createJournalReader()) {
assertTrue(reader.hasNext());
assertEquals(newRoot.getRecordId().toString10(), reader.next().getRevision());
}
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class TarRevisionsTest method concurrentSetHead.
@Test
public void concurrentSetHead() {
RecordId headId = revisions.getHead();
SegmentNodeState rootA = addChild(reader.readNode(headId), "a");
SegmentNodeState rootB = addChild(reader.readNode(headId), "a");
assertTrue(revisions.setHead(headId, rootA.getRecordId()));
assertFalse(revisions.setHead(headId, rootB.getRecordId()));
assertEquals(rootA, reader.readHeadState(revisions));
}
use of org.apache.jackrabbit.oak.segment.SegmentNodeState in project jackrabbit-oak by apache.
the class TarRevisionsTest method concurrentSetHeadFromFunction.
@Test
public void concurrentSetHeadFromFunction() throws IOException, InterruptedException, ExecutionException, TimeoutException {
ListeningExecutorService executor = listeningDecorator(newFixedThreadPool(2));
try {
ListenableFuture<Boolean> t1 = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return null != revisions.setHead(new Function<RecordId, RecordId>() {
@Nullable
@Override
public RecordId apply(RecordId headId) {
return addChild(reader.readNode(headId), "a").getRecordId();
}
});
}
});
ListenableFuture<Boolean> t2 = executor.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return null != revisions.setHead(new Function<RecordId, RecordId>() {
@Nullable
@Override
public RecordId apply(RecordId headId) {
return addChild(reader.readNode(headId), "b").getRecordId();
}
});
}
});
assertTrue(t1.get(500, MILLISECONDS));
assertTrue(t2.get(500, MILLISECONDS));
SegmentNodeState root = reader.readNode(revisions.getHead());
assertTrue(root.hasChildNode("a"));
assertTrue(root.hasChildNode("b"));
} finally {
executor.shutdown();
}
}
Aggregations