Posts

Does collect return a list snapshot if run on a parallel stream?

Image
up vote 2 down vote favorite 1 I have a unit test that started to fail on Circle CI only . It fails on the last line in this (Kotlin) example: generator.generateNames(50) // returns List<String> .parallelStream() .map { name -> val playerId = "${name.firstName.toLowerCase()}" Player(playerId = playerId) }.collect(Collectors.toList()).last() throwing: Caused by: java.util.NoSuchElementException . It works always on my local machine or on Circle CI if I do not use a parallel stream. My theory is that the collect call returns a List snapshot (it actually doesn't block until the List is completely filled) and that CI doesn't have enough CPU to collect a single element in other threads? However, my stream is ordered and so is the Collector right? Is this even collecting in parallel? ...