ErrorCheckingTimestampBoundStore implements TimestampBoundStore { @Override public synchronized void storeUpperLimit(long limit) { failures.verifyWeShouldIssueMoreTimestamps(); throwIfInterrupted(); try { delegate.storeUpperLimit(limit); } catch (Throwable t) { throw failures.responseTo(t); } } ErrorCheckingTimestampBoundStore(TimestampBoundStore delegate); @VisibleForTesting  ErrorCheckingTimestampBoundStore(TimestampBoundStore delegate, TimestampAllocationFailures failures); @Override long getUpperLimit(); @Override synchronized void storeUpperLimit(long limit);  }
@Test public void shouldDelegateHandlingOfAllocationFailures() { RuntimeException failure = new RuntimeException(); RuntimeException expectedException = new RuntimeException(); doThrow(failure).when(delegate).storeUpperLimit(anyLong()); when(allocationFailures.responseTo(failure)).thenReturn(expectedException); exception.expect(is(expectedException)); store.storeUpperLimit(1_000); }
@Test public void shouldNotAllocateTimestampsIfAllocationFailuresDisallowsIt() { doThrow(RuntimeException.class).when(allocationFailures).verifyWeShouldIssueMoreTimestamps(); try { store.storeUpperLimit(1_000); } catch (Exception e) { } verify(delegate, never()).storeUpperLimit(anyLong()); }
@Test public void shouldThrowAnInterruptedExceptionIfTheThreadIsInterrupted() { try { exception.expect(PalantirInterruptedException.class); Thread.currentThread().interrupt(); store.storeUpperLimit(1_000); } finally { Thread.interrupted(); } }
@Test public void shouldNotTryToPersistANewLimitIfInterrupted() { try { Thread.currentThread().interrupt(); store.storeUpperLimit(1_000); } catch (Exception e) { } finally { Thread.interrupted(); } verify(delegate, never()).storeUpperLimit(anyLong()); }