private Thread[] storeEvents(int threadCount, int eventsPerThread, int inverseRollbackRate) { Thread[] threads = new Thread[threadCount]; for (int i = 0; i < threadCount; i++) { final int threadIndex = i; threads[i] = new Thread(() -> { for (int j = 0; j < eventsPerThread; j++) { final int s = j; try { txTemplate.execute(ts -> { testSubject.appendEvents( createEvent(AGGREGATE, threadIndex * eventsPerThread + s, "Thread" + threadIndex)); if (s % inverseRollbackRate == 0) { throw new RuntimeException("Rolling back on purpose"); } try { Thread.sleep(ThreadLocalRandom.current().nextInt(10)); } catch (InterruptedException e) { e.printStackTrace(); } return null; }); } catch (Exception ignored) { } } }); threads[i].start(); } return threads; }
@Test @SuppressWarnings("OptionalGetWithoutIsPresent") public void testLoad_LargeAmountOfEvents() { int eventCount = testSubject.batchSize() + 10; testSubject.appendEvents(createEvents(eventCount)); assertEquals(eventCount, testSubject.readEvents(AGGREGATE).asStream().count()); assertEquals(eventCount - 1, testSubject.readEvents(AGGREGATE).asStream().reduce((a, b) -> b).get().getSequenceNumber()); }