use of alfio.model.CustomerName in project alf.io by alfio-event.
the class WaitingQueueProcessorMultiThreadedIntegrationTest method testPreRegistration.
@Test
public void testPreRegistration() throws InterruptedException {
IntegrationTestUtil.ensureMinimalConfiguration(configurationRepository);
configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_PRE_REGISTRATION, "true");
configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
initAdminUser(userRepository, authorityRepository);
Event event = null;
try {
List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(2), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null, 0, null, null, AlfioMetadata.empty()));
Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);
event = pair.getKey();
waitingQueueManager.subscribe(event, new CustomerName("Giuseppe Garibaldi", "Giuseppe", "Garibaldi", event.mustUseFirstAndLastName()), "peppino@garibaldi.com", null, Locale.ENGLISH);
waitingQueueManager.subscribe(event, new CustomerName("Nino Bixio", "Nino", "Bixio", event.mustUseFirstAndLastName()), "bixio@mille.org", null, Locale.ITALIAN);
assertEquals(2, (int) waitingQueueRepository.countWaitingPeople(event.getId()));
final int parallelism = 10;
List<Callable<Void>> calls = new ArrayList<>(parallelism);
ExecutorService executor = Executors.newFixedThreadPool(parallelism);
final Event eventF = event;
for (int i = 0; i < parallelism; i++) {
calls.add(() -> {
waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF);
return null;
});
}
executor.invokeAll(calls);
executor.shutdown();
while (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
}
assertEquals(18, ticketRepository.findFreeByEventId(event.getId()).size());
TicketCategoryModification tcm = new TicketCategoryModification(null, "default", TicketCategory.TicketAccessType.INHERIT, 10, new DateTimeModification(LocalDate.now(ClockProvider.clock()).minusDays(1), LocalTime.now(ClockProvider.clock())), new DateTimeModification(LocalDate.now(ClockProvider.clock()).plusDays(5), LocalTime.now(ClockProvider.clock())), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null, 0, null, null, AlfioMetadata.empty());
eventManager.insertCategory(event.getId(), tcm, pair.getValue());
// System.err.println("------------------------------------------------");
executor = Executors.newFixedThreadPool(parallelism);
calls.clear();
for (int i = 0; i < parallelism; i++) {
calls.add(() -> {
waitingQueueSubscriptionProcessor.distributeAvailableSeats(eventF);
return null;
});
}
executor.invokeAll(calls);
executor.shutdown();
while (!executor.awaitTermination(10, TimeUnit.MILLISECONDS)) {
}
List<WaitingQueueSubscription> subscriptions = waitingQueueRepository.loadAll(event.getId());
assertEquals(2, subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
assertTrue(subscriptions.stream().allMatch(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)));
assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.PRE_SALES)));
} finally {
if (event != null) {
eventManager.deleteEvent(event.getId(), UserManager.ADMIN_USERNAME);
}
configurationManager.deleteKey(ConfigurationKeys.ENABLE_PRE_REGISTRATION.name());
configurationManager.deleteKey(ConfigurationKeys.ENABLE_WAITING_QUEUE.name());
removeAdminUser(userRepository, authorityRepository);
}
}
Aggregations