return eventQueue.get(index).toEvent();
}
@Test
public void testPush() throws Exception {
TransUnitSaveEvent firstEvent = saveEvent(1, 0, "new", "old");
queue.push(firstEvent);
assertThat(queue.getEventQueue(), Matchers.hasSize(1));
// pushing another event with same id and version should replace the old
// pending one
TransUnitSaveEvent anotherEvent = saveEvent(1, 0, "newer", "new");
queue.push(anotherEvent);
assertThat(queue.getEventQueue(), Matchers.hasSize(1));
assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
anotherEvent);
assertThat(queue.hasPending(), Matchers.is(true));
// pushing another event but doesn't match previous one. It will get
// discarded
TransUnitSaveEvent invalidEvent =
saveEvent(1, 0, "blah", "content don't match previous");
queue.push(invalidEvent);
assertThat(queue.getEventQueue(), Matchers.hasSize(1));
assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
anotherEvent);
assertThat(queue.hasPending(), Matchers.is(true));
// pushing another event with different id will not conflict with other
// pending one
TransUnitSaveEvent differentId = saveEvent(2, 1, "different id", "hi");
queue.push(differentId);
assertThat(queue.getEventQueue(), Matchers.hasSize(2));
assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 0),
anotherEvent);
assertEventEquals(fromQueueAsEvent(queue.getEventQueue(), 1),