TXLastEventInTransactionUtils { public static EntryEventImpl getLastTransactionEvent(List<EntryEventImpl> callbacks, Cache cache) throws ServiceConfigurationError { if (checkNoSendersGroupTransactionEvents(callbacks, cache)) { return null; } List<Set> senderIdsPerEvent = getGroupingSendersPerEvent(callbacks, cache); if (senderIdsPerEvent.stream().distinct().count() > 1) { String info = eventsAndSendersPerEventToString(callbacks, senderIdsPerEvent); throw new ServiceConfigurationError( "Not all events go to the same senders that group transactions. " + info); } return callbacks.get(callbacks.size() - 1); }  static EntryEventImpl getLastTransactionEvent(List<EntryEventImpl> callbacks,
      Cache cache);  }
@Test public void getLastTransactionEventReturnsNullWhenGroupTransactionEventsIsFalseForAllSenders() { List<EntryEventImpl> events = new ArrayList(); EntryEventImpl event1 = createMockEntryEventImpl(region1); EntryEventImpl event2 = createMockEntryEventImpl(region2); events.add(event1); events.add(event2); EntryEventImpl lastTransactionEvent = TXLastEventInTransactionUtils.getLastTransactionEvent(events, cache); assertEquals(null, lastTransactionEvent); }
@Test public void getLastTransactionEventReturnsEventWhenAllSendersGroupTransactionEvents() { List<EntryEventImpl> events = new ArrayList(); EntryEventImpl event1 = createMockEntryEventImpl(region3); EntryEventImpl event2 = createMockEntryEventImpl(region4); events.add(event1); events.add(event2); EntryEventImpl lastTransactionEvent = TXLastEventInTransactionUtils.getLastTransactionEvent(events, cache); assertEquals(event2, lastTransactionEvent); }
@Test public void getLastTransactionEventReturnsWhenNotAllSendersGroupTransactionEvents() { List<EntryEventImpl> events = new ArrayList(); EntryEventImpl event1 = createMockEntryEventImpl(region5); EntryEventImpl event2 = createMockEntryEventImpl(region6); events.add(event1); events.add(event2); EntryEventImpl lastTransactionEvent = TXLastEventInTransactionUtils.getLastTransactionEvent(events, cache); assertEquals(event2, lastTransactionEvent); }
@Test public void getLastTransactionEventThrowsExceptionWhenNotAllEventsToSameGroupingSenders() { List<EntryEventImpl> events = new ArrayList(); EntryEventImpl event1 = createMockEntryEventImpl(region3); EntryEventImpl event2 = createMockEntryEventImpl(region7); events.add(event1); events.add(event2); assertThatThrownBy(() -> TXLastEventInTransactionUtils.getLastTransactionEvent(events, cache)) .isInstanceOf(ServiceConfigurationError.class) .hasMessageContaining("Not all events go to the same senders that group transactions"); }
@Test public void getLastTransactionEventThrowsExceptionWhenSenderNotFound() { List<EntryEventImpl> events = new ArrayList(); EntryEventImpl event1 = createMockEntryEventImpl(region8); EntryEventImpl event2 = createMockEntryEventImpl(region8); events.add(event1); events.add(event2); assertThatThrownBy(() -> TXLastEventInTransactionUtils.getLastTransactionEvent(events, cache)) .isInstanceOf(ServiceConfigurationError.class) .hasMessage("No information for senderId: sender5"); }