Search in sources :

Example 1 with SnomedIdentifierReservationServiceImpl

use of com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl 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 SnomedIdentifierReservationServiceImpl

use of com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl 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 SnomedIdentifierReservationServiceImpl

use of com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl in project snow-owl by b2ihealthcare.

the class CisSnomedIdentifierServiceTest method init.

@Before
public void init() {
    final SnomedIdentifierConfiguration conf = new SnomedIdentifierConfiguration();
    conf.setCisBaseUrl("http://107.170.101.181:3000");
    conf.setCisContextRoot("api");
    conf.setCisClientSoftwareKey("Snow Owl dev. tests");
    conf.setCisUserName("snowowl-dev-b2i");
    conf.setCisPassword("hAAYLYMX5gc98SDEz9cr");
    conf.setCisTimeBetweenPollTries(1000);
    conf.setCisNumberOfPollTries(5);
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    service = new CisSnomedIdentifierService(conf, reservationService, mapper);
}
Also used : SnomedIdentifierReservationServiceImpl(com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl) CisSnomedIdentifierService(com.b2international.snowowl.snomed.cis.client.CisSnomedIdentifierService) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) Before(org.junit.Before)

Example 4 with SnomedIdentifierReservationServiceImpl

use of com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl in project snow-owl by b2ihealthcare.

the class DefaultSnomedIdentifierServiceTest method init.

@Before
public void init() {
    store = Indexes.createIndex(UUID.randomUUID().toString(), new ObjectMapper(), new Mappings(SctId.class));
    store.admin().create();
    final ISnomedIdentifierReservationService reservationService = new SnomedIdentifierReservationServiceImpl();
    final ItemIdGenerationStrategy idGenerationStrategy = new SequentialItemIdGenerationStrategy(reservationService);
    service = new DefaultSnomedIdentifierService(store, idGenerationStrategy, reservationService, new SnomedIdentifierConfiguration());
}
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) Mappings(com.b2international.index.mapping.Mappings) ISnomedIdentifierReservationService(com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService) DefaultSnomedIdentifierService(com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService) SnomedIdentifierConfiguration(com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Before(org.junit.Before)

Example 5 with SnomedIdentifierReservationServiceImpl

use of com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl 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)

Aggregations

SnomedIdentifierReservationServiceImpl (com.b2international.snowowl.snomed.cis.internal.reservations.SnomedIdentifierReservationServiceImpl)12 SnomedIdentifierConfiguration (com.b2international.snowowl.snomed.cis.SnomedIdentifierConfiguration)11 ISnomedIdentifierReservationService (com.b2international.snowowl.snomed.cis.reservations.ISnomedIdentifierReservationService)11 DefaultSnomedIdentifierService (com.b2international.snowowl.snomed.cis.memory.DefaultSnomedIdentifierService)10 ISnomedIdentifierService (com.b2international.snowowl.snomed.cis.ISnomedIdentifierService)9 SequentialItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.SequentialItemIdGenerationStrategy)9 Test (org.junit.Test)9 ItemIdGenerationStrategy (com.b2international.snowowl.snomed.cis.gen.ItemIdGenerationStrategy)7 Mappings (com.b2international.index.mapping.Mappings)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 Before (org.junit.Before)2 Index (com.b2international.index.Index)1 ComponentCategory (com.b2international.snowowl.core.terminology.ComponentCategory)1 SnomedIdentifier (com.b2international.snowowl.snomed.cis.SnomedIdentifier)1 CisSnomedIdentifierService (com.b2international.snowowl.snomed.cis.client.CisSnomedIdentifierService)1 SctId (com.b2international.snowowl.snomed.cis.domain.SctId)1 Reservation (com.b2international.snowowl.snomed.cis.reservations.Reservation)1 Set (java.util.Set)1