diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderInstructionParserTest.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderInstructionParserTest.java index bc4c2900794..0fbcfa5e3a0 100644 --- a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderInstructionParserTest.java +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderInstructionParserTest.java @@ -14,8 +14,6 @@ package org.eclipse.jetty.http3.qpack; import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.Queue; import org.eclipse.jetty.http3.qpack.internal.parser.DecoderInstructionParser; import org.eclipse.jetty.util.BufferUtil; @@ -30,76 +28,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class DecoderInstructionParserTest { - public static class DebugHandler implements DecoderInstructionParser.Handler - { - public Queue setCapacities = new LinkedList<>(); - public Queue duplicates = new LinkedList<>(); - public Queue literalNameEntries = new LinkedList<>(); - public Queue referencedNameEntries = new LinkedList<>(); - - public static class Entry - { - public Entry(String name, String value) - { - this.value = value; - this.name = name; - } - - String name; - String value; - } - - public static class ReferencedEntry - { - public ReferencedEntry(int index, boolean dynamic, String value) - { - this.index = index; - this.dynamic = dynamic; - this.value = value; - } - - int index; - boolean dynamic; - String value; - } - - @Override - public void onSetDynamicTableCapacity(int capacity) - { - setCapacities.add(capacity); - } - - @Override - public void onDuplicate(int index) - { - duplicates.add(index); - } - - @Override - public void onInsertNameWithReference(int nameIndex, boolean isDynamicTableIndex, String value) - { - referencedNameEntries.add(new ReferencedEntry(nameIndex, isDynamicTableIndex, value)); - } - - @Override - public void onInsertWithLiteralName(String name, String value) - { - literalNameEntries.add(new Entry(name, value)); - } - - public boolean isEmpty() - { - return setCapacities.isEmpty() && duplicates.isEmpty() && literalNameEntries.isEmpty() && referencedNameEntries.isEmpty(); - } - } - private DecoderInstructionParser _instructionParser; - private DebugHandler _handler; + private DecoderParserDebugHandler _handler; @BeforeEach public void before() { - _handler = new DebugHandler(); + _handler = new DecoderParserDebugHandler(); _instructionParser = new DecoderInstructionParser(_handler); } @@ -109,7 +44,7 @@ public class DecoderInstructionParserTest String insertAuthorityEntry = "c00f7777772e6578616d706c652e636f6d"; ByteBuffer buffer = BufferUtil.toBuffer(TypeUtil.fromHexString(insertAuthorityEntry)); _instructionParser.parse(buffer); - DebugHandler.ReferencedEntry entry = _handler.referencedNameEntries.poll(); + DecoderParserDebugHandler.ReferencedEntry entry = _handler.referencedNameEntries.poll(); assertNotNull(entry); assertThat(entry.index, is(0)); assertThat(entry.dynamic, is(false)); diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderParserDebugHandler.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderParserDebugHandler.java new file mode 100644 index 00000000000..54afbe508f1 --- /dev/null +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/DecoderParserDebugHandler.java @@ -0,0 +1,102 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.http3.qpack; + +import java.util.LinkedList; +import java.util.Queue; + +import org.eclipse.jetty.http3.qpack.internal.parser.DecoderInstructionParser; + +public class DecoderParserDebugHandler implements DecoderInstructionParser.Handler +{ + public Queue setCapacities = new LinkedList<>(); + public Queue duplicates = new LinkedList<>(); + public Queue literalNameEntries = new LinkedList<>(); + public Queue referencedNameEntries = new LinkedList<>(); + + private final QpackDecoder _decoder; + + public DecoderParserDebugHandler() + { + this(null); + } + + public DecoderParserDebugHandler(QpackDecoder decoder) + { + _decoder = decoder; + } + + public static class Entry + { + public Entry(String name, String value) + { + this.value = value; + this.name = name; + } + + String name; + String value; + } + + public static class ReferencedEntry + { + public ReferencedEntry(int index, boolean dynamic, String value) + { + this.index = index; + this.dynamic = dynamic; + this.value = value; + } + + int index; + boolean dynamic; + String value; + } + + @Override + public void onSetDynamicTableCapacity(int capacity) + { + setCapacities.add(capacity); + if (_decoder != null) + _decoder.setCapacity(capacity); + } + + @Override + public void onDuplicate(int index) throws QpackException + { + duplicates.add(index); + if (_decoder != null) + _decoder.insert(index); + } + + @Override + public void onInsertNameWithReference(int nameIndex, boolean isDynamicTableIndex, String value) throws QpackException + { + referencedNameEntries.add(new ReferencedEntry(nameIndex, isDynamicTableIndex, value)); + if (_decoder != null) + _decoder.insert(nameIndex, isDynamicTableIndex, value); + } + + @Override + public void onInsertWithLiteralName(String name, String value) throws QpackException + { + literalNameEntries.add(new Entry(name, value)); + if (_decoder != null) + _decoder.insert(name, value); + } + + public boolean isEmpty() + { + return setCapacities.isEmpty() && duplicates.isEmpty() && literalNameEntries.isEmpty() && referencedNameEntries.isEmpty(); + } +} diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncodeDecodeTest.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncodeDecodeTest.java index e2a3a6e1588..f87df7979b1 100644 --- a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncodeDecodeTest.java +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncodeDecodeTest.java @@ -61,6 +61,9 @@ public class EncodeDecodeTest } }; _decoder = new QpackDecoder(_decoderHandler, MAX_HEADER_SIZE); + + _encoderInstructionParser = new EncoderInstructionParser(new EncoderParserDebugHandler(_encoder)); + _decoderInstructionParser = new DecoderInstructionParser(new DecoderParserDebugHandler(_decoder)); } @Test diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderInstructionParserTest.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderInstructionParserTest.java index f2610ca35fe..48f2c6983e8 100644 --- a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderInstructionParserTest.java +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderInstructionParserTest.java @@ -14,8 +14,6 @@ package org.eclipse.jetty.http3.qpack; import java.nio.ByteBuffer; -import java.util.LinkedList; -import java.util.Queue; import org.eclipse.jetty.http3.qpack.internal.parser.EncoderInstructionParser; import org.eclipse.jetty.util.BufferUtil; @@ -29,40 +27,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class EncoderInstructionParserTest { - public static class DebugHandler implements EncoderInstructionParser.Handler - { - public Queue sectionAcknowledgements = new LinkedList<>(); - public Queue streamCancellations = new LinkedList<>(); - public Queue insertCountIncrements = new LinkedList<>(); - - @Override - public void onSectionAcknowledgement(int streamId) - { - sectionAcknowledgements.add(streamId); - } - - @Override - public void onStreamCancellation(int streamId) - { - streamCancellations.add(streamId); - } - - @Override - public void onInsertCountIncrement(int increment) - { - insertCountIncrements.add(increment); - } - - public boolean isEmpty() - { - return sectionAcknowledgements.isEmpty() && streamCancellations.isEmpty() && insertCountIncrements.isEmpty(); - } - } @Test public void testSectionAcknowledgement() throws Exception { - DebugHandler debugHandler = new DebugHandler(); + EncoderParserDebugHandler debugHandler = new EncoderParserDebugHandler(); EncoderInstructionParser incomingEncoderStream = new EncoderInstructionParser(debugHandler); // Example from the spec, section acknowledgement instruction with stream id 4. diff --git a/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderParserDebugHandler.java b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderParserDebugHandler.java new file mode 100644 index 00000000000..2619f62bf7f --- /dev/null +++ b/jetty-http3/http3-qpack/src/test/java/org/eclipse/jetty/http3/qpack/EncoderParserDebugHandler.java @@ -0,0 +1,67 @@ +// +// ======================================================================== +// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others. +// +// This program and the accompanying materials are made available under the +// terms of the Eclipse Public License v. 2.0 which is available at +// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0 +// which is available at https://www.apache.org/licenses/LICENSE-2.0. +// +// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0 +// ======================================================================== +// + +package org.eclipse.jetty.http3.qpack; + +import java.util.LinkedList; +import java.util.Queue; + +import org.eclipse.jetty.http3.qpack.internal.parser.EncoderInstructionParser; + +public class EncoderParserDebugHandler implements EncoderInstructionParser.Handler +{ + public Queue sectionAcknowledgements = new LinkedList<>(); + public Queue streamCancellations = new LinkedList<>(); + public Queue insertCountIncrements = new LinkedList<>(); + + private final QpackEncoder _encoder; + + public EncoderParserDebugHandler() + { + this(null); + } + + public EncoderParserDebugHandler(QpackEncoder encoder) + { + _encoder = encoder; + } + + @Override + public void onSectionAcknowledgement(int streamId) throws QpackException + { + sectionAcknowledgements.add(streamId); + if (_encoder != null) + _encoder.sectionAcknowledgement(streamId); + } + + @Override + public void onStreamCancellation(int streamId) throws QpackException + { + streamCancellations.add(streamId); + if (_encoder != null) + _encoder.streamCancellation(streamId); + } + + @Override + public void onInsertCountIncrement(int increment) throws QpackException + { + insertCountIncrements.add(increment); + if (_encoder != null) + _encoder.insertCountIncrement(increment); + } + + public boolean isEmpty() + { + return sectionAcknowledgements.isEmpty() && streamCancellations.isEmpty() && insertCountIncrements.isEmpty(); + } +}