test/jdk/java/net/httpclient/whitebox/java.net.http/jdk/internal/net/http/WindowControllerTest.java
author chegar
Tue, 24 Jul 2018 10:07:26 +0100
changeset 51232 ad1fa1db73d9
permissions -rw-r--r--
8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative Reviewed-by: michaelm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
51232
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     1
/*
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     2
 * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved.
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     4
 *
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     7
 * published by the Free Software Foundation.
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     8
 *
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    13
 * accompanied this code).
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    14
 *
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    18
 *
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    21
 * questions.
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    22
 */
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    23
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    24
package jdk.internal.net.http;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    25
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    26
import org.testng.annotations.Test;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    27
import static jdk.internal.net.http.frame.SettingsFrame.DEFAULT_INITIAL_WINDOW_SIZE;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    28
import static org.testng.Assert.assertEquals;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    29
import static org.testng.Assert.assertThrows;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    30
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    31
public class WindowControllerTest {
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    32
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    33
    @Test
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    34
    public void testConnectionWindowOverflow() {
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    35
        WindowController wc = new WindowController();
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    36
        assertEquals(wc.connectionWindowSize(), DEFAULT_INITIAL_WINDOW_SIZE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    37
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    38
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    39
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    40
        assertEquals(wc.connectionWindowSize(), DEFAULT_INITIAL_WINDOW_SIZE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    41
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    42
        wc.registerStream(1, DEFAULT_INITIAL_WINDOW_SIZE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    43
        wc.tryAcquire(DEFAULT_INITIAL_WINDOW_SIZE - 1, 1, null);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    44
        assertEquals(wc.connectionWindowSize(), 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    45
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    46
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    47
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    48
        assertEquals(wc.connectionWindowSize(), 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    49
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    50
        wc.increaseConnectionWindow(Integer.MAX_VALUE - 1 -1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    51
        assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE - 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    52
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    53
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    54
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    55
        assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE - 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    56
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    57
        wc.increaseConnectionWindow(1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    58
        assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    59
        assertEquals(wc.increaseConnectionWindow(1), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    60
        assertEquals(wc.increaseConnectionWindow(100), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    61
        assertEquals(wc.increaseConnectionWindow(Integer.MAX_VALUE), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    62
        assertEquals(wc.connectionWindowSize(), Integer.MAX_VALUE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    63
    }
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    64
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    65
    @Test
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    66
    public void testStreamWindowOverflow() {
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    67
        WindowController wc = new WindowController();
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    68
        wc.registerStream(1, DEFAULT_INITIAL_WINDOW_SIZE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    69
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    70
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    71
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 1), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    72
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    73
        wc.registerStream(3, DEFAULT_INITIAL_WINDOW_SIZE);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    74
        assertEquals(wc.increaseStreamWindow(100, 3), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    75
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 3), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    76
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 3), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    77
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    78
        wc.registerStream(5, 0);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    79
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 5), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    80
        assertEquals(wc.increaseStreamWindow(1, 5), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    81
        assertEquals(wc.increaseStreamWindow(1, 5), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    82
        assertEquals(wc.increaseStreamWindow(10, 5), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    83
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    84
        wc.registerStream(7, -1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    85
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 7), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    86
        assertEquals(wc.increaseStreamWindow(1, 7), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    87
        assertEquals(wc.increaseStreamWindow(1, 7), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    88
        assertEquals(wc.increaseStreamWindow(10, 7), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    89
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    90
        wc.registerStream(9, -1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    91
        assertEquals(wc.increaseStreamWindow(1, 9), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    92
        assertEquals(wc.increaseStreamWindow(1, 9), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    93
        assertEquals(wc.increaseStreamWindow(1, 9), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    94
        assertEquals(wc.increaseStreamWindow(10, 9), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    95
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 9), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    96
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    97
        wc.registerStream(11, -10);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    98
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
    99
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   100
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   101
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   102
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   103
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   104
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   105
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   106
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   107
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   108
        assertEquals(wc.increaseStreamWindow(1, 11), true);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   109
        assertEquals(wc.streamWindowSize(11), 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   110
        assertEquals(wc.increaseStreamWindow(Integer.MAX_VALUE, 11), false);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   111
        assertEquals(wc.streamWindowSize(11), 1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   112
    }
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   113
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   114
    @Test
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   115
    public void testStreamAdjustment() {
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   116
        WindowController wc = new WindowController();
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   117
        wc.registerStream(1, 100);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   118
        wc.registerStream(3, 100);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   119
        wc.registerStream(5, 100);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   120
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   121
        // simulate some stream send activity before receiving the server's
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   122
        // SETTINGS frame, and staying within the connection window size
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   123
        wc.tryAcquire(49, 1 , null);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   124
        wc.tryAcquire(50, 3 , null);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   125
        wc.tryAcquire(51, 5 , null);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   126
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   127
        wc.adjustActiveStreams(-200);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   128
        assertEquals(wc.streamWindowSize(1), -149);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   129
        assertEquals(wc.streamWindowSize(3), -150);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   130
        assertEquals(wc.streamWindowSize(5), -151);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   131
    }
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   132
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   133
    static final Class<InternalError> IE = InternalError.class;
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   134
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   135
    @Test
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   136
    public void testRemoveStream() {
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   137
        WindowController wc = new WindowController();
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   138
        wc.registerStream(1, 999);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   139
        wc.removeStream(1);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   140
        assertThrows(IE, () -> wc.tryAcquire(5, 1, null));
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   141
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   142
        wc.registerStream(3, 999);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   143
        wc.tryAcquire(998, 3, null);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   144
        wc.removeStream(3);
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   145
        assertThrows(IE, () -> wc.tryAcquire(5, 1, null));
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   146
    }
ad1fa1db73d9 8207960: Non-negative WINDOW_UPDATE increments may leave the stream window size negative
chegar
parents:
diff changeset
   147
}