Search in sources :

Example 1 with Branching

use of com.b2international.snowowl.core.branch.Branching in project snow-owl by b2ihealthcare.

the class SnomedBranchRequestTest method createTwoBranchesSameTimeWithSameName.

@Test
public void createTwoBranchesSameTimeWithSameName() throws Exception {
    final Branching branches = RepositoryRequests.branching();
    // try to create two branches at the same time
    final String branchName = UUID.randomUUID().toString();
    final Promise<String> first = branches.prepareCreate().setParent(branchPath).setName(branchName).build(REPOSITORY_ID).execute(bus);
    final Promise<String> second = branches.prepareCreate().setParent(branchPath).setName(branchName).build(REPOSITORY_ID).execute(bus);
    final boolean sameBaseTimestamp = Promise.all(first, second).then(input -> {
        final Branch first1 = branches.prepareGet((String) input.get(0)).build(REPOSITORY_ID).execute(bus).getSync();
        final Branch second1 = branches.prepareGet((String) input.get(1)).build(REPOSITORY_ID).execute(bus).getSync();
        return first1.baseTimestamp() == second1.baseTimestamp();
    }).fail(e -> {
        if (e instanceof AlreadyExistsException) {
            return true;
        } else {
            throw new RuntimeException(e);
        }
    }).getSync();
    // fail the test only when the API managed to create two branches with different base timestamp which should not happen
    if (!sameBaseTimestamp) {
        fail("Two branches created with the same name but different baseTimestamp");
    }
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Branching(com.b2international.snowowl.core.branch.Branching) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) SortedSet(java.util.SortedSet) RestExtensions(com.b2international.snowowl.test.commons.rest.RestExtensions) RevisionBranch(com.b2international.index.revision.RevisionBranch) Promise(com.b2international.snowowl.core.events.util.Promise) Branch(com.b2international.snowowl.core.branch.Branch) Merging(com.b2international.snowowl.core.branch.Merging) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) AlreadyExistsException(com.b2international.commons.exceptions.AlreadyExistsException) Assert.fail(org.junit.Assert.fail) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) Branching(com.b2international.snowowl.core.branch.Branching) TestMethodNameRule(com.b2international.snowowl.test.commons.TestMethodNameRule) Before(org.junit.Before) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) CommitResult(com.b2international.snowowl.core.request.CommitResult) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ImmutableMap(com.google.common.collect.ImmutableMap) Request(com.b2international.snowowl.core.events.Request) Merge(com.b2international.snowowl.core.merge.Merge) JsonSupport(com.b2international.snowowl.core.repository.JsonSupport) Test(org.junit.Test) RevisionSegment(com.b2international.index.revision.RevisionSegment) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) IEventBus(com.b2international.snowowl.eventbus.IEventBus) UUID(java.util.UUID) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Services(com.b2international.snowowl.test.commons.Services) Rule(org.junit.Rule) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) AsyncRequest(com.b2international.snowowl.core.events.AsyncRequest) User(com.b2international.snowowl.core.identity.User) SnomedIdentifiers(com.b2international.snowowl.snomed.cis.SnomedIdentifiers) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) AlreadyExistsException(com.b2international.commons.exceptions.AlreadyExistsException) RevisionBranch(com.b2international.index.revision.RevisionBranch) Branch(com.b2international.snowowl.core.branch.Branch) Test(org.junit.Test)

Example 2 with Branching

use of com.b2international.snowowl.core.branch.Branching in project snow-owl by b2ihealthcare.

the class SnomedBranchRequestTest method createBranchAndCommitToParent.

