+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

@ -31,10 +31,12 @@ import scala.util.Try;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import static akka.stream.testkit.StreamTestKit.PublisherProbeSubscription;
import static akka.stream.testkit.TestPublisher.ManualProbe;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
@SuppressWarnings("serial")
public class SourceTest extends StreamTest {
@ -653,4 +655,62 @@ public class SourceTest extends StreamTest {
probe.expectMsgAllOf("A", "B", "C", "D", "E", "F");
}
@Test
public void mustBeAbleToUseInitialTimeout() throws Exception {
try {
Await.result(
Source.maybe().initialTimeout(Duration.create(1, "second")).runWith(Sink.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.maybe().completionTimeout(Duration.create(1, "second")).runWith(Sink.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.maybe().idleTimeout(Duration.create(1, "second")).runWith(Sink.head(), materializer),
Duration.create(3, "second")
);
fail("A TimeoutException was expected");
} catch(TimeoutException e) {
// expected
}
}
@Test
public void mustBeAbleToUseIdleInject() throws Exception {
Integer result = Await.result(
Source.maybe()
.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);
}
}