test/jdk/java/net/httpclient/whitebox/java.net.http/java/net/http/internal/frame/FramesDecoderTest.java
author chegar
Wed, 07 Feb 2018 14:17:24 +0000
branchhttp-client-branch
changeset 56089 42208b2f224e
parent 56036 test/jdk/java/net/httpclient/whitebox/jdk.incubator.httpclient/jdk/incubator/http/internal/frame/FramesDecoderTest.java@89a688549f5d
permissions -rw-r--r--
http-client-branch: move to standard package and module name
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
56036
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     1
/*
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     4
 *
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     8
 *
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    13
 * accompanied this code).
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    14
 *
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    18
 *
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    21
 * questions.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    22
 */
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    23
56089
42208b2f224e http-client-branch: move to standard package and module name
chegar
parents: 56036
diff changeset
    24
package java.net.http.internal.frame;
56036
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    25
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    26
import java.io.IOException;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    27
import java.nio.ByteBuffer;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    28
import java.util.ArrayList;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    29
import java.util.List;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    30
import org.testng.Assert;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    31
import org.testng.annotations.Test;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    32
import static java.lang.System.out;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    33
import static java.nio.charset.StandardCharsets.UTF_8;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    34
import static org.testng.Assert.*;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    35
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    36
public class FramesDecoderTest {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    37
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    38
    abstract class TestFrameProcessor implements FramesDecoder.FrameProcessor {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    39
        protected volatile int count;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    40
        public int numberOfFramesDecoded() { return count; }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    41
    }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    42
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    43
    /**
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    44
     * Verifies that a ByteBuffer containing more that one frame, destined
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    45
     * to be returned to the user's subscriber, i.e. a data frame, does not
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    46
     * inadvertently expose the following frame ( between its limit and
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    47
     * capacity ).
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    48
     */
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    49
    @Test
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    50
    public void decodeDataFrameFollowedByAnother() throws Exception {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    51
        // input frames for to the decoder
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    52
        List<ByteBuffer> data1 = List.of(ByteBuffer.wrap("XXXX".getBytes(UTF_8)));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    53
        DataFrame dataFrame1 = new DataFrame(1, 0, data1);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    54
        List<ByteBuffer> data2 = List.of(ByteBuffer.wrap("YYYY".getBytes(UTF_8)));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    55
        DataFrame dataFrame2 = new DataFrame(1, 0, data2);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    56
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    57
        List<ByteBuffer> buffers = new ArrayList<>();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    58
        FramesEncoder encoder = new FramesEncoder();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    59
        buffers.addAll(encoder.encodeFrame(dataFrame1));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    60
        buffers.addAll(encoder.encodeFrame(dataFrame2));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    61
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    62
        ByteBuffer combined = ByteBuffer.allocate(1024);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    63
        buffers.stream().forEach(combined::put);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    64
        combined.flip();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    65
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    66
        TestFrameProcessor testFrameProcessor = new TestFrameProcessor() {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    67
            @Override
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    68
            public void processFrame(Http2Frame frame) throws IOException {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    69
                assertTrue(frame instanceof DataFrame);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    70
                DataFrame dataFrame = (DataFrame) frame;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    71
                List<ByteBuffer> list = dataFrame.getData();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    72
                assertEquals(list.size(), 1);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    73
                ByteBuffer data = list.get(0);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    74
                byte[] bytes = new byte[data.remaining()];
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    75
                data.get(bytes);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    76
                if (count == 0) {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    77
                    assertEquals(new String(bytes, UTF_8), "XXXX");
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    78
                    out.println("First data received:" + data);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    79
                    assertEquals(data.position(), data.limit());  // since bytes read
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    80
                    assertEquals(data.limit(), data.capacity());
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    81
                } else {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    82
                    assertEquals(new String(bytes, UTF_8), "YYYY");
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    83
                    out.println("Second data received:" + data);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    84
                }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    85
                count++;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    86
            }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    87
        };
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    88
        FramesDecoder decoder = new FramesDecoder(testFrameProcessor);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    89
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    90
        out.println("Sending " + combined + " to decoder: ");
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    91
        decoder.decode(combined);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    92
        Assert.assertEquals(testFrameProcessor.numberOfFramesDecoded(), 2);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    93
    }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    94
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    95
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    96
    /**
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    97
     * Verifies that a ByteBuffer containing ONLY data one frame, destined
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    98
     * to be returned to the user's subscriber, does not restrict the capacity.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
    99
     * The complete buffer ( all its capacity ), since no longer used by the
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   100
     * HTTP Client, should be returned to the user.
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   101
     */
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   102
    @Test
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   103
    public void decodeDataFrameEnsureNotCapped() throws Exception {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   104
        // input frames for to the decoder
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   105
        List<ByteBuffer> data1 = List.of(ByteBuffer.wrap("XXXX".getBytes(UTF_8)));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   106
        DataFrame dataFrame1 = new DataFrame(1, 0, data1);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   107
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   108
        List<ByteBuffer> buffers = new ArrayList<>();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   109
        FramesEncoder encoder = new FramesEncoder();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   110
        buffers.addAll(encoder.encodeFrame(dataFrame1));
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   111
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   112
        ByteBuffer combined = ByteBuffer.allocate(1024);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   113
        buffers.stream().forEach(combined::put);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   114
        combined.flip();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   115
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   116
        TestFrameProcessor testFrameProcessor = new TestFrameProcessor() {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   117
            @Override
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   118
            public void processFrame(Http2Frame frame) throws IOException {
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   119
                assertTrue(frame instanceof DataFrame);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   120
                DataFrame dataFrame = (DataFrame) frame;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   121
                List<ByteBuffer> list = dataFrame.getData();
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   122
                assertEquals(list.size(), 1);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   123
                ByteBuffer data = list.get(0);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   124
                byte[] bytes = new byte[data.remaining()];
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   125
                data.get(bytes);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   126
                assertEquals(new String(bytes, UTF_8), "XXXX");
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   127
                out.println("First data received:" + data);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   128
                assertEquals(data.position(), data.limit());  // since bytes read
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   129
                //assertNotEquals(data.limit(), data.capacity());
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   130
                assertEquals(data.capacity(), 1024 - 9 /*frame header*/);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   131
                count++;
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   132
            }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   133
        };
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   134
        FramesDecoder decoder = new FramesDecoder(testFrameProcessor);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   135
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   136
        out.println("Sending " + combined + " to decoder: ");
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   137
        decoder.decode(combined);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   138
        Assert.assertEquals(testFrameProcessor.numberOfFramesDecoded(), 1);
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   139
    }
89a688549f5d http-client-branch: Import of 8195823: Buffers given to response body subscribers should not contain unprocessed HTTP data
chegar
parents:
diff changeset
   140
}