Fix broken test case EncodeDecodeTest.

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2021-03-10 12:37:51 +11:00 committed by Simone Bordet
parent ea70f599bb
commit 27122c2c91
5 changed files with 176 additions and 100 deletions

View File

@ -14,8 +14,6 @@
package org.eclipse.jetty.http3.qpack; package org.eclipse.jetty.http3.qpack;
import java.nio.ByteBuffer; 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.http3.qpack.internal.parser.DecoderInstructionParser;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
@ -30,76 +28,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class DecoderInstructionParserTest public class DecoderInstructionParserTest
{ {
public static class DebugHandler implements DecoderInstructionParser.Handler
{
public Queue<Integer> setCapacities = new LinkedList<>();
public Queue<Integer> duplicates = new LinkedList<>();
public Queue<Entry> literalNameEntries = new LinkedList<>();
public Queue<ReferencedEntry> 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 DecoderInstructionParser _instructionParser;
private DebugHandler _handler; private DecoderParserDebugHandler _handler;
@BeforeEach @BeforeEach
public void before() public void before()
{ {
_handler = new DebugHandler(); _handler = new DecoderParserDebugHandler();
_instructionParser = new DecoderInstructionParser(_handler); _instructionParser = new DecoderInstructionParser(_handler);
} }
@ -109,7 +44,7 @@ public class DecoderInstructionParserTest
String insertAuthorityEntry = "c00f7777772e6578616d706c652e636f6d"; String insertAuthorityEntry = "c00f7777772e6578616d706c652e636f6d";
ByteBuffer buffer = BufferUtil.toBuffer(TypeUtil.fromHexString(insertAuthorityEntry)); ByteBuffer buffer = BufferUtil.toBuffer(TypeUtil.fromHexString(insertAuthorityEntry));
_instructionParser.parse(buffer); _instructionParser.parse(buffer);
DebugHandler.ReferencedEntry entry = _handler.referencedNameEntries.poll(); DecoderParserDebugHandler.ReferencedEntry entry = _handler.referencedNameEntries.poll();
assertNotNull(entry); assertNotNull(entry);
assertThat(entry.index, is(0)); assertThat(entry.index, is(0));
assertThat(entry.dynamic, is(false)); assertThat(entry.dynamic, is(false));

View File

@ -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<Integer> setCapacities = new LinkedList<>();
public Queue<Integer> duplicates = new LinkedList<>();
public Queue<Entry> literalNameEntries = new LinkedList<>();
public Queue<ReferencedEntry> 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();
}
}

View File

@ -61,6 +61,9 @@ public class EncodeDecodeTest
} }
}; };
_decoder = new QpackDecoder(_decoderHandler, MAX_HEADER_SIZE); _decoder = new QpackDecoder(_decoderHandler, MAX_HEADER_SIZE);
_encoderInstructionParser = new EncoderInstructionParser(new EncoderParserDebugHandler(_encoder));
_decoderInstructionParser = new DecoderInstructionParser(new DecoderParserDebugHandler(_decoder));
} }
@Test @Test

View File

@ -14,8 +14,6 @@
package org.eclipse.jetty.http3.qpack; package org.eclipse.jetty.http3.qpack;
import java.nio.ByteBuffer; 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.http3.qpack.internal.parser.EncoderInstructionParser;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
@ -29,40 +27,11 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class EncoderInstructionParserTest public class EncoderInstructionParserTest
{ {
public static class DebugHandler implements EncoderInstructionParser.Handler
{
public Queue<Integer> sectionAcknowledgements = new LinkedList<>();
public Queue<Integer> streamCancellations = new LinkedList<>();
public Queue<Integer> 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 @Test
public void testSectionAcknowledgement() throws Exception public void testSectionAcknowledgement() throws Exception
{ {
DebugHandler debugHandler = new DebugHandler(); EncoderParserDebugHandler debugHandler = new EncoderParserDebugHandler();
EncoderInstructionParser incomingEncoderStream = new EncoderInstructionParser(debugHandler); EncoderInstructionParser incomingEncoderStream = new EncoderInstructionParser(debugHandler);
// Example from the spec, section acknowledgement instruction with stream id 4. // Example from the spec, section acknowledgement instruction with stream id 4.

View File

@ -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<Integer> sectionAcknowledgements = new LinkedList<>();
public Queue<Integer> streamCancellations = new LinkedList<>();
public Queue<Integer> 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();
}
}