Search in sources :

Example 46 with RevisionData

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);
}
Also used : RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Example 47 with RevisionData

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));
}
Also used : RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Example 48 with RevisionData

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);
}
Also used : RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Example 49 with RevisionData

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));
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) ImmutableList(com.google.common.collect.ImmutableList) Collection(java.util.Collection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) CountDownLatch(java.util.concurrent.CountDownLatch) RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Example 50 with RevisionData

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);
}
Also used : RevisionData(com.b2international.index.revision.RevisionFixtures.RevisionData) Test(org.junit.Test)

Aggregations

RevisionData (com.b2international.index.revision.RevisionFixtures.RevisionData)52 Test (org.junit.Test)52 ComponentRevisionData (com.b2international.index.revision.RevisionFixtures.ComponentRevisionData)13 ContainerRevisionData (com.b2international.index.revision.RevisionFixtures.ContainerRevisionData)13 Ignore (org.junit.Ignore)6 Expression (com.b2international.index.query.Expression)2 ImmutableList (com.google.common.collect.ImmutableList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 TimeUnit (java.util.concurrent.TimeUnit)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertTrue (org.junit.Assert.assertTrue)2