Skip to content

Commit

Permalink
Merge pull request Netflix#222 from benjchristensen/unit-test-fixes
Browse files Browse the repository at this point in the history
Future.cancel - Unit Test Fixes
  • Loading branch information
benjchristensen committed Mar 13, 2014
2 parents 3baaaf0 + 2efc350 commit e5b375b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ subprojects {

sourceSets.test.java.srcDir 'src/main/java'

tasks.withType(Javadoc).each {
it.classpath = sourceSets.main.compileClasspath
}
// tasks.withType(Javadoc).each {
// it.classpath = sourceSets.main.compileClasspath
// }
}

// Prevent contrib project from being published
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
Expand Down Expand Up @@ -145,7 +146,12 @@ public void testUnsubscribeOnOneDoesntKillBatch() throws Exception {
timer.incrementTime(10); // let time pass that equals the default delay/period

// the first is cancelled so should return null
assertEquals(null, response1.get());
try {
response1.get();
fail("expect CancellationException after cancelling");
} catch (CancellationException e) {
// expected
}
// we should still get a response on the second
assertEquals("2", response2.get());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static org.junit.Assert.*;

import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

Expand Down Expand Up @@ -110,7 +111,7 @@ public void testSetResponseDuplicate() throws InterruptedException, ExecutionExc
assertEquals("theResponse", v.get());
}

@Test
@Test(expected = CancellationException.class)
public void testSetResponseAfterUnsubscribe() throws InterruptedException, ExecutionException {
CollapsedRequestObservableFunction<String, String> cr = new CollapsedRequestObservableFunction<String, String>("hello");
Observable<String> o = Observable.create(cr);
Expand All @@ -125,11 +126,11 @@ public void testSetResponseAfterUnsubscribe() throws InterruptedException, Execu
fail("this should have done nothing as it was unsubscribed already");
}

// if you fetch after canceling it should be null
assertEquals(null, f.get());
// expect CancellationException after cancelling
f.get();
}

@Test
@Test(expected = CancellationException.class)
public void testSetExceptionAfterUnsubscribe() throws InterruptedException, ExecutionException {
CollapsedRequestObservableFunction<String, String> cr = new CollapsedRequestObservableFunction<String, String>("hello");
Observable<String> o = Observable.create(cr);
Expand All @@ -144,8 +145,8 @@ public void testSetExceptionAfterUnsubscribe() throws InterruptedException, Exec
fail("this should have done nothing as it was unsubscribed already");
}

// if you fetch after canceling it should be null
assertEquals(null, f.get());
// expect CancellationException after cancelling
f.get();
}

@Test
Expand Down

0 comments on commit e5b375b

Please sign in to comment.