diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/AccessioningService.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/AccessioningService.java index ff5acc14..bca65c28 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/AccessioningService.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/AccessioningService.java @@ -46,7 +46,7 @@ public interface AccessioningService { * @return List of wrapper objects containing the accessioned objects and their associated accessions and hashes * @throws AccessionCouldNotBeGeneratedException when accession could not be generated */ - List> getOrCreate(List messages) + List> getOrCreate(List messages, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException; /** diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningService.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningService.java index 068333f0..f09bba06 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningService.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningService.java @@ -69,9 +69,10 @@ public BasicAccessioningService(AccessionGenerator accessionGe } @Override - public List> getOrCreate(List messages) + public List> getOrCreate(List messages, + String applicationInstanceId) throws AccessionCouldNotBeGeneratedException { - return saveAccessions(accessionGenerator.generateAccessions(mapHashOfMessages(messages))); + return saveAccessions(accessionGenerator.generateAccessions(mapHashOfMessages(messages), applicationInstanceId)); } /** diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningService.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningService.java index effd3b0d..a980da26 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningService.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningService.java @@ -57,9 +57,9 @@ public DecoratedAccessioningService(AccessioningService> getOrCreate(List messages) + public List> getOrCreate(List messages, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException { - return getOrCreateDecorate(service.getOrCreate(messages)); + return getOrCreateDecorate(service.getOrCreate(messages, applicationInstanceId)); } private List> getOrCreateDecorate( diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/AccessionGenerator.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/AccessionGenerator.java index 9bfb9bec..7b946b3b 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/AccessionGenerator.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/AccessionGenerator.java @@ -40,7 +40,7 @@ public interface AccessionGenerator { * @return List of wrapper objects containing the accessioned objects and their associated accessions and hashes * @throws AccessionCouldNotBeGeneratedException when accession could not be generated */ - List> generateAccessions(Map messages) + List> generateAccessions(Map messages, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException; /** diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGenerator.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGenerator.java index 2a389715..9003f89f 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGenerator.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGenerator.java @@ -43,7 +43,7 @@ public SingleAccessionGenerator(Function generateAccessionFunc } @Override - public List> generateAccessions(Map messages) { + public List> generateAccessions(Map messages, String applicationInstanceId) { return messages.entrySet() .stream() .map(entry -> new AccessionWrapper<>(generateAccessionFunction.apply(entry.getValue()), entry.getKey(), diff --git a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/rest/controllers/BasicRestController.java b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/rest/controllers/BasicRestController.java index 519b5ef8..13759423 100644 --- a/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/rest/controllers/BasicRestController.java +++ b/accession-commons-core/src/main/java/uk/ac/ebi/ampt2d/commons/accession/rest/controllers/BasicRestController.java @@ -57,11 +57,12 @@ protected Function getModelToDTO() { return modelToDTO; } - @RequestMapping(method = RequestMethod.POST, produces = "application/json", + @RequestMapping(value = "/{applicationInstanceId}", method = RequestMethod.POST, produces = "application/json", consumes = "application/json") public List> generateAccessions( - @RequestBody @Valid List dtos) throws AccessionCouldNotBeGeneratedException { - return service.getOrCreate(dtos).stream() + @PathVariable String applicationInstanceId, @RequestBody @Valid List dtos) + throws AccessionCouldNotBeGeneratedException { + return service.getOrCreate(dtos, applicationInstanceId).stream() .map(accessionModel -> new GetOrCreateAccessionResponseDTO<>(accessionModel, modelToDTO)) .collect(Collectors.toList()); } diff --git a/accession-commons-core/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGeneratorTest.java b/accession-commons-core/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGeneratorTest.java index 6d30d648..175daf44 100644 --- a/accession-commons-core/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGeneratorTest.java +++ b/accession-commons-core/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/SingleAccessionGeneratorTest.java @@ -33,6 +33,7 @@ import static org.junit.Assert.assertEquals; public class SingleAccessionGeneratorTest { + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; private class TestUser { @@ -56,7 +57,7 @@ public void testSingleAccessionGenerator() { hashToModel.put("hash1", new TestUser("test_name1", "test_surname1")); hashToModel.put("hash2", new TestUser("test_name2", "test_surname2")); - List> accessions = generator.generateAccessions(hashToModel); + List> accessions = generator.generateAccessions(hashToModel, APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); assertAccession(0, accessions, null); } @@ -85,7 +86,7 @@ public void testOfHashAccession() { hashToModel.put("hash1", new TestUser("test_name1", "test_surname1")); hashToModel.put("hash2", new TestUser("test_name2", "test_surname2")); - List> accessions = generator.generateAccessions(hashToModel); + List> accessions = generator.generateAccessions(hashToModel, APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); assertAccession(0, accessions, new SHA1HashingFunction()); } @@ -101,7 +102,7 @@ public void testOfSHA1HashAccession() { hashToModel.put("hash1", new TestUser("test_name1", "test_surname1")); hashToModel.put("hash2", new TestUser("test_name2", "test_surname2")); - List> accessions = generator.generateAccessions(hashToModel); + List> accessions = generator.generateAccessions(hashToModel, APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); assertAccession(0, accessions, new SHA1HashingFunction()); } @@ -117,7 +118,7 @@ public void testPostSaveAction() { hashToModel.put("hash1", new TestUser("test_name1", "test_surname1")); hashToModel.put("hash2", new TestUser("test_name2", "test_surname2")); - List> modelAccessions = generator.generateAccessions(hashToModel); + List> modelAccessions = generator.generateAccessions(hashToModel, APPLICATION_INSTANCE_ID); Set accessions = modelAccessions.stream().map(AccessionWrapper::getAccession).collect(Collectors.toSet()); generator.postSave(new SaveResponse<>(accessions, new HashSet<>())); } diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java index 46f4b142..08ac4f90 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicAccessioningServiceTest.java @@ -48,7 +48,7 @@ @DataJpaTest @ContextConfiguration(classes = {TestJpaDatabaseServiceTestConfiguration.class}) public class BasicAccessioningServiceTest { - + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; @Autowired private TestRepository repository; @@ -62,7 +62,7 @@ public void accessionNotRepeatedElements() throws AccessionCouldNotBeGeneratedEx TestModel.of("service-test-1"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); } @@ -74,7 +74,7 @@ public void accessionWithRepeatedElementsReturnsUnique() throws AccessionCouldNo TestModel.of("service-test-2"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); } @@ -94,7 +94,7 @@ public void getAlreadyGeneratedAccessionsReturnsGeneratedOnly() throws Accession accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); List> accessions = accessioningService.get(Arrays.asList( TestModel.of("service-test-1"), @@ -111,13 +111,13 @@ public void accessioningMultipleTimesTheSameObjectReturnsTheSameAccession() List> accession1 = accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); TestTransaction.end(); List> accession2 = accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(1, accession2.size()); assertEquals(accession1.get(0).getAccession(), accession2.get(0).getAccession()); @@ -136,14 +136,14 @@ public void updateFailsWhenAccessionDoesNotExist() throws AccessionDoesNotExistE @Test(expected = HashAlreadyExistsException.class) public void updateFailsWhenAccessionAlreadyExists() throws AccessionDoesNotExistException, HashAlreadyExistsException, AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDeprecatedException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3"), TestModel.of("test-4"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3"), TestModel.of("test-4")), APPLICATION_INSTANCE_ID); accessioningService.update("id-service-test-3", 1, TestModel.of("test-4")); } @Test public void testUpdate() throws AccessionDoesNotExistException, HashAlreadyExistsException, AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDeprecatedException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3")), APPLICATION_INSTANCE_ID); final AccessionVersionsWrapper updatedAccession = accessioningService.update("id-service-test-3", 1, TestModel.of("test-3b")); @@ -163,7 +163,7 @@ public void testUpdate() throws AccessionDoesNotExistException, @Test public void testPatch() throws AccessionCouldNotBeGeneratedException, AccessionDeprecatedException, AccessionDoesNotExistException, AccessionMergedException, HashAlreadyExistsException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-3")), APPLICATION_INSTANCE_ID); final AccessionVersionsWrapper accession = accessioningService.patch("id-service-test-3", TestModel.of("test-3b")); assertEquals(2, accession.getModelWrappers().size()); @@ -182,7 +182,7 @@ public void testPatch() throws AccessionCouldNotBeGeneratedException, AccessionD @Test public void testGetAccessionVersion() throws AccessionCouldNotBeGeneratedException, AccessionDoesNotExistException, HashAlreadyExistsException, AccessionMergedException, AccessionDeprecatedException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-accession-version"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-accession-version")), APPLICATION_INSTANCE_ID); accessioningService.patch("id-service-test-accession-version", TestModel.of("test-accession-version-b")); final AccessionWrapper version1 = accessioningService @@ -196,7 +196,7 @@ public void testGetAccessionVersion() throws AccessionCouldNotBeGeneratedExcepti @Test public void testDeprecate() throws AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDoesNotExistException, AccessionDeprecatedException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-version"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-version")), APPLICATION_INSTANCE_ID); doDeprecateAndAssert("id-service-test-deprecate-version"); } @@ -220,7 +220,7 @@ public void testDeprecateAccessionDoesNotExist() throws AccessionCouldNotBeGener @Test(expected = AccessionDeprecatedException.class) public void testDeprecateTwice() throws AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDoesNotExistException, AccessionDeprecatedException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-version-2"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-version-2")), APPLICATION_INSTANCE_ID); accessioningService.deprecate("id-service-test-deprecate-version-2", "Reasons"); accessioningService.deprecate("id-service-test-deprecate-version-2", "Reasons"); } @@ -228,7 +228,7 @@ public void testDeprecateTwice() throws AccessionCouldNotBeGeneratedException, A @Test public void testDeprecateUpdated() throws AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDoesNotExistException, AccessionDeprecatedException, HashAlreadyExistsException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-update-version"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-update-version")), APPLICATION_INSTANCE_ID); accessioningService.update("id-service-test-deprecate-update-version", 1, TestModel.of("test-deprecate-update-version-updated!")); doDeprecateAndAssert("id-service-test-deprecate-update-version"); @@ -237,7 +237,7 @@ public void testDeprecateUpdated() throws AccessionCouldNotBeGeneratedException, @Test public void testDeprecatePatched() throws AccessionCouldNotBeGeneratedException, AccessionMergedException, AccessionDoesNotExistException, AccessionDeprecatedException, HashAlreadyExistsException { - accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-patch-version"))); + accessioningService.getOrCreate(Arrays.asList(TestModel.of("test-deprecate-patch-version")), APPLICATION_INSTANCE_ID); accessioningService.patch("id-service-test-deprecate-patch-version", TestModel.of("test-deprecate-update-version-patched!")); doDeprecateAndAssert("id-service-test-deprecate-patch-version"); diff --git a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningServiceTest.java b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningServiceTest.java index f15e7568..68cf8ec0 100644 --- a/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningServiceTest.java +++ b/accession-commons-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/DecoratedAccessioningServiceTest.java @@ -43,7 +43,7 @@ @DataJpaTest @ContextConfiguration(classes = {TestJpaDatabaseServiceTestConfiguration.class}) public class DecoratedAccessioningServiceTest { - + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; @Autowired private AccessioningService accessioningService; @@ -52,7 +52,7 @@ public void assertGetOrCreate() throws AccessionCouldNotBeGeneratedException { List> accessions = getPrefixedService().getOrCreate( Arrays.asList( TestModel.of("service-test-1") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(1, accessions.size()); assertEquals("prefix-id-service-service-test-1", accessions.get(0).getAccession()); } @@ -138,7 +138,7 @@ public void assertMerge() throws AccessionMergedException, AccessionDoesNotExist Arrays.asList( TestModel.of("service-test-1"), TestModel.of("service-test-2") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(2, accessions.size()); getPrefixedService().merge("prefix-id-service-service-test-1", "prefix-id-service-service-test-2", "reason"); } diff --git a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGenerator.java b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGenerator.java index 5daaaa85..55704ae3 100644 --- a/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGenerator.java +++ b/accession-commons-monotonic-generator-jpa/src/main/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGenerator.java @@ -45,7 +45,6 @@ public class MonotonicAccessionGenerator implements AccessionGenerator implements AccessionGenerator uncompletedBlocks = blockService .reserveUncompletedBlocksForCategoryIdAndApplicationInstanceId(categoryId, applicationInstanceId); @@ -103,12 +100,12 @@ private void recoverStateForElements(long[] committedElements) throws AccessionI blockService.save(blockManager.recoverState(committedElements)); } - public synchronized long[] generateAccessions(int numAccessionsToGenerate) + public synchronized long[] generateAccessions(int numAccessionsToGenerate, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException { checkAccessionGeneratorNotShutDown(); - recoverState(); + recoverState(applicationInstanceId); long[] accessions = new long[numAccessionsToGenerate]; - reserveNewBlocksUntilSizeIs(numAccessionsToGenerate); + reserveNewBlocksUntilSizeIs(numAccessionsToGenerate, applicationInstanceId); int i = 0; while (i < numAccessionsToGenerate) { @@ -127,7 +124,7 @@ public synchronized long[] generateAccessions(int numAccessionsToGenerate) * * @param totalAccessionsToGenerate */ - private synchronized void reserveNewBlocksUntilSizeIs(int totalAccessionsToGenerate) { + private synchronized void reserveNewBlocksUntilSizeIs(int totalAccessionsToGenerate, String applicationInstanceId) { while (!blockManager.hasAvailableAccessions(totalAccessionsToGenerate)) { ExponentialBackOff.execute(() -> reserveNewBlock(categoryId, applicationInstanceId), 10, 30); } @@ -153,10 +150,10 @@ public synchronized MonotonicRangePriorityQueue getAvailableRanges() { } @Override - public List> generateAccessions(Map messages) + public List> generateAccessions(Map messages, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException { checkAccessionGeneratorNotShutDown(); - long[] accessions = generateAccessions(messages.size()); + long[] accessions = generateAccessions(messages.size(), applicationInstanceId); int i = 0; List> accessionedModels = new ArrayList<>(); for (Map.Entry entry : messages.entrySet()) { diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java index b1276120..0ca23ba9 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningTest.java @@ -46,6 +46,8 @@ @ContextConfiguration(classes = {TestMonotonicDatabaseServiceTestConfiguration.class}) public class BasicMonotonicAccessioningTest { + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; + @Autowired private TestMonotonicRepository repository; @@ -64,7 +66,7 @@ public void testCreateAccessions() throws AccessionCouldNotBeGeneratedException TestModel.of("service-test-1"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); } @@ -88,7 +90,7 @@ public void testGetOrCreateFiltersRepeated() throws AccessionCouldNotBeGenerated TestModel.of("service-test-2"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); } @@ -112,7 +114,7 @@ public void testGetWithExistingEntries() throws AccessionCouldNotBeGeneratedExce List> accessions1 = accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(1, accessions1.size()); List> accessions2 = accessioningService.get( @@ -133,7 +135,7 @@ public void testGetByAccessionsWithExistingEntries() throws AccessionCouldNotBeG List> accessions1 = accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(1, accessions1.size()); AccessionWrapper accession2 = @@ -148,7 +150,7 @@ public void testGetOrCreateWithExistingEntries() throws AccessionCouldNotBeGener List> accessions1 = accessioningService.getOrCreate( Arrays.asList( TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(1, accessions1.size()); assertEquals(true, accessions1.get(0).isNewAccession()); TestTransaction.end(); @@ -158,7 +160,7 @@ public void testGetOrCreateWithExistingEntries() throws AccessionCouldNotBeGener TestModel.of("service-test-1"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions2.size()); accessions2.stream().forEach(wrapper -> { if (!wrapper.isNewAccession()) { diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java index 484d22b6..73913e83 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithAlternateRangesTest.java @@ -70,7 +70,7 @@ public class BasicMonotonicAccessioningWithAlternateRangesTest { public void testUnknownCategory() throws AccessionCouldNotBeGeneratedException { List> evaAccessions = getAccessioningService("unknown-category", INSTANCE_ID) - .getOrCreate(getObjectsForAccessionsInRange(1, 10)); + .getOrCreate(getObjectsForAccessionsInRange(1, 10), INSTANCE_ID); } @Test @@ -102,7 +102,7 @@ public void testRecoverState() throws AccessionCouldNotBeGeneratedException { // run recover state MonotonicAccessionGenerator generator = getGenerator(categoryId, instanceId2); - generator.generateAccessions(0); + generator.generateAccessions(0, INSTANCE_ID); // As we have already saved accessions in db from 100 to 124, the status should be // block-1 (100 to 109) : fully complete @@ -128,7 +128,7 @@ public void testAlternateRangesWithDifferentGenerators() throws AccessionCouldNo String categoryId = "eva_2"; String instanceId2 = "test-instance_2"; BasicAccessioningService accService1 = getAccessioningService(categoryId, INSTANCE_ID); - List> evaAccessions = accService1.getOrCreate(getObjectsForAccessionsInRange(1, 9)); + List> evaAccessions = accService1.getOrCreate(getObjectsForAccessionsInRange(1, 9), INSTANCE_ID); assertEquals(9, evaAccessions.size()); assertEquals(0, evaAccessions.get(0).getAccession().longValue()); assertEquals(8, evaAccessions.get(8).getAccession().longValue()); @@ -138,7 +138,7 @@ public void testAlternateRangesWithDifferentGenerators() throws AccessionCouldNo //Get another service for same category BasicAccessioningService accService2 = getAccessioningService(categoryId, INSTANCE_ID); - evaAccessions = accService2.getOrCreate(getObjectsForAccessionsInRange(11, 30)); + evaAccessions = accService2.getOrCreate(getObjectsForAccessionsInRange(11, 30), INSTANCE_ID); assertEquals(20, evaAccessions.size()); //Previous block ended here as only 9 elements were accessioned out of a blocksize of 10 assertEquals(9, evaAccessions.get(0).getAccession().longValue()); @@ -156,7 +156,7 @@ public void testAlternateRangesWithDifferentGenerators() throws AccessionCouldNo //Get another service for same category but different Instance BasicAccessioningService accService3 = getAccessioningService(categoryId, instanceId2); - evaAccessions = accService3.getOrCreate(getObjectsForAccessionsInRange(31, 39)); + evaAccessions = accService3.getOrCreate(getObjectsForAccessionsInRange(31, 39), INSTANCE_ID); assertEquals(9, evaAccessions.size()); //New Block from different instance have not jumped as still blocks are available before interleaving point assertNotEquals(80, evaAccessions.get(0).getAccession().longValue()); @@ -167,7 +167,7 @@ public void testAlternateRangesWithDifferentGenerators() throws AccessionCouldNo //Get previous uncompleted service from instance1 and create accessions BasicAccessioningService accService4 = getAccessioningService(categoryId, INSTANCE_ID); - evaAccessions = accService4.getOrCreate(getObjectsForAccessionsInRange(40, 42)); + evaAccessions = accService4.getOrCreate(getObjectsForAccessionsInRange(40, 42), INSTANCE_ID); assertEquals(3, evaAccessions.size()); assertEquals(58, evaAccessions.get(0).getAccession().longValue()); //Block ended here //New Block with 20 interval from last block made in instanceId2 @@ -195,7 +195,7 @@ public void testInitializeBlockManagerInMonotonicAccessionGenerator() throws Acc // this will run the recover state MonotonicAccessionGenerator monotonicAccessionGenerator = getGenerator(categoryId, instanceId2); - monotonicAccessionGenerator.generateAccessions(0); + monotonicAccessionGenerator.generateAccessions(0, INSTANCE_ID); // assert block gets reserved after recover state blockInDBList = getAllBlocksForCategoryId(contiguousIdBlockRepository, categoryId); @@ -229,7 +229,7 @@ private BasicAccessioningService getAccessioningService } private MonotonicAccessionGenerator getGenerator(String categoryId, String instanceId) { - return new MonotonicAccessionGenerator<>(categoryId, instanceId, contiguousIdBlockService, databaseService); + return new MonotonicAccessionGenerator<>(categoryId, contiguousIdBlockService, databaseService); } } diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java index 24e1b09a..dc5ce692 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/core/BasicMonotonicAccessioningWithInitValuesTest.java @@ -45,6 +45,7 @@ @ContextConfiguration(classes = {TestMonotonicDatabaseServiceTestConfiguration.class}) public class BasicMonotonicAccessioningWithInitValuesTest { + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; @Autowired private TestMonotonicRepository repository; @@ -63,7 +64,7 @@ public void testAccessionElements() throws AccessionCouldNotBeGeneratedException TestModel.of("service-test-1"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); accessions.stream().forEach(entry -> assertTrue(entry.getAccession() >= 100L)); @@ -88,7 +89,7 @@ public void testGetOrCreateFiltersRepeated() throws AccessionCouldNotBeGenerated TestModel.of("service-test-2"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); accessions.stream().forEach(entry -> assertTrue(entry.getAccession() >= 100L)); } @@ -140,7 +141,7 @@ public void testGetOrCreateWithExistingEntries() throws AccessionCouldNotBeGener TestModel.of("service-test-1"), TestModel.of("service-test-2"), TestModel.of("service-test-3") - )); + ), APPLICATION_INSTANCE_ID); assertEquals(3, accessions.size()); accessions.stream().forEach(entry -> assertTrue(entry.getAccession() == 0L || entry.getAccession() >= 100L)); diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGeneratorTest.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGeneratorTest.java index bd7b8ee1..fec40efc 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGeneratorTest.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/commons/accession/generators/monotonic/MonotonicAccessionGeneratorTest.java @@ -87,7 +87,7 @@ public void assertNoBlockGeneratedAtLoadIfNoneExists() throws Exception { @Test public void assertBlockGeneratedAtGenerateOperationIfNoBlockExists() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(TENTH_BLOCK_SIZE); + generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(1, repository.count()); ContiguousIdBlock block = repository.findFirstByCategoryIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(0, block.getFirstValue()); @@ -101,7 +101,7 @@ public void assertBlockNotGeneratedIfPreviousExists() throws Exception { repository.save(new ContiguousIdBlock(CATEGORY_ID, INSTANCE_ID, 0, BLOCK_SIZE)); assertEquals(1, repository.count()); MonotonicAccessionGenerator generator = new MonotonicAccessionGenerator( - CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + CATEGORY_ID, service, monotonicDBService); assertEquals(1, repository.count()); } @@ -112,18 +112,18 @@ public void assertNewBlockGeneratedInSecondInstance() throws Exception { assertEquals(0, repository.count()); MonotonicAccessionGenerator generator1 = new MonotonicAccessionGenerator( - CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + CATEGORY_ID, service, monotonicDBService); MonotonicAccessionGenerator generator2 = new MonotonicAccessionGenerator( - CATEGORY_ID, INSTANCE_2_ID, service, monotonicDBService); + CATEGORY_ID, service, monotonicDBService); - generator1.generateAccessions(TENTH_BLOCK_SIZE); + generator1.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(1, repository.count()); block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(0, block.getFirstValue()); assertEquals(BLOCK_SIZE - 1, block.getLastValue()); assertEquals(-1, block.getLastCommitted()); - generator2.generateAccessions(TENTH_BLOCK_SIZE); + generator2.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_2_ID); assertEquals(2, repository.count()); block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(BLOCK_SIZE, block.getFirstValue()); @@ -135,7 +135,7 @@ public void assertNewBlockGeneratedInSecondInstance() throws Exception { public void assertGenerateAccessions() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(TENTH_BLOCK_SIZE, accessions.length); } @@ -145,10 +145,10 @@ public void assertGenerateMoreAccessionsThanBlockSizeGeneratesTwoBlocks() throws //Generate BLOCK_SIZE accessions in BLOCK_SIZE/10 increments for (int i = 0; i < 10; i++) { - long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(i * TENTH_BLOCK_SIZE, accessions[0]); } - long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(BLOCK_SIZE, accessions[0]); assertEquals(2, repository.count()); } @@ -156,7 +156,7 @@ public void assertGenerateMoreAccessionsThanBlockSizeGeneratesTwoBlocks() throws @Test public void assertGenerateMoreAccessionsThanBlockSizeGeneratesInOneCall() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions = generator.generateAccessions(BLOCK_SIZE + (BLOCK_SIZE / 2)); + long[] accessions = generator.generateAccessions(BLOCK_SIZE + (BLOCK_SIZE / 2), INSTANCE_ID); assertEquals(2, repository.count()); } @@ -164,7 +164,7 @@ public void assertGenerateMoreAccessionsThanBlockSizeGeneratesInOneCall() throws @Test public void assertCommitModifiesLastCommitted() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.commit(accessions); @@ -175,7 +175,7 @@ public void assertCommitModifiesLastCommitted() throws Exception { @Test public void assertNotCommittingDoesNotModifyLastCommitted() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); ContiguousIdBlock block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(-1, block.getLastCommitted()); @@ -184,8 +184,8 @@ public void assertNotCommittingDoesNotModifyLastCommitted() throws Exception { @Test public void assertCommitOutOfOrderDoesNotModifyLastCommittedUntilTheSequenceIsComplete() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.commit(accessions2); @@ -202,8 +202,8 @@ public void assertCommitOutOfOrderDoesNotModifyLastCommittedUntilTheSequenceIsCo public void assertCommitOutOfOrderDoesNotModifyLastCommittedUntilTheSequenceIsCompleteMultipleBlocks() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(BLOCK_SIZE + TENTH_BLOCK_SIZE); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(BLOCK_SIZE + TENTH_BLOCK_SIZE, INSTANCE_ID); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.commit(accessions2); @@ -221,26 +221,26 @@ public void assertCommitOutOfOrderDoesNotModifyLastCommittedUntilTheSequenceIsCo @Test public void assertGenerateDoesNotReuseIds() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(TENTH_BLOCK_SIZE); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(TENTH_BLOCK_SIZE, accessions2[0]); } @Test public void assertReleaseMakesGenerateReuseIds() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.release(accessions1); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(0, accessions2[0]); } @Test public void assertReleaseSomeIdsMakesGenerateReuseReleasedIdsAndNewOnes() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(TENTH_BLOCK_SIZE); + generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.release(0, 1); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(0, accessions2[0]); assertEquals(1, accessions2[1]); assertEquals(TENTH_BLOCK_SIZE, accessions2[2]); @@ -249,11 +249,11 @@ public void assertReleaseSomeIdsMakesGenerateReuseReleasedIdsAndNewOnes() throws @Test public void assertMultipleReleaseSomeIdsMakesGenerateReuseReleasedIdsAndNewOnes() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.release(0, 1); generator.release(3, 4, 5); generator.release(8, 9, 10); - long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE); + long[] accessions2 = generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); assertEquals(0, accessions2[0]); assertEquals(1, accessions2[1]); assertEquals(3, accessions2[2]); @@ -268,7 +268,7 @@ public void assertMultipleReleaseSomeIdsMakesGenerateReuseReleasedIdsAndNewOnes( @Test public void assertMultipleReleaseAndCommitsWorks() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(BLOCK_SIZE); + generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); generator.commit(2); generator.release(0, 1); generator.release(3, 4, 5); @@ -279,7 +279,7 @@ public void assertMultipleReleaseAndCommitsWorks() throws Exception { ContiguousIdBlock block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(-1, block.getLastCommitted()); - long[] accessions2 = generator.generateAccessions(BLOCK_SIZE); + long[] accessions2 = generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); assertEquals(0, accessions2[0]); assertEquals(1, accessions2[1]); assertEquals(3, accessions2[2]); @@ -305,31 +305,31 @@ public void assertMultipleReleaseAndCommitsWorks() throws Exception { @Test public void assertRecoverNoPendingCommit() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); generator.shutDownAccessionGenerator(); // Now assume that the db layer has stored some elements and that the application has died and restarted. MonotonicAccessionGenerator generatorRecovering = - new MonotonicAccessionGenerator(CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + new MonotonicAccessionGenerator(CATEGORY_ID, service, monotonicDBService); ContiguousIdBlock block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(-1, block.getLastCommitted()); - generatorRecovering.generateAccessions(0); + generatorRecovering.generateAccessions(0, INSTANCE_ID); assertFalse(generatorRecovering.getAvailableRanges().isEmpty()); } @Test public void assertRecoverPendingCommit() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - long[] accessions1 = generator.generateAccessions(BLOCK_SIZE); + long[] accessions1 = generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); generator.commit(0, 1); generator.shutDownAccessionGenerator(); // Now assume that the db layer has stored some elements and that the application has died and restarted. MonotonicAccessionGenerator generatorRecovering = new MonotonicAccessionGenerator( - CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + CATEGORY_ID, service, monotonicDBService); ContiguousIdBlock block = findFirstByCategoryIdAndApplicationInstanceIdOrderByLastValueDesc(CATEGORY_ID); assertEquals(1, block.getLastCommitted()); - generatorRecovering.generateAccessions(0); + generatorRecovering.generateAccessions(0, INSTANCE_ID); assertEquals(1, generatorRecovering.getAvailableRanges().size()); MonotonicRange monotonicRange = generatorRecovering.getAvailableRanges().peek(); assertEquals(2, monotonicRange.getStart()); @@ -339,7 +339,7 @@ public void assertRecoverPendingCommit() throws Exception { @Test(expected = AccessionIsNotPendingException.class) public void assertReleaseAndCommitSameElement() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(BLOCK_SIZE); + generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); generator.release(2); generator.commit(2); } @@ -347,7 +347,7 @@ public void assertReleaseAndCommitSameElement() throws Exception { @Test(expected = AccessionIsNotPendingException.class) public void assertCommitAndReleaseSameElement() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(BLOCK_SIZE); + generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); generator.commit(2); generator.release(2); } @@ -355,7 +355,7 @@ public void assertCommitAndReleaseSameElement() throws Exception { @Test(expected = AccessionIsNotPendingException.class) public void releaseSomeIdsTwice() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(TENTH_BLOCK_SIZE); + generator.generateAccessions(TENTH_BLOCK_SIZE, INSTANCE_ID); generator.release(0, 1); generator.release(0, 1); } @@ -374,13 +374,13 @@ public void assertGenerateWithObjects() throws Exception { assertEquals(0, repository.count()); MonotonicAccessionGenerator generator = - new MonotonicAccessionGenerator(CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + new MonotonicAccessionGenerator(CATEGORY_ID, service, monotonicDBService); HashMap objects = new HashMap<>(); objects.put("hash1", "object2"); objects.put("hash2", "object2"); - List> generatedAccessions = generator.generateAccessions(objects); + List> generatedAccessions = generator.generateAccessions(objects, INSTANCE_ID); assertEquals(1, repository.count()); assertEquals(0L, (long) generatedAccessions.get(0).getAccession()); @@ -390,7 +390,7 @@ public void assertGenerateWithObjects() throws Exception { @Test public void postSaveAction() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGenerator(); - generator.generateAccessions(BLOCK_SIZE); + generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); Set committed = new HashSet<>(); committed.add(0L); committed.add(1L); @@ -400,7 +400,7 @@ public void postSaveAction() throws Exception { released.add(2L); released.add(5L); generator.postSave(new SaveResponse(committed, released)); - long[] accessions = generator.generateAccessions(BLOCK_SIZE); + long[] accessions = generator.generateAccessions(BLOCK_SIZE, INSTANCE_ID); assertEquals(2, accessions[0]); assertEquals(5, accessions[1]); assertEquals(BLOCK_SIZE, accessions[2]); @@ -409,13 +409,13 @@ public void postSaveAction() throws Exception { @Test public void assertReleaseInAlternateRanges() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGeneratorForCategoryHavingBlockInterval(); - long[] accessions1 = generator.generateAccessions(NUM_OF_ACCESSIONS); + long[] accessions1 = generator.generateAccessions(NUM_OF_ACCESSIONS, INSTANCE_ID); assertEquals(1, accessions1[0]); assertEquals(2, accessions1[1]); assertEquals(3, accessions1[2]); assertEquals(4, accessions1[3]); generator.release(new long[]{2, 3}); - long[] accessions2 = generator.generateAccessions(NUM_OF_ACCESSIONS); + long[] accessions2 = generator.generateAccessions(NUM_OF_ACCESSIONS, INSTANCE_ID); assertEquals(2, accessions2[0]); assertEquals(3, accessions2[1]); assertEquals(5, accessions2[2]); @@ -425,12 +425,12 @@ public void assertReleaseInAlternateRanges() throws Exception { @Test public void assertRecoverInAlternateRanges() throws Exception { MonotonicAccessionGenerator generator = getMonotonicAccessionGeneratorForCategoryHavingBlockInterval(); - long[] accessions1 = generator.generateAccessions(6); + long[] accessions1 = generator.generateAccessions(6, INSTANCE_ID); generator.shutDownAccessionGenerator(); // Now assume that the db layer has stored some elements and that the application has died and restarted. MonotonicAccessionGenerator generatorRecovering = - new MonotonicAccessionGenerator(CATEGORY_ID_2, INSTANCE_ID, service, monotonicDBService); - long[] accessions2 = generatorRecovering.generateAccessions(6); + new MonotonicAccessionGenerator(CATEGORY_ID_2, service, monotonicDBService); + long[] accessions2 = generatorRecovering.generateAccessions(6, INSTANCE_ID); assertEquals(1, accessions2[0]); assertEquals(2, accessions2[1]); assertEquals(3, accessions2[2]); @@ -443,21 +443,21 @@ private MonotonicAccessionGenerator getMonotonicAccessionGenerator() throws Exce assertEquals(0, repository.count()); MonotonicAccessionGenerator generator = new MonotonicAccessionGenerator( - CATEGORY_ID, INSTANCE_ID, service, monotonicDBService); + CATEGORY_ID, service, monotonicDBService); return generator; } private MonotonicAccessionGenerator getMonotonicAccessionGeneratorForCategoryHavingBlockInterval() { assertEquals(0, repository.count()); - return new MonotonicAccessionGenerator(CATEGORY_ID_2, INSTANCE_ID, service, monotonicDBService); + return new MonotonicAccessionGenerator(CATEGORY_ID_2, service, monotonicDBService); } @Test public void assertAbortExecutionWhenDBConstraintExceptionThrown() { ContiguousIdBlockService mockService = Mockito.mock(ContiguousIdBlockService.class, Answers.RETURNS_DEEP_STUBS); - MonotonicAccessionGenerator mockGenerator = new MonotonicAccessionGenerator(CATEGORY_ID, INSTANCE_ID, mockService, monotonicDBService); + MonotonicAccessionGenerator mockGenerator = new MonotonicAccessionGenerator(CATEGORY_ID, mockService, monotonicDBService); when(mockService.reserveNewBlock(anyString(), anyString())).thenThrow(ConstraintViolationException.class); - assertThrows(ExponentialBackOffMaxRetriesRuntimeException.class, () -> mockGenerator.generateAccessions(1)); + assertThrows(ExponentialBackOffMaxRetriesRuntimeException.class, () -> mockGenerator.generateAccessions(1, INSTANCE_ID)); assertEquals(0, repository.count()); } @@ -479,10 +479,10 @@ public void testInitializeBlockManager() throws AccessionCouldNotBeGeneratedExce assertEquals(false, unreservedBlocks.get(0).isReserved()); // Generator 1 starts - MonotonicAccessionGenerator generator1 = new MonotonicAccessionGenerator(CATEGORY_ID_2, INSTANCE_ID, service, monotonicDBService); + MonotonicAccessionGenerator generator1 = new MonotonicAccessionGenerator(CATEGORY_ID_2, service, monotonicDBService); assertEquals(0, generator1.getAvailableRanges().size()); // its recover state reserves the UnCompleted block - generator1.generateAccessions(0); + generator1.generateAccessions(0, INSTANCE_ID); assertEquals(1, generator1.getAvailableRanges().size()); assertEquals(new MonotonicRange(0, 9), generator1.getAvailableRanges().peek()); @@ -499,14 +499,14 @@ public void testInitializeBlockManager() throws AccessionCouldNotBeGeneratedExce assertEquals(true, reservedBlocks.get(0).isReserved()); // Generator-2 will not be able to reserve the un-completed block as it is currently reserved by Generator-1 - MonotonicAccessionGenerator generator2 = new MonotonicAccessionGenerator(CATEGORY_ID_2, INSTANCE_ID, service, monotonicDBService); - generator2.generateAccessions(0); + MonotonicAccessionGenerator generator2 = new MonotonicAccessionGenerator(CATEGORY_ID_2, service, monotonicDBService); + generator2.generateAccessions(0, INSTANCE_ID); assertEquals(0, generator2.getAvailableRanges().size()); // Generator-3 can reserve the same Uncompleted block, once Generator-1 releases it generator1.shutDownAccessionGenerator(); - MonotonicAccessionGenerator generator3 = new MonotonicAccessionGenerator(CATEGORY_ID_2, INSTANCE_ID, service, monotonicDBService); - generator3.generateAccessions(0); + MonotonicAccessionGenerator generator3 = new MonotonicAccessionGenerator(CATEGORY_ID_2, service, monotonicDBService); + generator3.generateAccessions(0, INSTANCE_ID); assertEquals(1, generator3.getAvailableRanges().size()); assertEquals(new MonotonicRange(0, 9), generator3.getAvailableRanges().peek()); } @@ -516,8 +516,8 @@ public void testShutDownAccessionGenerator() { MonotonicAccessionGenerator generator = getMonotonicAccessionGeneratorForCategoryHavingBlockInterval(); generator.shutDownAccessionGenerator(); - assertThrows(AccessionGeneratorShutDownException.class, () -> generator.generateAccessions(24)); - assertThrows(AccessionGeneratorShutDownException.class, () -> generator.generateAccessions(new HashMap())); + assertThrows(AccessionGeneratorShutDownException.class, () -> generator.generateAccessions(24, INSTANCE_ID)); + assertThrows(AccessionGeneratorShutDownException.class, () -> generator.generateAccessions(new HashMap(), INSTANCE_ID)); assertThrows(AccessionGeneratorShutDownException.class, () -> generator.commit()); assertThrows(AccessionGeneratorShutDownException.class, () -> generator.release()); assertThrows(AccessionGeneratorShutDownException.class, () -> generator.postSave(new SaveResponse<>())); diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerForDecoratedAccessionTestConfiguration.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerForDecoratedAccessionTestConfiguration.java index 04e81c27..d8d6d5fc 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerForDecoratedAccessionTestConfiguration.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/BasicRestControllerForDecoratedAccessionTestConfiguration.java @@ -106,7 +106,7 @@ public AccessioningService decoratedAccessioningServi @Bean public AccessioningService analysisAccessionService() { return new BasicAccessioningService<>( - new MonotonicAccessionGenerator<>(CATEGORY_ID, INSTANCE_ID, contiguousIdBlockService, + new MonotonicAccessionGenerator<>(CATEGORY_ID, contiguousIdBlockService, getDatabaseService()), getDatabaseService(), analysis -> analysis.getValue(), diff --git a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java index ea76d134..63806208 100644 --- a/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java +++ b/accession-commons-monotonic-generator-jpa/src/test/java/uk/ac/ebi/ampt2d/test/configuration/TestMonotonicDatabaseServiceTestConfiguration.java @@ -70,7 +70,6 @@ public BasicSpringDataRepositoryMonotonicDatabaseService monotonicAccessionGenerator() { return new MonotonicAccessionGenerator<>( CATEGORY_ID, - INSTANCE_ID, contiguousIdBlockService, getDatabaseService()); } diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java index bc7e18de..3e63e290 100644 --- a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/rest/MockTestAccessionGenerator.java @@ -39,7 +39,7 @@ public MockTestAccessionGenerator() { } @Override - public List> generateAccessions(Map messages) + public List> generateAccessions(Map messages, String applicationInstanceId) throws AccessionCouldNotBeGeneratedException { List> accessions = new ArrayList<>(); for (Map.Entry entry : messages.entrySet()) { diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java index e407d384..6fce2531 100644 --- a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessionTester.java @@ -29,6 +29,7 @@ import java.util.Arrays; public class AccessionTester { + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; private AccessioningService accessioningService; @@ -37,7 +38,7 @@ public AccessionTester(AccessioningService accessioni } public SingleAccessionTester accession(String value) throws AccessionCouldNotBeGeneratedException { - return new SingleAccessionTester(accessioningService.getOrCreate(Arrays.asList(TestModel.of(value))).get(0)); + return new SingleAccessionTester(accessioningService.getOrCreate(Arrays.asList(TestModel.of(value)), APPLICATION_INSTANCE_ID).get(0)); } public class SingleAccessionTester { diff --git a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java index 4f3ed345..c05585f1 100644 --- a/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java +++ b/accession-commons-test/src/main/java/uk/ac/ebi/ampt2d/test/testers/AccessioningServiceTester.java @@ -31,6 +31,7 @@ import java.util.stream.Collectors; public class AccessioningServiceTester { + private static String APPLICATION_INSTANCE_ID = "TEST_APPPLICATION_INSTANCE_ID"; private final AccessioningService accessioningService; @@ -52,7 +53,7 @@ public AccessioningServiceTester getOrCreate(String... values) { public AccessioningServiceTester getOrCreate(List models) { addToCollection(singleVersionResults, - new AccessionWrapperCollectionTester(() -> accessioningService.getOrCreate(models))); + new AccessionWrapperCollectionTester(() -> accessioningService.getOrCreate(models, APPLICATION_INSTANCE_ID))); return this; }