Search in sources :

Example 36 with WritableByteChannelMock

use of org.apache.hc.core5.http2.WritableByteChannelMock in project httpcomponents-core by apache.

the class TestPathAsyncEntityProducer method testTextContentRepeatable.

@Test
public void testTextContentRepeatable() throws Exception {
    final Path tempPath = tempFile.toPath();
    final AsyncEntityProducer producer = new PathEntityProducer(tempPath, ContentType.TEXT_PLAIN, StandardOpenOption.READ);
    Assertions.assertEquals(6, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    for (int i = 0; i < 3; i++) {
        final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
        final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
        producer.produce(streamChannel);
        producer.produce(streamChannel);
        Assertions.assertFalse(byteChannel.isOpen());
        Assertions.assertEquals("abcdef", byteChannel.dump(StandardCharsets.US_ASCII));
        producer.releaseResources();
    }
}
Also used : Path(java.nio.file.Path) AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 37 with WritableByteChannelMock

use of org.apache.hc.core5.http2.WritableByteChannelMock in project httpcomponents-core by apache.

the class TestStringAsyncEntityProducer method testTextContentRepeatable.

@Test
public void testTextContentRepeatable() throws Exception {
    final AsyncEntityProducer producer = new StringAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
    Assertions.assertEquals(-1, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    for (int i = 0; i < 3; i++) {
        final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
        final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
        producer.produce(streamChannel);
        Assertions.assertFalse(byteChannel.isOpen());
        Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
        producer.releaseResources();
    }
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 38 with WritableByteChannelMock

use of org.apache.hc.core5.http2.WritableByteChannelMock in project httpcomponents-core by apache.

the class TestStringAsyncEntityProducer method testTextContent.

@Test
public void testTextContent() throws Exception {
    final AsyncEntityProducer producer = new StringAsyncEntityProducer("abc", ContentType.TEXT_PLAIN);
    Assertions.assertEquals(-1, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 39 with WritableByteChannelMock

use of org.apache.hc.core5.http2.WritableByteChannelMock in project httpcomponents-core by apache.

the class TestSharedOutputBuffer method testFlush.

@Test
public void testFlush() throws Exception {
    final Charset charset = StandardCharsets.US_ASCII;
    final SharedOutputBuffer outputBuffer = new SharedOutputBuffer(30);
    final WritableByteChannelMock channel = new WritableByteChannelMock(1024);
    final DataStreamChannel dataStreamChannel = new DataStreamChannelMock(channel);
    outputBuffer.flush(dataStreamChannel);
    Assertions.assertEquals(0, outputBuffer.length());
    Assertions.assertEquals(30, outputBuffer.capacity());
    final byte[] tmp = "1234567890".getBytes(charset);
    outputBuffer.write(tmp, 0, tmp.length);
    outputBuffer.write(tmp, 0, tmp.length);
    outputBuffer.write('1');
    outputBuffer.write('2');
    outputBuffer.flush(dataStreamChannel);
    Assertions.assertEquals(0, outputBuffer.length());
    Assertions.assertEquals(30, outputBuffer.capacity());
}
Also used : WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) Charset(java.nio.charset.Charset) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Example 40 with WritableByteChannelMock

use of org.apache.hc.core5.http2.WritableByteChannelMock in project httpcomponents-core by apache.

the class TestAbstractCharAsyncEntityProducer method testProduceDataNoBuffering.

@Test
public void testProduceDataNoBuffering() throws Exception {
    final AsyncEntityProducer producer = new ChunkCharAsyncEntityProducer(256, 0, ContentType.TEXT_PLAIN, "this", "this and that");
    Assertions.assertEquals(-1, producer.getContentLength());
    Assertions.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType());
    Assertions.assertNull(producer.getContentEncoding());
    final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024);
    final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel);
    producer.produce(streamChannel);
    Assertions.assertTrue(byteChannel.isOpen());
    Assertions.assertEquals("this", byteChannel.dump(StandardCharsets.US_ASCII));
    producer.produce(streamChannel);
    Assertions.assertFalse(byteChannel.isOpen());
    Assertions.assertEquals("this and that", byteChannel.dump(StandardCharsets.US_ASCII));
}
Also used : AsyncEntityProducer(org.apache.hc.core5.http.nio.AsyncEntityProducer) WritableByteChannelMock(org.apache.hc.core5.http.WritableByteChannelMock) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) BasicDataStreamChannel(org.apache.hc.core5.http.nio.BasicDataStreamChannel) DataStreamChannel(org.apache.hc.core5.http.nio.DataStreamChannel) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)79 WritableByteChannelMock (org.apache.hc.core5.http.WritableByteChannelMock)70 SessionOutputBuffer (org.apache.hc.core5.http.nio.SessionOutputBuffer)52 BasicHttpTransportMetrics (org.apache.hc.core5.http.impl.BasicHttpTransportMetrics)50 DataStreamChannel (org.apache.hc.core5.http.nio.DataStreamChannel)20 BasicDataStreamChannel (org.apache.hc.core5.http.nio.BasicDataStreamChannel)15 AsyncEntityProducer (org.apache.hc.core5.http.nio.AsyncEntityProducer)14 RandomAccessFile (java.io.RandomAccessFile)11 FileChannel (java.nio.channels.FileChannel)11 ByteBuffer (java.nio.ByteBuffer)10 CharArrayBuffer (org.apache.hc.core5.util.CharArrayBuffer)10 WritableByteChannelMock (org.apache.hc.core5.http2.WritableByteChannelMock)5 RawFrame (org.apache.hc.core5.http2.frame.RawFrame)5 Charset (java.nio.charset.Charset)3 Path (java.nio.file.Path)2 HttpStreamResetException (org.apache.hc.core5.http.HttpStreamResetException)2 ExecutorService (java.util.concurrent.ExecutorService)1 Header (org.apache.hc.core5.http.Header)1 BasicHeader (org.apache.hc.core5.http.message.BasicHeader)1 ReadableByteChannelMock (org.apache.hc.core5.http2.ReadableByteChannelMock)1