Skip to content

Commit

Permalink
Merge pull request #12343 from jetty/jetty-12.0.x-12341-QpackEncoderC…
Browse files Browse the repository at this point in the history
…apacity

Issue #12341 - only send QpackEncoder instructions if change in capacity
  • Loading branch information
lachlan-roberts authored Oct 4, 2024
2 parents 65b3130 + cbfd6b3 commit c2c2735
Show file tree
Hide file tree
Showing 11 changed files with 67 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public int getTableCapacity()
}

/**
* Set the capacity of the DynamicTable and send a instruction to set the capacity on the remote Decoder.
* Set the capacity of the DynamicTable and send an instruction to set the capacity on the remote Decoder.
*
* @param capacity the new capacity.
*/
Expand All @@ -166,9 +166,15 @@ public void setTableCapacity(int capacity)
{
if (capacity > getMaxTableCapacity())
throw new IllegalArgumentException("DynamicTable capacity exceeds max capacity");
_context.getDynamicTable().setCapacity(capacity);
_handler.onInstructions(List.of(new SetCapacityInstruction(capacity)));
notifyInstructionHandler();
int oldCapacity = _context.getDynamicTable().getCapacity();

// Only send the instruction if there was a change to the table capacity.
if (oldCapacity != capacity)
{
_context.getDynamicTable().setCapacity(capacity);
_handler.onInstructions(List.of(new SetCapacityInstruction(capacity)));
notifyInstructionHandler();
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@
import org.eclipse.jetty.http3.qpack.internal.instruction.LiteralNameEntryInstruction;
import org.eclipse.jetty.http3.qpack.internal.instruction.SectionAcknowledgmentInstruction;
import org.eclipse.jetty.http3.qpack.internal.instruction.SetCapacityInstruction;
import org.eclipse.jetty.http3.qpack.util.QpackTestUtil;
import org.eclipse.jetty.http3.qpack.util.TestDecoderHandler;
import org.eclipse.jetty.http3.qpack.util.TestEncoderHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.NanoTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.eclipse.jetty.http3.qpack.QpackTestUtil.encode;
import static org.eclipse.jetty.http3.qpack.QpackTestUtil.toBuffer;
import static org.eclipse.jetty.http3.qpack.QpackTestUtil.toMetaData;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.encode;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.toBuffer;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.toMetaData;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.eclipse.jetty.http3.qpack.internal.instruction.IndexedNameEntryInstruction;
import org.eclipse.jetty.http3.qpack.internal.instruction.SetCapacityInstruction;
import org.eclipse.jetty.http3.qpack.internal.parser.DecoderInstructionParser;
import org.eclipse.jetty.http3.qpack.util.QpackTestUtil;
import org.eclipse.jetty.io.ByteBufferPool;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
import org.eclipse.jetty.http3.qpack.internal.instruction.SetCapacityInstruction;
import org.eclipse.jetty.http3.qpack.internal.parser.DecoderInstructionParser;
import org.eclipse.jetty.http3.qpack.internal.parser.EncoderInstructionParser;
import org.eclipse.jetty.http3.qpack.util.QpackTestUtil;
import org.eclipse.jetty.http3.qpack.util.TestDecoderHandler;
import org.eclipse.jetty.http3.qpack.util.TestEncoderHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.NanoTime;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -155,4 +158,32 @@ public void test() throws Exception
assertThat(QpackTestUtil.toHexString(instruction), QpackTestUtil.equalsHex("4a63 7573 746f 6d2d 6b65 790c 6375 7374 6f6d 2d76 616c 7565"));
_encoder.getInstructionHandler().onInsertCountIncrement(1);
}

@Test
public void testEncoderSetCapacity()
{
_encoder.setMaxTableCapacity(1024 * 1024);

// Since capacity is already 0, this should not produce an instruction.
_encoder.setTableCapacity(0);
Instruction instruction = _encoderHandler.getInstruction();
assertNull(instruction);

// If we change the value of the table an instruction will be produced.
_encoder.setTableCapacity(1024);
instruction = _encoderHandler.getInstruction();
assertThat(instruction, instanceOf(SetCapacityInstruction.class));
assertThat(((SetCapacityInstruction)instruction).getCapacity(), is(1024));

// No instruction since size was already 1024.
_encoder.setTableCapacity(1024);
instruction = _encoderHandler.getInstruction();
assertNull(instruction);

// We can return the size back to 0 and an instruction is sent.
_encoder.setTableCapacity(0);
instruction = _encoderHandler.getInstruction();
assertThat(instruction, instanceOf(SetCapacityInstruction.class));
assertThat(((SetCapacityInstruction)instruction).getCapacity(), is(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.nio.ByteBuffer;

import org.eclipse.jetty.http3.qpack.internal.parser.EncoderInstructionParser;
import org.eclipse.jetty.http3.qpack.util.QpackTestUtil;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
import org.junit.jupiter.api.BeforeEach;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http3.qpack.util.TestDecoderHandler;
import org.eclipse.jetty.http3.qpack.util.TestEncoderHandler;
import org.eclipse.jetty.util.NanoTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http3.qpack.internal.table.Entry;
import org.eclipse.jetty.http3.qpack.util.TestDecoderHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.NanoTime;
import org.eclipse.jetty.util.StringUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,16 @@

import org.eclipse.jetty.http3.qpack.QpackException.SessionException;
import org.eclipse.jetty.http3.qpack.internal.instruction.SectionAcknowledgmentInstruction;
import org.eclipse.jetty.http3.qpack.util.TestDecoderHandler;
import org.eclipse.jetty.http3.qpack.util.TestEncoderHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.NanoTime;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.eclipse.jetty.http3.qpack.QpackTestUtil.encode;
import static org.eclipse.jetty.http3.qpack.QpackTestUtil.toBuffer;
import static org.eclipse.jetty.http3.qpack.QpackTestUtil.toMetaData;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.encode;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.toBuffer;
import static org.eclipse.jetty.http3.qpack.util.QpackTestUtil.toMetaData;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// ========================================================================
//

package org.eclipse.jetty.http3.qpack;
package org.eclipse.jetty.http3.qpack.util;

import java.nio.ByteBuffer;
import java.util.List;
Expand All @@ -21,6 +21,9 @@
import org.eclipse.jetty.http.HttpFields;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http3.qpack.Instruction;
import org.eclipse.jetty.http3.qpack.QpackEncoder;
import org.eclipse.jetty.http3.qpack.QpackException;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.StringUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@
// ========================================================================
//

package org.eclipse.jetty.http3.qpack;
package org.eclipse.jetty.http3.qpack.util;

import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.jetty.http.MetaData;
import org.eclipse.jetty.http3.qpack.Instruction;
import org.eclipse.jetty.http3.qpack.QpackDecoder;

public class TestDecoderHandler implements QpackDecoder.Handler, Instruction.Handler
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
// ========================================================================
//

package org.eclipse.jetty.http3.qpack;
package org.eclipse.jetty.http3.qpack.util;

import java.nio.ByteBuffer;
import java.util.LinkedList;
import java.util.List;

import org.eclipse.jetty.http3.qpack.Instruction;

public class TestEncoderHandler implements Instruction.Handler
{
private final LinkedList<Instruction> _instructionList = new LinkedList<>();
Expand Down

0 comments on commit c2c2735

Please sign in to comment.