Elffuss BraidHub

kikocis/java-driver public

Fix should_stop_if_cancelled_between_attempts and relabel it as 'short'
Changesetf6fcf70d35a80c3209e36eae6bf6a781f7bfcf16243f349d311c27e06d172ff4
AuthorAndrew Tolbert <andrew.tolbert@datastax.com> · 2015-09-09 19:43 -05:00
Committerolim7t <omichallat+github@gmail.com> · 2015-09-29 16:16 -07:00
Parents08569ae862b6

Browse the files at this changeset

1 file changed

modified driver-core/src/test/java/com/datastax/driver/core/AbstractReconnectionHandlerTest.java +31 −5
@@ -46,7 +46,7 @@
4646 final AtomicReference<ListenableFuture<?>> future = new AtomicReference<ListenableFuture<?>>();
4747 AbstractReconnectionHandler handler;
4848
49- @BeforeMethod(groups = "unit")
49+ @BeforeMethod(groups = {"unit", "short"})
5050 public void setup() {
5151 executor = Executors.newScheduledThreadPool(2);
5252 schedule = new MockReconnectionSchedule();
@@ -65,7 +65,7 @@
6565 };
6666 }
6767
68- @AfterMethod(groups = "unit")
68+ @AfterMethod(groups = {"unit", "short"})
6969 public void tearDown() {
7070 if (future.get() != null)
7171 future.get().cancel(false);
@@ -115,10 +115,9 @@
115115 }
116116
117117 @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() {
121119 schedule.delay = 10 * 1000; // give ourselves time to cancel
120+ handler.start();
122121 schedule.tick();
123122
124123 future.get().cancel(false);
@@ -130,6 +129,33 @@
130129 assertThat(future.get().isCancelled()).isTrue();
131130 }
132131
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+
133159 @Test(groups = "unit")
134160 public void should_complete_if_cancelled_during_successful_reconnect() throws InterruptedException {
135161 handler.start();