mardi 19 mai 2020

Spring repository find calls in java parallelStream error for unit tests

Spring repository find calls inside java parallelStream for unit tests do not return the expected results. I suspect it could be some configuration needed for spring tests when using parallelStream? Any ideas?

//Is never empty
List<ObjectHistory> allHist = objectHistoryRepository.findAll();

//problematic
objects.parallelStream()
        .forEach(i-> {
              //Is  empty except for one or none
              List<ObjectHistory> allHist = objectHistoryRepository.findAll();

              //Optional is empty except for one or none
              Optional<ObjectHistory> objHistoryOptional = objectHistoryRepository.findFirstById(i.getId());
         });

//works fine
objects.stream()
        .forEach(i-> {
              //Is never empty
              List<ObjectHistory> allHist = objectHistoryRepository.findAll();

              //Optional is never empty
              Optional<ObjectHistory> objHistoryOptional = objectHistoryRepository.findFirstById(i.getId());
        });

Aucun commentaire:

Enregistrer un commentaire