use of okio.Pipe in project okhttp by square.
the class RelayTest method racingReaders.
@Test
public void racingReaders() throws Exception {
Pipe pipe = new Pipe(1024);
BufferedSink sink = Okio.buffer(pipe.sink());
Relay relay = Relay.edit(file, pipe.source(), metadata, 5);
Future<ByteString> future1 = executor.submit(sourceReader(relay.newSource()));
Future<ByteString> future2 = executor.submit(sourceReader(relay.newSource()));
Thread.sleep(500);
sink.writeUtf8("abcdefghij");
Thread.sleep(500);
sink.writeUtf8("klmnopqrst");
sink.close();
assertEquals(ByteString.encodeUtf8("abcdefghijklmnopqrst"), future1.get());
assertEquals(ByteString.encodeUtf8("abcdefghijklmnopqrst"), future2.get());
assertTrue(relay.isClosed());
assertFile(Relay.PREFIX_CLEAN, 20L, metadata.size(), "abcdefghijklmnopqrst", metadata);
}
Aggregations