View Javadoc
1   /*
2    * ====================================================================
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *   http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing,
14   * software distributed under the License is distributed on an
15   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16   * KIND, either express or implied.  See the License for the
17   * specific language governing permissions and limitations
18   * under the License.
19   * ====================================================================
20   *
21   * This software consists of voluntary contributions made by many
22   * individuals on behalf of the Apache Software Foundation.  For more
23   * information on the Apache Software Foundation, please see
24   * <http://www.apache.org/>.
25   *
26   */
27  
28  package org.apache.hc.core5.http2.hpack;
29  
30  import org.junit.jupiter.api.Assertions;
31  import org.junit.jupiter.api.Test;
32  
33  public class TestOutboundDynamicTable {
34  
35      @Test
36      public void testBasics() throws Exception {
37  
38          final OutboundDynamicTable table = new OutboundDynamicTable();
39          Assertions.assertEquals(Integer.MAX_VALUE, table.getMaxSize());
40          Assertions.assertEquals(0, table.getCurrentSize());
41  
42          final HPackHeader header1 = new HPackHeader("h", "1");
43          table.add(header1);
44          Assertions.assertEquals(1, table.dynamicLength());
45          Assertions.assertEquals(61, table.staticLength());
46          Assertions.assertEquals(62, table.length());
47          Assertions.assertSame(header1, table.getHeader(62));
48          Assertions.assertEquals(34, table.getCurrentSize());
49      }
50  
51      @Test
52      public void testEviction() throws Exception {
53  
54          final OutboundDynamicTable table = new OutboundDynamicTable();
55  
56          table.add(new HPackHeader("h", "1"));
57          table.add(new HPackHeader("h", "2"));
58  
59          Assertions.assertEquals(68, table.getCurrentSize());
60  
61          table.setMaxSize(256);
62          Assertions.assertEquals(68, table.getCurrentSize());
63          table.setMaxSize(67);
64          Assertions.assertEquals(34, table.getCurrentSize());
65          table.setMaxSize(10);
66          Assertions.assertEquals(0, table.getCurrentSize());
67      }
68  
69  }
70