@Test
@FixFor("MODE-2547")
public void shouldStoreBinariesConcurrently() throws Exception {

    int binariesCount = 11;  //to cover MongoDB, make sure this is >10 which is the default Mongo pool size
    List<byte[]> bytesToStore = new ArrayList<>(binariesCount);
    for (int i = 0; i < binariesCount; i++) {
        byte[] data = new byte[LARGE_BINARY_SIZE];
        RANDOM.nextBytes(data);
        bytesToStore.add(data);
    }
    ExecutorService executorService = Executors.newFixedThreadPool(binariesCount);
    try {
        final CyclicBarrier barrier = new CyclicBarrier(binariesCount + 1);
        List<Future<BinaryValue>> results = new ArrayList<>(binariesCount);
        for (final byte[] data : bytesToStore) {
            Future<BinaryValue> result = executorService.submit(() -> {
                barrier.await();
                return getBinaryStore().storeValue(new ByteArrayInputStream(data), false);
            });
            results.add(result);
        }
        barrier.await();
        List<BinaryValue> storedBinaries = new ArrayList<>(binariesCount);
        for (Future<BinaryValue> result : results) {
            storedBinaries.add(result.get(2, TimeUnit.SECONDS));
        }
        for (int i = 0; i < binariesCount; i++) {
            byte[] expectedBytes = bytesToStore.get(i);
            byte[] actualBytes = IoUtil.readBytes(storedBinaries.get(i).getStream());
            Assert.assertArrayEquals("Invalid binary found", expectedBytes, actualBytes);
        }
    } finally {
        executorService.shutdownNow();
    }
}