### Question:
DbEventMatcher implements EventHandler<DbOperation> { @Override public void onEvent(DbOperation event, long sequence, boolean endOfBatch) { if (LOGGER.isDebugEnabled()) { LOGGER.debug("{} event with message id {} for sequence {}", event.getType(), event.getMessage(), sequence); } eventQueue.add(event.getMessageId()); switch (event.getType()) { case INSERT_MESSAGE: insertMap.put(event.getMessage().getInternalId(), event); break; case DELETE_MESSAGE: long internalId = event.getMessageId(); removeMatchingInsertEvent(event, sequence, internalId); removeMatchingDetachEvents(internalId); break; case DETACH_MSG_FROM_QUEUE: detachMap.computeIfAbsent(event.getMessageId(), k -> new ArrayList<>()) .add(event); break; case READ_MSG_DATA: case NO_OP: break; default: if (LOGGER.isDebugEnabled()) { LOGGER.error("Unknown event type " + event.getType()); } } removeOldestEntryFromIndex(); event.completeProcessing(); } DbEventMatcher(int ringBufferSize); @Override void onEvent(DbOperation event, long sequence, boolean endOfBatch);  }### Answer:
@Test(dataProvider = "testDbOperationData") public void testInsertsCancelOut(TestOperationRequest[] testOperationsArray) { for (int i = 0; i < testOperationsArray.length; i++) { operationsList.add(DbOperation.getFactory().newInstance()); TestOperationRequest request = testOperationsArray[i]; if (request.beforeType == INSERT_MESSAGE) { operationsList.get(i).insertMessage(new Message(request.messageId, new Metadata("queue1", "amq.direct", 0))); } else if (request.beforeType == DELETE_MESSAGE) { operationsList.get(i).deleteMessage(request.messageId); } else { operationsList.get(i).detachFromQueue("queue1", request.messageId); } } for (int i = 0; i < testOperationsArray.length; i++) { dbEventMatcher.onEvent(operationsList.get(i), i, false); } for (int i = 0; i < testOperationsArray.length; i++) { Assert.assertTrue(operationsList.get(i).acquireForPersisting(), "Must be able to acquire for persisting."); Assert.assertEquals(operationsList.get(i).getType(), testOperationsArray[i].afterType, "Operation type after operation doesn't match for operation " + (i + 1) + "."); } }