Search in sources :

Example 1 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing_wraparound.

@Test
public void testQuadraticProbing_wraparound() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final SequentialItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    // next free itemId is 99999997
    idGenerationStrategy.getOrCreateCounter("1000154", ComponentCategory.CONCEPT).setCounter(99999997L);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    assertEquals("999999971000154106", Iterables.getOnlyElement(identifiers.generate("1000154", ComponentCategory.CONCEPT, 1)));
    // 99999998 and 2 becomes registered
    identifiers.register(ImmutableSet.of("999999981000154108", "21000154106"));
    // Attempt 1, quantity 2, 99999998 - 0
    // Attempt 2, quantity 1, 2 - 2
    // Attempt 3, quantity 1, 6 - 6
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate("1000154", ComponentCategory.CONCEPT, 2));
    List<String> expectedIds = ImmutableList.of("999999991000154105", "11000154102");
    assertEquals(expectedIds, actualIds);
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 2 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService in project snow-owl by b2ihealthcare.

the class ReservationImplTest method whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries.

@Test
public void whenReservingRangeOfIDs_ThenItShouldConflictWithAllIDsInThatRangeIncludingBoundaries() throws Exception {
    final Index store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
    store.admin().create();
    final ISnomedIdentifierService identifierService = new DefaultSnomedIdentifierService(store, new ItemIdGenerationStrategy() {

        int counter = 200;

        @Override
        public Set<String> generateItemIds(String namespace, ComponentCategory category, int quantity, int attempt) {
            return IntStream.range(counter, counter + quantity).mapToObj(String::valueOf).collect(Collectors.toSet());
        }
    }, new SnomedIdentifierReservationServiceImpl(), new SnomedIdentifierConfiguration());
    final Set<ComponentCategory> components = Collections.singleton(ComponentCategory.CONCEPT);
    final Reservation range = Reservations.range(200, 300, "", components);
    final Set<String> componentIds = identifierService.generate(null, ComponentCategory.CONCEPT, 300 - 200 + 1);
    for (String id : componentIds) {
        final SnomedIdentifier identifier = SnomedIdentifiers.create(id);
        assertTrue(range.includes(identifier));
    }
    store.admin().delete();
}
Also used : ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) Set(java.util.Set) Index(com.b2international.index.Index) SnomedIdentifier(com.b2international.snowowl.snomed.cis.SnomedIdentifier) ComponentCategory(com.b2international.snowowl.core.terminology.ComponentCategory) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) Reservation(com.b2international.snowowl.snomed.cis.reservations.Reservation) Mappings(com.b2international.index.mapping.Mappings) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) SctId(com.b2international.snowowl.snomed.cis.domain.SctId) Test(org.junit.Test)

Example 3 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_1945_testItemIdPoolExhausted.

@Test
public void issue_SO_1945_testItemIdPoolExhausted() throws Exception {
    final Provider<Index> storeProvider = Providers.of(store);
    final ItemIdGenerationStrategy idGenerationStrategy = new CyclingItemIdGenerationStrategy("1000", "1001");
    final SnomedIdentifierConfiguration config = new SnomedIdentifierConfiguration();
    config.setMaxIdGenerationAttempts(10);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(storeProvider, idGenerationStrategy, config);
    final String first = Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1));
    assertThat(first).startsWith("1000");
    final String second = Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1));
    assertThat(second).startsWith("1001");
    /*
		 * The third attempt should generate itemId 1000 again,
		 * but that is already generated and no more itemIds are available
		 * therefore it will try to generate 1001, and that fails too, 
		 * rinse and repeat until maxIdGenerationAttempts are made
		 */
    try {
        identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1);
    } catch (final BadRequestException e) {
        assertThat(e.getMessage()).isEqualTo(String.format("Couldn't generate 1 identifiers [CONCEPT, INT] in maximum (%s) number of attempts", config.getMaxIdGenerationAttempts()));
    }
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) BadRequestException(com.b2international.commons.exceptions.BadRequestException) Index(com.b2international.index.Index) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 4 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method issue_SO_2138_testItemIdsReturnedInSequence.

@Test
public void issue_SO_2138_testItemIdsReturnedInSequence() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    List<String> actualIds = ImmutableList.copyOf(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 3));
    List<String> expectedIds = ImmutableList.of("100005", "101009", "102002");
    assertEquals(expectedIds, actualIds);
    actualIds = ImmutableList.copyOf(identifiers.generate(B2I_NAMESPACE, ComponentCategory.CONCEPT, 3));
    expectedIds = ImmutableList.of("11000129102", "21000129106", "31000129108");
    assertEquals(expectedIds, actualIds);
    // Make a surprise return to the INT namespace here
    assertEquals("103007", Iterables.getFirst(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1), null));
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Example 5 with ISnomedIdentifierService

use of com.b2international.snowowl.snomed.cis.ISnomedIdentifierService in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceRegressionTest method testQuadraticProbing.

@Test
public void testQuadraticProbing() throws Exception {
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    final ISnomedIdentifierService identifiers = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
    identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1);
    // Register a few existing SCTIDs that are "in the way"
    identifiers.register(ImmutableSet.of(// 1
    "101009", // 2
    "102002"));
    assertEquals("104001", Iterables.getOnlyElement(identifiers.generate(INT_NAMESPACE, ComponentCategory.CONCEPT, 1)));
}
Also used : SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) SequentialItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy) ItemIdGenerationStrategy(com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) ISnomedIdentifierService(com.b2international.snowowl.snomed.cis.ISnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Test(org.junit.Test)

Aggregations

ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)15 Test (org.junit.Test)14 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)10 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)10 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)9 SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)9 ISnomedIdentifierReservationService (com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService)8 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)7 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)5 Json (com.b2international.commons.json.Json)3 AbstractSnomedApiTest (com.b2international.snowowl.snomed.core.rest.AbstractSnomedApiTest)3 Index (com.b2international.index.Index)2 BadRequestException (com.b2international.commons.exceptions.BadRequestException)1 Mappings (com.b2international.index.mapping.Mappings)1 Commit (com.b2international.index.revision.Commit)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)1 SnomedIdentifiers (com.b2international.snowowl.snomed.cis.SnomedIdentifiers)1 Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)1 RelationshipValue (com.b2international.snowowl.snomed.core.domain.RelationshipValue)1