@Test
public void createBranchAndCommitToParent() throws Exception {
    final Branching branches = RepositoryRequests.branching();
    final Merging merges = RepositoryRequests.merging();
    final String branchA = UUID.randomUUID().toString();
    final String branchB = UUID.randomUUID().toString();
    final String first = branches.prepareCreate().setParent(branchPath).setName(branchA).build(REPOSITORY_ID).execute(bus).getSync();
    final SnomedDescriptionCreateRequestBuilder fsnBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("FSN " + branchA).setTypeId(Concepts.FULLY_SPECIFIED_NAME).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
    final SnomedDescriptionCreateRequestBuilder ptBuilder = SnomedRequests.prepareNewDescription().setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).setModuleId(Concepts.MODULE_ROOT).setTerm("PT " + branchA).setTypeId(Concepts.SYNONYM).setAcceptability(ImmutableMap.of(Concepts.REFSET_LANGUAGE_TYPE_UK, Acceptability.PREFERRED));
    final AsyncRequest<CommitResult> conceptRequest = SnomedRequests.prepareNewConcept().setModuleId(Concepts.MODULE_ROOT).setIdFromNamespace(SnomedIdentifiers.INT_NAMESPACE).addParent(Concepts.ROOT_CONCEPT).addDescription(fsnBuilder).addDescription(ptBuilder).build(first, RestExtensions.USER, "Created new concept");
    final CommitResult info = conceptRequest.execute(bus).getSync();
    final String conceptId = info.getResultAs(String.class);
    final String firstParentPath = BranchPathUtils.createPath(first).getParentPath();
    final Request<ServiceProvider, Merge> mergeRequest = merges.prepareCreate().setSource(first).setTarget(firstParentPath).setUserId(User.SYSTEM.getUsername()).setCommitComment("Merging changes").build(REPOSITORY_ID).getRequest();
    final String mergeJobId = JobRequests.prepareSchedule().setDescription("Merging changes").setRequest(mergeRequest).setUser(User.SYSTEM.getUsername()).buildAsync().execute(bus).getSync();
    final RemoteJobEntry mergeJobResult = JobRequests.waitForJob(bus, mergeJobId);
    final Merge merge = mergeJobResult.getResultAs(JsonSupport.getDefaultObjectMapper(), Merge.class);
    assertEquals(true, merge.getConflicts().isEmpty());
    String second = branches.prepareCreate().setParent(firstParentPath).setName(branchB).build(REPOSITORY_ID).execute(bus).getSync();
    final Branch sourceBranch = branches.prepareGet(merge.getSource()).build(REPOSITORY_ID).execute(bus).getSync();
    final Branch secondBranch = branches.prepareGet(second).build(REPOSITORY_ID).execute(bus).getSync();
    assertBranchesCreated(branchA, branchB, sourceBranch, secondBranch);
    assertBranchSegmentsValid(merge.getTarget(), sourceBranch.path(), secondBranch.path());
    // Check that the concept is visible on parent
    SnomedRequests.prepareGetConcept(conceptId).build(firstParentPath).execute(bus).getSync();
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Branching(com.b2international.snowowl.core.branch.Branching) Merge(com.b2international.snowowl.core.merge.Merge) Merging(com.b2international.snowowl.core.branch.Merging) CommitResult(com.b2international.snowowl.core.request.CommitResult) RevisionBranch(com.b2international.index.revision.RevisionBranch) Branch(com.b2international.snowowl.core.branch.Branch) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) Test(org.junit.Test)

Example 3 with Branching

use of com.b2international.snowowl.core.branch.Branching in project snow-owl by b2ihealthcare.

the class SnomedBranchRequestTest method createTwoBranchesSameTimeWithDifferentName.

