2015-07-12 23:04:26 -04:00
|
|
|
/**
|
|
|
|
|
* Copyright (C) 2015 Typesafe Inc. <http://www.typesafe.com>
|
|
|
|
|
*/
|
|
|
|
|
package akka.stream.io;
|
|
|
|
|
|
|
|
|
|
import akka.japi.Pair;
|
|
|
|
|
import akka.stream.StreamTest;
|
|
|
|
|
import akka.stream.javadsl.AkkaJUnitActorSystemResource;
|
|
|
|
|
import akka.stream.javadsl.Sink;
|
|
|
|
|
import akka.stream.javadsl.Source;
|
|
|
|
|
import akka.stream.testkit.AkkaSpec;
|
|
|
|
|
import akka.stream.testkit.Utils;
|
|
|
|
|
import akka.util.ByteString;
|
|
|
|
|
import org.junit.ClassRule;
|
|
|
|
|
import org.junit.Test;
|
|
|
|
|
import scala.concurrent.Future;
|
|
|
|
|
import scala.concurrent.duration.FiniteDuration;
|
|
|
|
|
|
|
|
|
|
import java.io.InputStream;
|
|
|
|
|
import java.util.Arrays;
|
|
|
|
|
import java.util.Collections;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
import static org.junit.Assert.assertTrue;
|
|
|
|
|
|
|
|
|
|
public class InputStreamSinkTest extends StreamTest {
|
|
|
|
|
public InputStreamSinkTest() {
|
|
|
|
|
super(actorSystemResource);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ClassRule
|
|
|
|
|
public static AkkaJUnitActorSystemResource actorSystemResource = new AkkaJUnitActorSystemResource("InputStreamSink",
|
|
|
|
|
Utils.UnboundedMailboxConfig());
|
|
|
|
|
@Test
|
|
|
|
|
public void mustReadEventViaInputStream() throws Exception {
|
|
|
|
|
final FiniteDuration timeout = FiniteDuration.create(300, TimeUnit.MILLISECONDS);
|
|
|
|
|
|
2015-11-17 13:17:30 +01:00
|
|
|
final Sink<ByteString, InputStream> sink = Sink.inputStream(timeout);
|
2015-07-12 23:04:26 -04:00
|
|
|
final List<ByteString> list = Collections.singletonList(ByteString.fromString("a"));
|
|
|
|
|
final InputStream stream = Source.from(list).runWith(sink, materializer);
|
|
|
|
|
|
|
|
|
|
byte[] a = new byte[1];
|
|
|
|
|
stream.read(a);
|
|
|
|
|
assertTrue(Arrays.equals("a".getBytes(), a));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|