+str 18735: Added keepalive inject and initial delay ops

Also, improved documentation of timeout operations
Added missing Java DSL smoke tests
This commit is contained in:
Endre Sándor Varga 2015-11-02 15:30:10 +01:00
parent fb3dd99eb3
commit 8e62c0d9d7
12 changed files with 595 additions and 71 deletions

View file

@ -27,9 +27,11 @@ import scala.runtime.BoxedUnit;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static akka.stream.testkit.StreamTestKit.PublisherProbeSubscription;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@SuppressWarnings("serial")
public class FlowTest extends StreamTest {
@ -718,4 +720,69 @@ public class FlowTest extends StreamTest {
probe.expectMsgAllOf("A", "B", "C", "D", "E", "F");
}
@Test
public void mustBeAbleToUseInitialTimeout() throws Exception {
try {
Await.result(
Source.<Integer>maybe()
.via(Flow.of(Integer.class).initialTimeout(Duration.create(1, "second")))
.runWith(Sink.<Integer>head(), materializer),
Duration.create(3, "second")
);
fail("A TimeoutException was expected");
} catch(TimeoutException e) {
// expected
}
}
@Test
public void mustBeAbleToUseCompletionTimeout() throws Exception {
try {
Await.result(
Source.<Integer>maybe()
.via(Flow.of(Integer.class).completionTimeout(Duration.create(1, "second")))
.runWith(Sink.<Integer>head(), materializer),
Duration.create(3, "second")
);
fail("A TimeoutException was expected");
} catch(TimeoutException e) {
// expected
}
}
@Test
public void mustBeAbleToUseIdleTimeout() throws Exception {
try {
Await.result(
Source.<Integer>maybe()
.via(Flow.of(Integer.class).idleTimeout(Duration.create(1, "second")))
.runWith(Sink.<Integer>head(), materializer),
Duration.create(3, "second")
);
fail("A TimeoutException was expected");
} catch(TimeoutException e) {
// expected
}
}
@Test
public void mustBeAbleToUseKeepAlive() throws Exception {
Integer result = Await.result(
Source.<Integer>maybe()
.via(Flow.of(Integer.class)
.keepAlive(Duration.create(1, "second"), new Creator<Integer>() {
public Integer create() {
return 0;
}
})
)
.takeWithin(Duration.create(1500, "milliseconds"))
.runWith(Sink.<Integer>head(), materializer),
Duration.create(3, "second")
);
assertEquals((Object) 0, result);
}
}