Search in sources :

Example 1 with Pipe

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);
}
Also used : ByteString(okio.ByteString) BufferedSink(okio.BufferedSink) Pipe(okio.Pipe) Test(org.junit.Test)

Aggregations

BufferedSink (okio.BufferedSink)1 ByteString (okio.ByteString)1 Pipe (okio.Pipe)1 Test (org.junit.Test)1