Program: 164555
Project: 164555
Buggy source:
@Test public void testSoldOut() throws InterruptedException {
  List<TicketCategoryModification> categories=Arrays.asList(new TicketCategoryModification(null,"String_Node_Str",AVAILABLE_SEATS - 1,new DateTimeModification(LocalDate.now().minusDays(1),LocalTime.now()),new DateTimeModification(LocalDate.now().plusDays(2),LocalTime.now()),DESCRIPTION,BigDecimal.ZERO,false,"String_Node_Str",true),new TicketCategoryModification(null,"String_Node_Str",0,new DateTimeModification(LocalDate.now().minusDays(1),LocalTime.now()),new DateTimeModification(LocalDate.now().plusDays(2),LocalTime.now()),DESCRIPTION,BigDecimal.ZERO,false,"String_Node_Str",false));
  Pair<Event,String> pair=initEvent(categories,organizationRepository,userManager,eventManager);
  Event event=pair.getKey();
  List<TicketCategory> ticketCategories=eventManager.loadTicketCategories(event);
  TicketCategory bounded=ticketCategories.get(0);
  TicketCategory unbounded=ticketCategories.get(1);
  List<Integer> reserved=ticketRepository.selectFreeTicketsForPreReservation(event.getId(),20);
  String reservationId=UUID.randomUUID().toString();
  ticketReservationRepository.createNewReservation(reservationId,DateUtils.addHours(new Date(),1),null,Locale.ITALIAN.getLanguage());
  ticketRepository.reserveTickets(reservationId,reserved.subList(0,19),bounded.getId(),Locale.ITALIAN.getLanguage());
  ticketRepository.reserveTickets(reservationId,reserved.subList(19,20),unbounded.getId(),Locale.ITALIAN.getLanguage());
  ticketRepository.updateTicketsStatusWithReservationId(reservationId,Ticket.TicketStatus.ACQUIRED.name());
  waitingQueueManager.subscribe(event,"String_Node_Str","String_Node_Str",Locale.ENGLISH);
  Thread.sleep(100L);
  waitingQueueManager.subscribe(event,"String_Node_Str","String_Node_Str",Locale.ITALIAN);
  List<WaitingQueueSubscription> subscriptions=waitingQueueRepository.loadAll(event.getId());
  assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
  assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT)));
  waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
  assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
  Ticket firstTicket=ticketRepository.findTicketsInReservation(reservationId).get(0);
  ticketRepository.releaseTicket(reservationId,event.getId(),firstTicket.getId());
  waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
  subscriptions=waitingQueueRepository.loadAll(event.getId());
  assertEquals(1,subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
  Optional<WaitingQueueSubscription> first=subscriptions.stream().filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst();
  assertTrue(first.isPresent());
  assertEquals("String_Node_Str",first.get().getFullName());
}

Fixed version (ground truth):
@Test public void testSoldOut() throws InterruptedException {
  List<TicketCategoryModification> categories=Arrays.asList(new TicketCategoryModification(null,"String_Node_Str",AVAILABLE_SEATS - 1,new DateTimeModification(LocalDate.now().minusDays(1),LocalTime.now()),new DateTimeModification(LocalDate.now().plusDays(2),LocalTime.now()),DESCRIPTION,BigDecimal.ZERO,false,"String_Node_Str",true),new TicketCategoryModification(null,"String_Node_Str",0,new DateTimeModification(LocalDate.now().minusDays(1),LocalTime.now()),new DateTimeModification(LocalDate.now().plusDays(2),LocalTime.now()),DESCRIPTION,BigDecimal.ZERO,false,"String_Node_Str",false));
  Pair<Event,String> pair=initEvent(categories,organizationRepository,userManager,eventManager);
  Event event=pair.getKey();
  List<TicketCategory> ticketCategories=eventManager.loadTicketCategories(event);
  TicketCategory bounded=ticketCategories.get(0);
  TicketCategory unbounded=ticketCategories.get(1);
  List<Integer> boundedReserved=ticketRepository.selectFreeTicketsForPreReservation(event.getId(),20,ticketCategories.get(0).getId());
  assertEquals(19,boundedReserved.size());
  List<Integer> unboundedReserved=ticketRepository.selectNotAllocatedFreeTicketsForPreReservation(event.getId(),20);
  assertEquals(1,unboundedReserved.size());
  List<Integer> reserved=new ArrayList<>(boundedReserved);
  reserved.addAll(unboundedReserved);
  String reservationId=UUID.randomUUID().toString();
  ticketReservationRepository.createNewReservation(reservationId,DateUtils.addHours(new Date(),1),null,Locale.ITALIAN.getLanguage());
  ticketRepository.reserveTickets(reservationId,reserved.subList(0,19),bounded.getId(),Locale.ITALIAN.getLanguage());
  ticketRepository.reserveTickets(reservationId,reserved.subList(19,20),unbounded.getId(),Locale.ITALIAN.getLanguage());
  ticketRepository.updateTicketsStatusWithReservationId(reservationId,Ticket.TicketStatus.ACQUIRED.name());
  waitingQueueManager.subscribe(event,"String_Node_Str","String_Node_Str",Locale.ENGLISH);
  Thread.sleep(100L);
  waitingQueueManager.subscribe(event,"String_Node_Str","String_Node_Str",Locale.ITALIAN);
  List<WaitingQueueSubscription> subscriptions=waitingQueueRepository.loadAll(event.getId());
  assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
  assertTrue(subscriptions.stream().allMatch(w -> w.getSubscriptionType().equals(WaitingQueueSubscription.Type.SOLD_OUT)));
  waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
  assertTrue(waitingQueueRepository.countWaitingPeople(event.getId()) == 2);
  Ticket firstTicket=ticketRepository.findTicketsInReservation(reservationId).get(0);
  ticketRepository.releaseTicket(reservationId,event.getId(),firstTicket.getId());
  waitingQueueSubscriptionProcessor.distributeAvailableSeats(event);
  subscriptions=waitingQueueRepository.loadAll(event.getId());
  assertEquals(1,subscriptions.stream().filter(w -> StringUtils.isNotBlank(w.getReservationId())).count());
  Optional<WaitingQueueSubscription> first=subscriptions.stream().filter(w -> w.getStatus().equals(WaitingQueueSubscription.Status.PENDING)).findFirst();
  assertTrue(first.isPresent());
  assertEquals("String_Node_Str",first.get().getFullName());
}