@Test
public void createTwoBranchesSameTimeWithDifferentName() throws Exception {
    final Branching branches = RepositoryRequests.branching();
    // try to create two branches at the same time
    final String branchA = UUID.randomUUID().toString();
    final String branchB = UUID.randomUUID().toString();
    final Promise<String> first = branches.prepareCreate().setParent(branchPath).setName(branchA).build(REPOSITORY_ID).execute(bus);
    final Promise<String> second = branches.prepareCreate().setParent(branchPath).setName(branchB).build(REPOSITORY_ID).execute(bus);
    Promise.all(first, second).then(input -> {
        final Branch firstBranch = branches.prepareGet((String) input.get(0)).build(REPOSITORY_ID).execute(bus).getSync();
        final Branch secondBranch = branches.prepareGet((String) input.get(1)).build(REPOSITORY_ID).execute(bus).getSync();
        assertBranchesCreated(branchA, branchB, firstBranch, secondBranch);
        assertBranchSegmentsValid(branchPath, firstBranch.path(), secondBranch.path());
        return null;
    }).getSync();
}
Also used : BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Branching(com.b2international.snowowl.core.branch.Branching) BaseRevisionBranching(com.b2international.index.revision.BaseRevisionBranching) Acceptability(com.b2international.snowowl.snomed.core.domain.Acceptability) SortedSet(java.util.SortedSet) RestExtensions(com.b2international.snowowl.test.commons.rest.RestExtensions) RevisionBranch(com.b2international.index.revision.RevisionBranch) Promise(com.b2international.snowowl.core.events.util.Promise) Branch(com.b2international.snowowl.core.branch.Branch) Merging(com.b2international.snowowl.core.branch.Merging) RepositoryRequests(com.b2international.snowowl.core.repository.RepositoryRequests) Concepts(com.b2international.snowowl.snomed.common.SnomedConstants.Concepts) SnomedRequests(com.b2international.snowowl.snomed.datastore.request.SnomedRequests) AlreadyExistsException(com.b2international.commons.exceptions.AlreadyExistsException) Assert.fail(org.junit.Assert.fail) SnomedDescriptionCreateRequestBuilder(com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder) Branching(com.b2international.snowowl.core.branch.Branching) TestMethodNameRule(com.b2international.snowowl.test.commons.TestMethodNameRule) Before(org.junit.Before) BranchPathUtils(com.b2international.snowowl.core.branch.BranchPathUtils) CommitResult(com.b2international.snowowl.core.request.CommitResult) RepositoryManager(com.b2international.snowowl.core.RepositoryManager) ImmutableMap(com.google.common.collect.ImmutableMap) Request(com.b2international.snowowl.core.events.Request) Merge(com.b2international.snowowl.core.merge.Merge) JsonSupport(com.b2international.snowowl.core.repository.JsonSupport) Test(org.junit.Test) RevisionSegment(com.b2international.index.revision.RevisionSegment) RemoteJobEntry(com.b2international.snowowl.core.jobs.RemoteJobEntry) IEventBus(com.b2international.snowowl.eventbus.IEventBus) UUID(java.util.UUID) SnomedTerminologyComponentConstants(com.b2international.snowowl.snomed.common.SnomedTerminologyComponentConstants) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) Services(com.b2international.snowowl.test.commons.Services) Rule(org.junit.Rule) JobRequests(com.b2international.snowowl.core.jobs.JobRequests) ServiceProvider(com.b2international.snowowl.core.ServiceProvider) AsyncRequest(com.b2international.snowowl.core.events.AsyncRequest) User(com.b2international.snowowl.core.identity.User) SnomedIdentifiers(com.b2international.snowowl.snomed.cis.SnomedIdentifiers) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationContext(com.b2international.snowowl.core.ApplicationContext) RevisionBranch(com.b2international.index.revision.RevisionBranch) Branch(com.b2international.snowowl.core.branch.Branch) Test(org.junit.Test)

Aggregations

BaseRevisionBranching (com.b2international.index.revision.BaseRevisionBranching)3 RevisionBranch (com.b2international.index.revision.RevisionBranch)3 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)3 Branch (com.b2international.snowowl.core.branch.Branch)3 Branching (com.b2international.snowowl.core.branch.Branching)3 Merging (com.b2international.snowowl.core.branch.Merging)3 RemoteJobEntry (com.b2international.snowowl.core.jobs.RemoteJobEntry)3 Merge (com.b2international.snowowl.core.merge.Merge)3 CommitResult (com.b2international.snowowl.core.request.CommitResult)3 SnomedDescriptionCreateRequestBuilder (com.b2international.snowowl.snomed.datastore.request.SnomedDescriptionCreateRequestBuilder)3 Test (org.junit.Test)3 AlreadyExistsException (com.b2international.commons.exceptions.AlreadyExistsException)2 RevisionSegment (com.b2international.index.revision.RevisionSegment)2 ApplicationContext (com.b2international.snowowl.core.ApplicationContext)2 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)2 BranchPathUtils (com.b2international.snowowl.core.branch.BranchPathUtils)2 AsyncRequest (com.b2international.snowowl.core.events.AsyncRequest)2 Request (com.b2international.snowowl.core.events.Request)2 Promise (com.b2international.snowowl.core.events.util.Promise)2 User (com.b2international.snowowl.core.identity.User)2