@Test public void testCancelFutureWithInterruptionWhenPropertySaysNotTo() throws InterruptedException, ExecutionException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true, false, 1000); // when Future<Boolean> f = cmd.queue(); Thread.sleep(500); f.cancel(true); Thread.sleep(500); // then try { f.get(); fail("Should have thrown a CancellationException"); } catch (CancellationException e) { assertFalse(cmd.hasBeenInterrupted()); } }
@Test public void testCancelFutureWithoutInterruption() throws InterruptedException, ExecutionException, TimeoutException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true, true, 1000); // when Future<Boolean> f = cmd.queue(); Thread.sleep(500); f.cancel(false); Thread.sleep(500); // then try { f.get(); fail("Should have thrown a CancellationException"); } catch (CancellationException e) { assertFalse(cmd.hasBeenInterrupted()); } }
@Test public void testCancelFutureWithInterruption() throws InterruptedException, ExecutionException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true, true, 1000); // when Future<Boolean> f = cmd.queue(); Thread.sleep(500); f.cancel(true); Thread.sleep(500); // then try { f.get(); fail("Should have thrown a CancellationException"); } catch (CancellationException e) { assertTrue(cmd.hasBeenInterrupted()); } }
@Test public void testDoNotInterruptToObservableOnTimeoutIfPropertySaysNotTo() throws InterruptedException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), false); // when cmd.toObservable().subscribe(); // then Thread.sleep(500); assertFalse(cmd.hasBeenInterrupted()); }
@Test public void testDoNotInterruptFutureOnTimeoutIfPropertySaysNotTo() throws InterruptedException, ExecutionException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), false); // when Future<Boolean> f = cmd.queue(); // then Thread.sleep(500); assertFalse(cmd.hasBeenInterrupted()); }
@Test public void testInterruptToObservableOnTimeout() throws InterruptedException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true); // when cmd.toObservable().subscribe(); // then Thread.sleep(500); assertTrue(cmd.hasBeenInterrupted()); }
@Test public void testInterruptFutureOnTimeout() throws InterruptedException, ExecutionException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true); // when Future<Boolean> f = cmd.queue(); // then Thread.sleep(500); assertTrue(cmd.hasBeenInterrupted()); }
@Test public void testInterruptObserveOnTimeout() throws InterruptedException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), true); // when cmd.observe().subscribe(); // then Thread.sleep(500); assertTrue(cmd.hasBeenInterrupted()); }
@Test public void testDoNotInterruptObserveOnTimeoutIfPropertySaysNotTo() throws InterruptedException { // given InterruptibleCommand cmd = new InterruptibleCommand(new TestCircuitBreaker(), false); // when cmd.observe().subscribe(); // then Thread.sleep(500); assertFalse(cmd.hasBeenInterrupted()); }