@Test public void shouldSucceedOnNoEvents() { assertNoError(ImmutableList.<Event>of()); }
@Test public void shouldSucceedWhenNoRefreshes() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.invokeLock(1, PROCESS_2)) .add(TestEventUtils.lockSuccess(2, PROCESS_2)) .add(TestEventUtils.lockSuccess(3, PROCESS_1)) .build(); assertNoError(eventList); }
@Test public void allowSimultaneousLockAndRefresh() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.lockSuccess(0, PROCESS_1)) .add(TestEventUtils.invokeRefresh(0, PROCESS_1)) .add(TestEventUtils.refreshSuccess(0, PROCESS_1)) .build(); assertNoError(eventList); }
@Test public void failedLockIntervalCoveredByAnotherProcessSucceeds() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.lockSuccess(1, PROCESS_1)) .add(TestEventUtils.invokeLock(2, PROCESS_2)) .add(TestEventUtils.lockFailure(3, PROCESS_2)) .add(TestEventUtils.invokeRefresh(4, PROCESS_1)) .add(TestEventUtils.refreshSuccess(5, PROCESS_1)) .build(); assertNoError(eventList); }
@Test public void canRefreshWhenAnotherProcessHasDifferentLock() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.lockSuccess(1, PROCESS_1)) .add(TestEventUtils.invokeLock(2, PROCESS_2, "alternate_lock")) .add(TestEventUtils.lockSuccess(3, PROCESS_2)) .add(TestEventUtils.invokeRefresh(4, PROCESS_1)) .add(TestEventUtils.refreshSuccess(5, PROCESS_1)) .build(); assertNoError(eventList); }
@Test public void shouldSucceedForIntervalEdgeCases() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.lockSuccess(1, PROCESS_1)) .add(TestEventUtils.invokeLock(1, PROCESS_2)) .add(TestEventUtils.lockSuccess(2, PROCESS_2)) .add(TestEventUtils.invokeLock(3, PROCESS_3)) .add(TestEventUtils.lockSuccess(4, PROCESS_3)) .add(TestEventUtils.invokeRefresh(4, PROCESS_1)) .add(TestEventUtils.refreshSuccess(5, PROCESS_1)) .build(); assertNoError(eventList); }
/** * The following test should succeed because it is theoretically possible for PROCESS_1 to hold the lock, * refresh it at time 3, then immediately lose the lock, the lock being granted to PROCESS_2 at time 3, then * again immediately lose it, the lock being granted to PROCESS_3, still at time 3. Then, a delayed response * informs PROCESS_2 that it was granted the lock, but it is actually PROCESS_3 that holds the lock. */ @Test public void shouldSucceedWhenThereIsASmallWindow() { ImmutableList<Event> eventList = ImmutableList.<Event>builder() .add(TestEventUtils.invokeLock(0, PROCESS_1)) .add(TestEventUtils.lockSuccess(1, PROCESS_1)) .add(TestEventUtils.invokeLock(2, PROCESS_2)) .add(TestEventUtils.invokeLock(2, PROCESS_3)) .add(TestEventUtils.invokeRefresh(3, PROCESS_1)) .add(TestEventUtils.refreshSuccess(3, PROCESS_1)) .add(TestEventUtils.lockSuccess(3, PROCESS_3)) .add(TestEventUtils.lockSuccess(4, PROCESS_2)) .add(TestEventUtils.invokeRefresh(5, PROCESS_3)) .add(TestEventUtils.refreshSuccess(6, PROCESS_3)) .build(); assertNoError(eventList); }