use of com.b2international.index.revision.RevisionFixtures.RevisionData in project snow-owl by b2ihealthcare.
the class RevisionTransactionalityTest method tx1UpdateAndTx2UpdateOnSameDocumentShouldInvalidateThePreviousRevisionOnBothSegments.
@Test
public void tx1UpdateAndTx2UpdateOnSameDocumentShouldInvalidateThePreviousRevisionOnBothSegments() throws Exception {
// store the initial revision on segment 0
final RevisionData data = new RevisionData(STORAGE_KEY1, "field1", "field2");
indexRevision(MAIN, data);
// create MAIN/a, which will create two new segments, 1 for 'a' and 2 for 'MAIN'
createBranch(MAIN, "a");
final long mainCommitTime = currentTime();
final long childCommitTime = currentTime();
final RevisionIndex index = index();
StagingArea mainCommit = index.prepareCommit(MAIN);
StagingArea childCommit = index.prepareCommit("MAIN/a");
mainCommit.stageNew(new RevisionData(STORAGE_KEY1, "field1ChangedOnMAIN", "field2"));
childCommit.stageNew(new RevisionData(STORAGE_KEY1, "field1", "field2ChangedOnChild"));
mainCommit.commit(mainCommitTime, UUID.randomUUID().toString(), "Commit on MAIN");
childCommit.commit(childCommitTime, UUID.randomUUID().toString(), "Commit on MAIN/a");
// after both tx commit query the branches for the latest revision
final RevisionData childRevision = getRevision("MAIN/a", RevisionData.class, STORAGE_KEY1);
final RevisionData mainRevision = getRevision(MAIN, RevisionData.class, STORAGE_KEY1);
final RevisionData expectedOnChild = new RevisionData(STORAGE_KEY1, "field1", "field2ChangedOnChild");
final RevisionData expectedOnMain = new RevisionData(STORAGE_KEY1, "field1ChangedOnMAIN", "field2");
assertDocEquals(expectedOnChild, childRevision);
assertDocEquals(expectedOnMain, mainRevision);
// assert that mainRevision has segment ID equal to 2, while childRevision has segment ID equal to 1
// assertEquals(1, childRevision.getSegmentId());
// assertEquals(2, mainRevision.getSegmentId());
// assert that the previous revision of the document has replacedIns set for both segment 1 and 2
// final Data replacedRevision = rawIndex().read(new IndexRead<Data>() {
// @Override
// public Data execute(DocSearcher index) throws IOException {
// final Hits<Data> hits = index.search(Query.select(Data.class)
// // only a single revision exists in segment 0
// .where(Expressions.match(Revision.SEGMENT_ID, 0))
// .limit(2) // query two items so getOnlyElement will throw exception in case of invalid query
// .build());
// return Iterables.getOnlyElement(hits);
// }
// });
// assertThat(replacedRevision.getReplacedIns()).containsOnly(1, 2);
}
use of com.b2international.index.revision.RevisionFixtures.RevisionData in project snow-owl by b2ihealthcare.
the class SingleDocumentRevisionIndexTest method indexRevision.
@Test
public void indexRevision() throws Exception {
final RevisionData data = new RevisionData(STORAGE_KEY1, "field1", "field2");
indexRevision(MAIN, data);
assertEquals(data, getRevision(MAIN, RevisionData.class, STORAGE_KEY1));
}
use of com.b2international.index.revision.RevisionFixtures.RevisionData in project snow-owl by b2ihealthcare.
the class SingleDocumentRevisionIndexTest method searchEmptyIndexShouldReturnNullRevision.
@Test
public void searchEmptyIndexShouldReturnNullRevision() throws Exception {
final RevisionData revision = getRevision(MAIN, RevisionData.class, STORAGE_KEY1);
assertNull(revision);
}
use of com.b2international.index.revision.RevisionFixtures.RevisionData in project snow-owl by b2ihealthcare.
the class HookTest method postCommitHook.
@Test
public void postCommitHook() throws Exception {
CountDownLatch latch = new CountDownLatch(1);
withHook((Hooks.PostCommitHook) commit -> {
assertEquals(1, commit.getDetailsByObject(STORAGE_KEY1).size());
latch.countDown();
});
commit(MAIN, Collections.singleton(new RevisionData(STORAGE_KEY1, "field1", "field2")));
assertTrue(latch.await(1, TimeUnit.SECONDS));
}
use of com.b2international.index.revision.RevisionFixtures.RevisionData in project snow-owl by b2ihealthcare.
the class BranchBaseQueryTest method readBaseOfBranchWithChangedComponents.
@Test
public void readBaseOfBranchWithChangedComponents() throws Exception {
final RevisionData data = new RevisionData(STORAGE_KEY1, "field1", "field2");
indexRevision(MAIN, data);
final String branch = createBranch(MAIN, "a");
indexRevision(branch, new RevisionData(STORAGE_KEY1, "field1Changed", "field2Changed"));
final Iterable<RevisionData> hits = search(branch + RevisionIndex.BASE_REF_CHAR, Query.select(RevisionData.class).where(Expressions.matchAll()).build());
assertThat(hits).containsOnly(data);
}
Aggregations