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