kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | f6fcf70d35a80c3209e36eae6bf6a781f7bfcf16243f349d311c27e06d172ff4 |
|---|---|
| Author | Andrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-09 19:43 -05:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-09-29 16:16 -07:00 |
| Parents | 08569ae862b6 |
1 file changed
modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +31 −5
| @@ -46,7 +46,7 @@ | ||
| 46 | 46 | final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>(); |
| 47 | 47 | AbstractReconnectionHandler handler; |
| 48 | 48 | |
| 49 | - @BeforeMethod(groups = "unit") | |
| 49 | + @BeforeMethod(groups = {"unit", "short"}) | |
| 50 | 50 | public void setup() { |
| 51 | 51 | executor = Executors.newScheduledThreadPool(2); |
| 52 | 52 | schedule = new MockReconnectionSchedule(); |
| @@ -65,7 +65,7 @@ | ||
| 65 | 65 | }; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - @AfterMethod(groups = "unit") | |
| 68 | + @AfterMethod(groups = {"unit", "short"}) | |
| 69 | 69 | public void tearDown() { |
| 70 | 70 | if (future.get() != null) |
| 71 | 71 | future.get().cancel(false); |
| @@ -115,10 +115,9 @@ | ||
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | @Test(groups = "unit") |
| 118 | - public void should_stop_if_cancelled_between_attempts() { | |
| 119 | - handler.start(); | |
| 120 | - | |
| 118 | + public void should_stop_if_cancelled_before_first_attempt() { | |
| 121 | 119 | schedule.delay = 10 * 1000; // give ourselves time to cancel |
| 120 | + handler.start(); | |
| 122 | 121 | schedule.tick(); |
| 123 | 122 | |
| 124 | 123 | future.get().cancel(false); |
| @@ -130,6 +129,33 @@ | ||
| 130 | 129 | assertThat(future.get().isCancelled()).isTrue(); |
| 131 | 130 | } |
| 132 | 131 | |
| 132 | + @Test(groups = "short") | |
| 133 | + public void should_stop_if_cancelled_between_attempts() { | |
| 134 | + handler.start(); | |
| 135 | + | |
| 136 | + // Force a failed reconnect. | |
| 137 | + schedule.tick(); | |
| 138 | + work.nextReconnect = ReconnectBehavior.THROW_EXCEPTION; | |
| 139 | + // Tick work, should trigger the barrier in tryReconnect. | |
| 140 | + work.tick(); | |
| 141 | + | |
| 142 | + // Tick schedule, should cause nextDelayMs to proceed, reconnect handler will call reschedule. | |
| 143 | + schedule.delay = 3000; | |
| 144 | + schedule.tick(); | |
| 145 | + | |
| 146 | + // At this point the reconnect should be scheduled but not executed yet, cancel the future. | |
| 147 | + future.get().cancel(false); | |
| 148 | + | |
| 149 | + // Should block until scheduler runs, detects cancel and exits. | |
| 150 | + waitForCompletion(); | |
| 151 | + | |
| 152 | + assertThat(work.success).isFalse(); | |
| 153 | + // Should have had 1 failed attempt, no second attempt since cancelled. | |
| 154 | + assertThat(work.tries).isEqualTo(1); | |
| 155 | + // The future will be marked null once it is detected as cancelled. | |
| 156 | + assertThat(future.get()).isNull(); | |
| 157 | + } | |
| 158 | + | |
| 133 | 159 | @Test(groups = "unit") |
| 134 | 160 | public void should_complete_if_cancelled_during_successful_reconnect() throws InterruptedException { |
| 135 | 161 | handler.start(); |