8373808: Refactor java/net/httpclient qpack and hpack tests to use JUnit

Reviewed-by: djelinski
This commit is contained in:
Aleksei Efimov 2025-12-23 12:37:34 +00:00
parent e1d81c0946
commit 40755afdf9
31 changed files with 427 additions and 398 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2017, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm/timeout=240 java.net.http/jdk.internal.net.http.hpack.BinaryPrimitivesTest
* @run junit/othervm/timeout=240 java.net.http/jdk.internal.net.http.hpack.BinaryPrimitivesTest
*/
public class HpackBinaryTestDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm java.net.http/jdk.internal.net.http.hpack.CircularBufferTest
* @run junit/othervm java.net.http/jdk.internal.net.http.hpack.CircularBufferTest
*/
public class HpackCircularBufferDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm java.net.http/jdk.internal.net.http.hpack.DecoderTest
* @run junit/othervm java.net.http/jdk.internal.net.http.hpack.DecoderTest
*/
public class HpackDecoderDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm java.net.http/jdk.internal.net.http.hpack.EncoderTest
* @run junit/othervm java.net.http/jdk.internal.net.http.hpack.EncoderTest
*/
public class HpackEncoderDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,6 +30,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm java.net.http/jdk.internal.net.http.hpack.HeaderTableTest
* @run junit/othervm java.net.http/jdk.internal.net.http.hpack.HeaderTableTest
*/
public class HpackHeaderTableDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm/timeout=300 java.net.http/jdk.internal.net.http.hpack.HuffmanTest
* @run junit/othervm/timeout=300 java.net.http/jdk.internal.net.http.hpack.HuffmanTest
*/
public class HpackHuffmanDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -29,6 +29,6 @@
* @compile/module=java.net.http jdk/internal/net/http/hpack/SpecHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/TestHelper.java
* @compile/module=java.net.http jdk/internal/net/http/hpack/BuffersTestingKit.java
* @run testng/othervm java.net.http/jdk.internal.net.http.hpack.TestHelper
* @run junit/othervm java.net.http/jdk.internal.net.http.hpack.TestHelper
*/
public class HpackTestHelperDriver { }

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,6 @@
*/
package jdk.internal.net.http.hpack;
import org.testng.annotations.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
@ -33,10 +32,11 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import static jdk.internal.net.http.hpack.BuffersTestingKit.*;
import static jdk.internal.net.http.hpack.TestHelper.newRandom;
import org.junit.jupiter.api.Test;
//
// Some of the tests below overlap in what they test. This allows to diagnose
@ -96,7 +96,7 @@ public final class BinaryPrimitivesTest {
totalCases++;
maxFilling = Math.max(maxFilling, buf.remaining());
r.reset().configure(N).read(buf);
assertEquals(r.get(), expected);
assertEquals(expected, r.get());
buf.clear();
}
}
@ -127,7 +127,7 @@ public final class BinaryPrimitivesTest {
throw new UncheckedIOException(e);
}
}
assertEquals(r.get(), expected);
assertEquals(expected, r.get());
r.reset();
});
bb.clear();
@ -167,7 +167,7 @@ public final class BinaryPrimitivesTest {
throw new UncheckedIOException(e);
}
// TODO: check payload here
assertEquals(r.get(), expected);
assertEquals(expected, r.get());
w.reset();
r.reset();
bb.clear();
@ -209,7 +209,7 @@ public final class BinaryPrimitivesTest {
bytes.flip();
reader.read(bytes, chars);
chars.flip();
assertEquals(chars.toString(), expected);
assertEquals(expected, chars.toString());
reader.reset();
writer.reset();
}
@ -257,7 +257,7 @@ public final class BinaryPrimitivesTest {
throw new UncheckedIOException(e);
}
chars.flip();
assertEquals(chars.toString(), expected);
assertEquals(expected, chars.toString());
reader.reset();
writer.reset();
chars.clear();
@ -301,7 +301,7 @@ public final class BinaryPrimitivesTest {
buf.position(p0);
}
chars.flip();
assertEquals(chars.toString(), expected);
assertEquals(expected, chars.toString());
reader.reset();
chars.clear();
});
@ -356,7 +356,7 @@ public final class BinaryPrimitivesTest {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
assertEquals(reader.get(), expected);
assertEquals(expected, reader.get());
}
private void verifyWrite(byte[] expected, int data, int N) {
@ -364,6 +364,6 @@ public final class BinaryPrimitivesTest {
ByteBuffer buf = ByteBuffer.allocate(2 * expected.length);
w.configure(data, N, 1).write(buf);
buf.flip();
assertEquals(buf, ByteBuffer.wrap(expected));
assertEquals(ByteBuffer.wrap(expected), buf);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2016, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2016, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,6 @@
*/
package jdk.internal.net.http.hpack;
import org.testng.annotations.Test;
import jdk.internal.net.http.hpack.SimpleHeaderTable.CircularBuffer;
import java.util.Arrays;
@ -31,10 +30,11 @@ import java.util.Random;
import java.util.concurrent.ArrayBlockingQueue;
import static jdk.internal.net.http.common.Utils.pow2Size;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static jdk.internal.net.http.hpack.TestHelper.assertVoidThrows;
import static jdk.internal.net.http.hpack.TestHelper.newRandom;
import static org.testng.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public final class CircularBufferTest {
@ -143,7 +143,7 @@ public final class CircularBufferTest {
for (int i = 0; i < gets; i++) {
Integer expected = referenceQueue.poll();
Integer actual = buffer.remove();
assertEquals(actual, expected);
assertEquals(expected, actual);
}
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,6 @@
*/
package jdk.internal.net.http.hpack;
import org.testng.annotations.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
@ -33,9 +32,9 @@ import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static jdk.internal.net.http.hpack.TestHelper.*;
import org.junit.jupiter.api.Test;
//
// Tests whose names start with "testX" are the ones captured from real HPACK
@ -402,9 +401,9 @@ public final class DecoderTest {
@Test
public void sizeUpdate() throws IOException {
Decoder d = new Decoder(4096);
assertEquals(d.getTable().maxSize(), 4096);
assertEquals(4096, d.getTable().maxSize());
d.decode(ByteBuffer.wrap(new byte[]{0b00111110}), true, nopCallback()); // newSize = 30
assertEquals(d.getTable().maxSize(), 30);
assertEquals(30, d.getTable().maxSize());
}
@Test
@ -650,8 +649,8 @@ public final class DecoderTest {
throw new UncheckedIOException(e);
}
} while (i.hasNext());
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
assertEquals(expectedHeaderTable, d.getTable().getStateString());
assertEquals(expectedHeaderList, actual.stream().collect(Collectors.joining("\n")));
});
// Now introduce last ByteBuffer which is empty and EOF (mimics idiom
@ -690,8 +689,8 @@ public final class DecoderTest {
throw new UncheckedIOException(e);
}
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
assertEquals(expectedHeaderTable, d.getTable().getStateString());
assertEquals(expectedHeaderList, actual.stream().collect(Collectors.joining("\n")));
});
}
@ -717,8 +716,8 @@ public final class DecoderTest {
throw new UncheckedIOException(e);
}
assertEquals(d.getTable().getStateString(), expectedHeaderTable);
assertEquals(actual.stream().collect(Collectors.joining("\n")), expectedHeaderList);
assertEquals(expectedHeaderTable, d.getTable().getStateString());
assertEquals(expectedHeaderList, actual.stream().collect(Collectors.joining("\n")));
}
private static DecodingCallback nopCallback() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,7 +22,6 @@
*/
package jdk.internal.net.http.hpack;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.Buffer;
@ -40,8 +39,9 @@ import static jdk.internal.net.http.hpack.BuffersTestingKit.forEachSplit;
import static jdk.internal.net.http.hpack.SpecHelper.toHexdump;
import static jdk.internal.net.http.hpack.TestHelper.assertVoidThrows;
import static java.util.Arrays.asList;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
// TODO: map textual representation of commands from the spec to actual
// calls to encoder (actually, this is a good idea for decoder as well)
@ -627,10 +627,10 @@ public final class EncoderTest {
String expectedTableState) {
String actualTableState = encoder.getHeaderTable().getStateString();
assertEquals(actualTableState, expectedTableState);
assertEquals(expectedTableState, actualTableState);
String actualHexdump = toHexdump(output);
assertEquals(actualHexdump, expectedHexdump.replaceAll("\\n", " "));
assertEquals(expectedHexdump.replaceAll("\\n", " "), actualHexdump);
}
// initial size - the size encoder is constructed with
@ -657,7 +657,7 @@ public final class EncoderTest {
actual.add(capacity);
}
});
assertEquals(actual, expected);
assertEquals(expected, actual);
}
//

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,15 +23,15 @@
package jdk.internal.net.http.hpack;
import jdk.internal.net.http.hpack.SimpleHeaderTable.HeaderField;
import org.testng.annotations.Test;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import static org.testng.Assert.assertEquals;
import static org.testng.AssertJUnit.assertTrue;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class HeaderTableTest extends SimpleHeaderTableTest {
@ -61,8 +61,8 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
staticHeaderFields.forEach((key, expectedHeaderField) -> {
// lookup
HeaderField actualHeaderField = table.get(key);
assertEquals(actualHeaderField.name, expectedHeaderField.name);
assertEquals(actualHeaderField.value, expectedHeaderField.value);
assertEquals(expectedHeaderField.name, actualHeaderField.name);
assertEquals(expectedHeaderField.value, actualHeaderField.value);
// reverse lookup (name, value)
String hName = expectedHeaderField.name;
@ -70,13 +70,13 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
int expectedIndex = key;
int actualIndex = table.indexOf(hName, hValue);
assertEquals(actualIndex, expectedIndex);
assertEquals(expectedIndex, actualIndex);
// reverse lookup (name)
Set<Integer> expectedIndexes = indexes.get(hName);
int actualMinimalIndex = table.indexOf(hName, "blah-blah");
assertTrue(expectedIndexes.contains(-actualMinimalIndex));
Assertions.assertTrue(expectedIndexes.contains(-actualMinimalIndex));
});
}
@ -88,9 +88,9 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
table.put("bender", "rodriguez");
table.put("bender", "rodriguez");
assertEquals(table.length(), oldLength + 3); // more like an assumption
assertEquals(oldLength + 3, table.length()); // more like an assumption
int i = table.indexOf("bender", "rodriguez");
assertEquals(i, oldLength + 1);
assertEquals(oldLength + 1, i);
}
@Test
@ -98,13 +98,13 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
HeaderTable table = createHeaderTable(256);
int oldLength = table.length();
table.put("bender", "rodriguez");
assertEquals(table.indexOf("bender", "rodriguez"), oldLength + 1);
assertEquals(oldLength + 1, table.indexOf("bender", "rodriguez"));
table.put("bender", "rodriguez");
assertEquals(table.indexOf("bender", "rodriguez"), oldLength + 1);
assertEquals(oldLength + 1, table.indexOf("bender", "rodriguez"));
table.evictEntry();
assertEquals(table.indexOf("bender", "rodriguez"), oldLength + 1);
assertEquals(oldLength + 1, table.indexOf("bender", "rodriguez"));
table.evictEntry();
assertEquals(table.indexOf("bender", "rodriguez"), 0);
assertEquals(0, table.indexOf("bender", "rodriguez"));
}
@Test
@ -114,9 +114,9 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
int idx = rnd.nextInt(oldLength) + 1;
HeaderField f = table.get(idx);
table.put(f.name, f.value);
assertEquals(table.length(), oldLength + 1);
assertEquals(oldLength + 1, table.length());
int i = table.indexOf(f.name, f.value);
assertEquals(i, idx);
assertEquals(idx, i);
}
@Test
@ -137,16 +137,16 @@ public class HeaderTableTest extends SimpleHeaderTableTest {
String s = String.valueOf(j);
int actualIndex = table.indexOf(s, s);
int expectedIndex = STATIC_TABLE_LENGTH + NUM_HEADERS - j + 1;
assertEquals(actualIndex, expectedIndex);
assertEquals(expectedIndex, actualIndex);
}
// as well as for just a name lookup
for (int j = 1; j <= NUM_HEADERS; j++) {
String s = String.valueOf(j);
int actualIndex = table.indexOf(s, "blah");
int expectedIndex = -(STATIC_TABLE_LENGTH + NUM_HEADERS - j + 1);
assertEquals(actualIndex, expectedIndex);
assertEquals(expectedIndex, actualIndex);
}
// lookup for non-existent name returns 0
assertEquals(table.indexOf("chupacabra", "1"), 0);
assertEquals(0, table.indexOf("chupacabra", "1"));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2015, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@ package jdk.internal.net.http.hpack;
import jdk.internal.net.http.hpack.Huffman.Reader;
import jdk.internal.net.http.hpack.Huffman.Writer;
import org.testng.annotations.Test;
import java.io.IOException;
import java.io.UncheckedIOException;
@ -39,8 +38,9 @@ import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static jdk.internal.net.http.hpack.HPACK.bytesForBits;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import org.junit.jupiter.api.Test;
public final class HuffmanTest {
@ -412,8 +412,8 @@ public final class HuffmanTest {
// might not be printable/visible)
int expected = code.sym;
int actual = (int) output.charAt(0);
assertEquals(output.length(), 1); // exactly 1 character
assertEquals(actual, expected);
assertEquals(1, output.length()); // exactly 1 character
assertEquals(expected, actual);
}
}
@ -653,7 +653,7 @@ public final class HuffmanTest {
w.from(str, 0, str.length()).write(buffer);
Reader r = READER.get();
r.read(buffer.flip(), b, true);
assertEquals(b.toString(), str);
assertEquals(str, b.toString());
}
private void roundTrip(int... lengths) throws IOException {
@ -765,7 +765,7 @@ public final class HuffmanTest {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
assertEquals(actual.toString(), decoded);
assertEquals(decoded, actual.toString());
}
private static void readExhaustively(String hexdump, String decoded) {
@ -782,7 +782,7 @@ public final class HuffmanTest {
} catch (IOException e) {
throw new UncheckedIOException(e);
}
assertEquals(actual.toString(), decoded);
assertEquals(decoded, actual.toString());
reader.reset();
actual.setLength(0);
});
@ -796,7 +796,7 @@ public final class HuffmanTest {
boolean written = writer.write(destination);
assertTrue(written);
String actual = SpecHelper.toHexdump(destination.flip());
assertEquals(actual, hexdump);
assertEquals(hexdump, actual);
writer.reset();
}
@ -815,7 +815,7 @@ public final class HuffmanTest {
assertTrue(written);
ByteBuffer concated = BuffersTestingKit.concat(byteBuffers);
String actual = SpecHelper.toHexdump(concated);
assertEquals(actual, hexdump);
assertEquals(hexdump, actual);
writer.reset();
});
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -23,7 +23,6 @@
package jdk.internal.net.http.hpack;
import jdk.internal.net.http.hpack.SimpleHeaderTable.HeaderField;
import org.testng.annotations.Test;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
@ -39,7 +38,8 @@ import static jdk.internal.net.http.hpack.TestHelper.assertThrows;
import static jdk.internal.net.http.hpack.TestHelper.assertVoidThrows;
import static jdk.internal.net.http.hpack.TestHelper.newRandom;
import static java.lang.String.format;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
public class SimpleHeaderTableTest {
@ -125,8 +125,8 @@ public class SimpleHeaderTableTest {
Map<Integer, HeaderField> staticHeaderFields = createStaticEntries();
staticHeaderFields.forEach((index, expectedHeaderField) -> {
SimpleHeaderTable.HeaderField actualHeaderField = table.get(index);
assertEquals(actualHeaderField.name, expectedHeaderField.name);
assertEquals(actualHeaderField.value, expectedHeaderField.value);
assertEquals(expectedHeaderField.name, actualHeaderField.name);
assertEquals(expectedHeaderField.value, actualHeaderField.value);
});
}
@ -134,8 +134,8 @@ public class SimpleHeaderTableTest {
public void constructorSetsMaxSize() {
int size = rnd.nextInt(64);
SimpleHeaderTable table = createHeaderTable(size);
assertEquals(table.size(), 0);
assertEquals(table.maxSize(), size);
assertEquals(0, table.size());
assertEquals(size, table.maxSize());
}
@Test
@ -152,7 +152,7 @@ public class SimpleHeaderTableTest {
public void zeroMaximumSize() {
SimpleHeaderTable table = createHeaderTable(0);
table.setMaxSize(0);
assertEquals(table.maxSize(), 0);
assertEquals(0, table.maxSize());
}
@Test
@ -177,7 +177,7 @@ public class SimpleHeaderTableTest {
@Test
public void length() {
SimpleHeaderTable table = createHeaderTable(0);
assertEquals(table.length(), STATIC_TABLE_LENGTH);
assertEquals(STATIC_TABLE_LENGTH, table.length());
}
@Test
@ -203,14 +203,14 @@ public class SimpleHeaderTableTest {
table.put(name, value);
SimpleHeaderTable.HeaderField f = table.get(idx);
assertEquals(f.name, name);
assertEquals(f.value, value);
assertEquals(name, f.name);
assertEquals(value, f.value);
}
@Test
public void staticTableHasZeroSize() {
SimpleHeaderTable table = createHeaderTable(0);
assertEquals(table.size(), 0);
assertEquals(0, table.size());
}
// TODO: negative indexes check
@ -236,13 +236,13 @@ public class SimpleHeaderTableTest {
SimpleHeaderTable.HeaderField f = table.get(STATIC_TABLE_LENGTH + j);
int actualName = Integer.parseInt(f.name);
int expectedName = NUM_HEADERS - j + 1;
assertEquals(actualName, expectedName);
assertEquals(expectedName, actualName);
}
// Entries MUST be evicted in the order they were added:
// the newer the entry the later it is evicted
for (int k = 1; k <= NUM_HEADERS; k++) {
SimpleHeaderTable.HeaderField f = table.evictEntry();
assertEquals(f.name, String.valueOf(k));
assertEquals(String.valueOf(k), f.name);
}
}
@ -257,7 +257,7 @@ public class SimpleHeaderTableTest {
Locale.setDefault(Locale.FRENCH);
try {
String s = format("%.1f", 3.1);
assertEquals(s, "3,1"); // assumption of the test, otherwise the test is useless
assertEquals("3,1", s); // assumption of the test, otherwise the test is useless
testToString0();
} finally {
Locale.setDefault(locale);
@ -272,7 +272,7 @@ public class SimpleHeaderTableTest {
String expected = format(
"dynamic length: %s, full length: %s, used space: %s/%s (%.1f%%)",
0, STATIC_TABLE_LENGTH, 0, maxSize, 0.0);
assertEquals(table.toString(), expected);
assertEquals(expected, table.toString());
}
{
@ -290,7 +290,7 @@ public class SimpleHeaderTableTest {
String expected = format(
"dynamic length: %s, full length: %s, used space: %s/%s (%.1f%%)",
1, STATIC_TABLE_LENGTH + 1, used, size, ratio);
assertEquals(s, expected);
assertEquals(expected, s);
}
{
@ -301,7 +301,7 @@ public class SimpleHeaderTableTest {
String expected =
format("dynamic length: %s, full length: %s, used space: %s/%s (%.1f%%)",
2, STATIC_TABLE_LENGTH + 2, 78, 78, 100.0);
assertEquals(s, expected);
assertEquals(expected, s);
}
}
@ -310,9 +310,8 @@ public class SimpleHeaderTableTest {
SimpleHeaderTable table = createHeaderTable(256);
table.put("custom-key", "custom-header");
// @formatter:off
assertEquals(table.getStateString(),
"[ 1] (s = 55) custom-key: custom-header\n" +
" Table size: 55");
assertEquals("[ 1] (s = 55) custom-key: custom-header\n" +
" Table size: 55", table.getStateString());
// @formatter:on
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2014, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,10 +22,10 @@
*/
package jdk.internal.net.http.hpack;
import org.testng.annotations.Test;
import java.util.Objects;
import java.util.Random;
import org.junit.jupiter.api.Test;
public final class TestHelper {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,6 @@ import jdk.internal.net.http.http3.frames.SettingsFrame;
import jdk.internal.net.http.qpack.DecodingCallback;
import jdk.internal.net.http.qpack.DynamicTable;
import jdk.internal.net.http.qpack.Encoder;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@ -43,7 +41,9 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import static org.testng.Assert.assertNotEquals;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;
/*
* @test
@ -59,7 +59,7 @@ import static org.testng.Assert.assertNotEquals;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA BlockingDecodingTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA BlockingDecodingTest
*/
@ -94,7 +94,7 @@ public class BlockingDecodingTest {
encoder.header(context, header.name(), header.value(),
false, IGNORE_RECEIVED_COUNT_CHECK);
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -110,8 +110,8 @@ public class BlockingDecodingTest {
// and the default number of blocked streams (0) will be exceeded (1).
var lastHttp3Error = decodingCallback.lastHttp3Error.get();
System.err.println("Last Http3Error: " + lastHttp3Error);
Assert.assertEquals(lastHttp3Error, Http3Error.QPACK_DECOMPRESSION_FAILED);
Assert.assertFalse(decodingCallback.completed.isDone());
Assertions.assertEquals(Http3Error.QPACK_DECOMPRESSION_FAILED, lastHttp3Error);
Assertions.assertFalse(decodingCallback.completed.isDone());
}
@Test
@ -149,7 +149,7 @@ public class BlockingDecodingTest {
encoder.header(context, expectedHeader.name,
expectedHeader.value, false, IGNORE_RECEIVED_COUNT_CHECK);
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -165,12 +165,12 @@ public class BlockingDecodingTest {
// and the default number of blocked streams (0) will be exceeded (1).
var lastHttp3Error = decodingCallback.lastHttp3Error.get();
System.err.println("Last Http3Error: " + lastHttp3Error);
Assert.assertNull(lastHttp3Error);
Assert.assertNull(decodingCallback.lastThrowable.get());
Assert.assertTrue(decodingCallback.completed.isDone());
Assertions.assertNull(lastHttp3Error);
Assertions.assertNull(decodingCallback.lastThrowable.get());
Assertions.assertTrue(decodingCallback.completed.isDone());
// Check that onDecoded was called for the test entry
var decodedHeader = decodingCallback.decodedHeaders.get(0);
Assert.assertEquals(decodedHeader, expectedHeader);
Assertions.assertEquals(expectedHeader, decodedHeader);
}
@Test
@ -224,7 +224,7 @@ public class BlockingDecodingTest {
IGNORE_RECEIVED_COUNT_CHECK);
headerFrameWriter.write(headersBb);
}
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -261,13 +261,13 @@ public class BlockingDecodingTest {
// Check results of each decoding task
for (var decodingResultFuture : decodingTaskResults) {
var taskCallback = decodingResultFuture.get();
Assert.assertNull(taskCallback.lastHttp3Error.get());
Assert.assertNull(taskCallback.lastThrowable.get());
Assertions.assertNull(taskCallback.lastHttp3Error.get());
Assertions.assertNull(taskCallback.lastThrowable.get());
long decodingTaskCompleted = taskCallback.completedTimestamp.get();
System.err.println("Decoding task completion timestamp: " + decodingTaskCompleted);
Assert.assertTrue(decodingTaskCompleted >= updateDoneTimeStamp);
Assertions.assertTrue(decodingTaskCompleted >= updateDoneTimeStamp);
var decodedHeaders = taskCallback.decodedHeaders;
Assert.assertEquals(decodedHeaders, expectedHeaders);
Assertions.assertEquals(expectedHeaders, decodedHeaders);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -37,7 +37,7 @@
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL
* DecoderSectionSizeLimitTest
*/
@ -48,18 +48,21 @@ import jdk.internal.net.http.qpack.DecodingCallback;
import jdk.internal.net.http.qpack.DynamicTable;
import jdk.internal.net.http.qpack.Encoder;
import jdk.test.lib.RandomFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DecoderSectionSizeLimitTest {
@Test(dataProvider = "headerSequences")
@ParameterizedTest
@MethodSource("headerSequences")
public void fieldSectionSizeLimitExceeded(List<TestHeader> headersSequence,
long maxFieldSectionSize) {
@ -144,21 +147,20 @@ public class DecoderSectionSizeLimitTest {
System.err.printf("Decoding error observed during buffer #%d processing: %s throwable: %s%n",
bufferIdx, decodingError, decodingCallback.lastThrowable.get());
if (decoderErrorExpected) {
Assert.assertEquals(decodingError, Http3Error.QPACK_DECOMPRESSION_FAILED);
Assertions.assertEquals(Http3Error.QPACK_DECOMPRESSION_FAILED, decodingError);
return;
} else {
Assert.fail("No HTTP/3 error was expected");
Assertions.fail("No HTTP/3 error was expected");
}
} else {
System.err.println("Buffer #" + bufferIdx + " readout completed without errors");
}
}
if (decoderErrorExpected) {
Assert.fail("HTTP/3 error was expected but was not observed");
Assertions.fail("HTTP/3 error was expected but was not observed");
}
}
@DataProvider
public Object[][] headerSequences() {
List<Object[]> testCases = new ArrayList<>();
for (var sequence : generateHeaderSequences()) {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -31,8 +31,6 @@ import jdk.internal.net.http.qpack.readers.HeaderFrameReader;
import jdk.internal.net.http.qpack.writers.IntegerWriter;
import jdk.internal.net.http.qpack.StaticTable;
import jdk.internal.net.http.qpack.writers.StringWriter;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -40,7 +38,11 @@ import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Consumer;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -51,8 +53,9 @@ import static org.testng.Assert.*;
* java.net.http/jdk.internal.net.http.http3.streams
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @run testng/othervm DecoderTest
* @run junit/othervm DecoderTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DecoderTest {
private final Random random = new Random();
@ -78,7 +81,6 @@ public class DecoderTest {
return null;
}
@DataProvider(name = "indexProvider")
public Object[][] indexProvider() {
AtomicInteger tableIndex = new AtomicInteger();
return StaticTable.HTTP3_HEADER_FIELDS.stream()
@ -87,7 +89,6 @@ public class DecoderTest {
.toArray(Object[][]::new);
}
@DataProvider(name = "nameReferenceProvider")
public Object[][] nameReferenceProvider() {
AtomicInteger tableIndex = new AtomicInteger();
return StaticTable.HTTP3_HEADER_FIELDS.stream()
@ -95,7 +96,6 @@ public class DecoderTest {
.map(List::toArray).toArray(Object[][]::new);
}
@DataProvider(name = "literalProvider")
public Object[][] literalProvider() {
var output = new String[100][];
for (int i = 0; i < 100; i++) {
@ -104,7 +104,8 @@ public class DecoderTest {
return output;
}
@Test(dataProvider = "indexProvider")
@ParameterizedTest
@MethodSource("indexProvider")
public void testIndexedOnStaticTable(int index, HeaderField h) throws IOException {
var actual = writeIndex(index);
var callback = new TestingCallBack(index, h.name(), h.value());
@ -112,7 +113,8 @@ public class DecoderTest {
dr.decoder().decodeHeader(actual, true, dr.reader());
}
@Test(dataProvider = "nameReferenceProvider")
@ParameterizedTest
@MethodSource("nameReferenceProvider")
public void testLiteralWithNameReferenceOnStaticTable(int index, String name, String value) throws IOException {
boolean sensitive = random.nextBoolean();
@ -122,7 +124,8 @@ public class DecoderTest {
dr.decoder().decodeHeader(actual, true, dr.reader());
}
@Test(dataProvider = "literalProvider")
@ParameterizedTest
@MethodSource("literalProvider")
public void testLiteralWithLiteralNameOnStaticTable(String name, String value) throws IOException {
boolean sensitive = random.nextBoolean();
@ -345,30 +348,30 @@ public class DecoderTest {
@Override
public void onIndexed(long index, CharSequence name, CharSequence value) {
assertEquals(this.index, index);
assertEquals(this.name, name.toString());
assertEquals(this.value, value.toString());
assertEquals(index, this.index);
assertEquals(name.toString(), this.name);
assertEquals(value.toString(), this.value);
}
@Override
public void onLiteralWithNameReference(long index, CharSequence name,
CharSequence value, boolean huffmanValue,
boolean sensitive) {
assertEquals(this.index, index);
assertEquals(this.value, value.toString());
assertEquals(this.huffmanValue, huffmanValue);
assertEquals(this.sensitive, sensitive);
assertEquals(index, this.index);
assertEquals(value.toString(), this.value);
assertEquals(huffmanValue, this.huffmanValue);
assertEquals(sensitive, this.sensitive);
}
@Override
public void onLiteralWithLiteralName(CharSequence name, boolean huffmanName,
CharSequence value, boolean huffmanValue,
boolean sensitive) {
assertEquals(this.name, name.toString());
assertEquals(this.huffmanName, huffmanName);
assertEquals(this.value, value.toString());
assertEquals(this.huffmanValue, huffmanValue);
assertEquals(this.sensitive, sensitive);
assertEquals(name.toString(), this.name);
assertEquals(huffmanName, this.huffmanName);
assertEquals(value.toString(), this.value);
assertEquals(huffmanValue, this.huffmanValue);
assertEquals(sensitive, this.sensitive);
}
@Override

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -28,7 +28,6 @@ import jdk.internal.net.http.qpack.DecodingCallback;
import jdk.internal.net.http.qpack.DynamicTable;
import jdk.internal.net.http.qpack.Encoder;
import jdk.test.lib.RandomFactory;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -37,7 +36,8 @@ import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicReference;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.Test;
/*
* @test
@ -55,7 +55,7 @@ import static org.testng.Assert.*;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA
* -Djdk.http.qpack.allowBlockingEncoding=true
* -Djdk.http.qpack.decoderBlockedStreams=4
* DynamicTableFieldLineRepresentationTest
@ -105,7 +105,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Write the header
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -115,7 +115,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Decode headers
decoder.decodeHeader(buffers.get(0), false, headerFrameReader);
decoder.decodeHeader(buffers.get(1), true, headerFrameReader);
assertEquals(callback.lastIndexedName,name);
assertEquals(name, callback.lastIndexedName);
}
//4.5.3. Indexed Field Line with Post-Base Index
@ -160,7 +160,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Write the header
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -170,8 +170,8 @@ public class DynamicTableFieldLineRepresentationTest {
// Decode headers
decoder.decodeHeader(buffers.get(0), false, headerFrameReader);
decoder.decodeHeader(buffers.get(1), true, headerFrameReader);
assertEquals(callback.lastIndexedName,name);
assertEquals(callback.lastValue,value);
assertEquals(name, callback.lastIndexedName);
assertEquals(value, callback.lastValue);
}
// 4.5.4. Literal Field Line with Name Reference
@ -221,7 +221,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Write the header
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -231,7 +231,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Decode headers
decoder.decodeHeader(buffers.get(0), false, headerFrameReader);
decoder.decodeHeader(buffers.get(1), true, headerFrameReader);
assertEquals(callback.lastReferenceName, name);
assertEquals(name, callback.lastReferenceName);
}
//4.5.5. Literal Field Line with Post-Base Name Reference
@ -276,7 +276,7 @@ public class DynamicTableFieldLineRepresentationTest {
// Write the header
headerFrameWriter.write(headersBb);
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -286,8 +286,8 @@ public class DynamicTableFieldLineRepresentationTest {
// Decode headers
decoder.decodeHeader(buffers.get(0), false, headerFrameReader);
decoder.decodeHeader(buffers.get(1), true, headerFrameReader);
assertEquals(callback.lastReferenceName, name);
assertEquals(callback.lastValue, value);
assertEquals(name, callback.lastReferenceName);
assertEquals(value, callback.lastValue);
}
private void configureConnector(EncoderDecoderConnector.EncoderDecoderPair connector, int numberOfEntries){
@ -362,8 +362,8 @@ public class DynamicTableFieldLineRepresentationTest {
@Override
public void onIndexed(long actualIndex, CharSequence actualName, CharSequence actualValue) {
System.out.println("Indexed called");
assertEquals(actualName, name);
assertEquals(actualValue, value);
assertEquals(name, actualName);
assertEquals(value, actualValue);
lastValue = value;
lastIndexedName = name;
}
@ -375,8 +375,8 @@ public class DynamicTableFieldLineRepresentationTest {
boolean valueHuffman,
boolean hideIntermediary) {
System.out.println("Literal with name reference called");
assertEquals(actualName.toString(), name);
assertEquals(actualValue.toString(), value);
assertEquals(name, actualName.toString());
assertEquals(value, actualValue.toString());
lastReferenceName = name;
lastValue = value;
}
@ -386,8 +386,8 @@ public class DynamicTableFieldLineRepresentationTest {
CharSequence actualValue, boolean valueHuffman,
boolean hideIntermediary) {
System.out.println("Literal with literal name called");
assertEquals(actualName.toString(), name);
assertEquals(actualValue.toString(), value);
assertEquals(name, actualName.toString());
assertEquals(value, actualValue.toString());
lastLiteralName = name;
lastValue = value;
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,7 +27,7 @@
* @library /test/lib
* @modules java.net.http/jdk.internal.net.http.qpack:+open
* java.net.http/jdk.internal.net.http.qpack.readers
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL DynamicTableTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL DynamicTableTest
*/
import jdk.internal.net.http.qpack.DynamicTable;
@ -35,9 +35,6 @@ import jdk.internal.net.http.qpack.HeaderField;
import jdk.internal.net.http.qpack.QPACK;
import jdk.internal.net.http.qpack.readers.IntegerReader;
import jdk.test.lib.RandomFactory;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
@ -47,7 +44,13 @@ import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class DynamicTableTest {
// Test for addition to the table and that indices are growing monotonically,
@ -74,7 +77,7 @@ public class DynamicTableTest {
long addedId = dynamicTable.insert(name, value);
// Check that dynamic table put gives back monotonically increasing indexes
Assert.assertEquals(addedId, lastAddedId);
Assertions.assertEquals(lastAddedId, addedId);
if (lastAddedId > maxElementsInTable) {
// Check that oldest element is available and not reclaimed
@ -98,21 +101,21 @@ public class DynamicTableTest {
long onlyNameSearchResult = dynamicTable.search(rName, "notFoundInTable");
long noMatchResult = dynamicTable.search(HEADER_NAME_PREFIX, HEADER_VALUE_PREFIX);
Assert.assertEquals(fullMatchSearchResult - 1, rid);
Assert.assertEquals(-onlyNameSearchResult - 1, rid);
Assert.assertEquals(noMatchResult, 0);
Assertions.assertEquals(rid, fullMatchSearchResult - 1);
Assertions.assertEquals(rid, -onlyNameSearchResult - 1);
Assertions.assertEquals(0, noMatchResult);
}
}
}
@Test(dataProvider = "randomTableResizeData")
@ParameterizedTest
@MethodSource("randomTableResizeData")
public void randomTableResize(int initialSize, long tail, long head, int resizeTo)
throws Throwable {
HeaderField[] initial = generateHeadersArray(initialSize, tail, head);
resizeTestRunner(initial, tail, head, resizeTo);
}
@DataProvider
public Object[][] randomTableResizeData() {
return IntStream.range(0, 1000)
.boxed()
@ -127,31 +130,29 @@ public class DynamicTableTest {
var dynamicTable = new DynamicTable(QPACK.getLogger().subLogger("tableResizeTests"));
// Check that the initial array length is DynamicTable.INITIAL_HOLDER_ARRAY_SIZE
Assert.assertEquals(getElementsArrayLength(dynamicTable),
INITIAL_HOLDER_ARRAY_SIZE);
Assertions.assertEquals( INITIAL_HOLDER_ARRAY_SIZE, getElementsArrayLength(dynamicTable));
// Update dynamic table capacity to maximum allowed value and check
// that holder array is not changed
dynamicTable.setMaxTableCapacity(IntegerReader.QPACK_MAX_INTEGER_VALUE);
dynamicTable.setCapacity(IntegerReader.QPACK_MAX_INTEGER_VALUE);
Assert.assertEquals(getElementsArrayLength(dynamicTable),
INITIAL_HOLDER_ARRAY_SIZE);
Assertions.assertEquals( INITIAL_HOLDER_ARRAY_SIZE, getElementsArrayLength(dynamicTable));
// Add DynamicTable.INITIAL_HOLDER_ARRAY_SIZE + 1 element to the dynamic table
// and check that its length is increased 2 times
for (int i = 0; i <= INITIAL_HOLDER_ARRAY_SIZE; i++) {
dynamicTable.insert("name" + i, "value" + i);
}
Assert.assertEquals(getElementsArrayLength(dynamicTable), INITIAL_HOLDER_ARRAY_SIZE << 1);
Assertions.assertEquals(INITIAL_HOLDER_ARRAY_SIZE << 1, getElementsArrayLength(dynamicTable));
}
// Test for a simple resize that checks that unique indexes still reference the correct entry
@Test(dataProvider = "simpleTableResizeData")
@ParameterizedTest
@MethodSource("simpleTableResizeData")
public void simpleTableResize(HeaderField[] array, long tail, long head, int resizeTo) throws Throwable {
resizeTestRunner(array, tail, head, resizeTo);
}
@DataProvider
public Object[][] simpleTableResizeData() {
return new Object[][]{
tableResizeScenario1(), tableResizeScenario2(),
@ -270,13 +271,13 @@ public class DynamicTableTest {
}
private static void checkResizeResult(HeaderField[] initial, HeaderField[] resized, HeaderField[] expected) {
Assert.assertEquals(resized.length, expected.length);
Assertions.assertEquals(expected.length, resized.length);
for (int index = 0; index < expected.length; index++) {
if (!sameHeaderField(expected[index], resized[index])) {
System.err.println("Initial Array:" + Arrays.deepToString(initial));
System.err.println("Resized Array:" + Arrays.deepToString(resized));
System.err.println("Expected Array:" + Arrays.deepToString(expected));
Assert.fail("DynamicTable.resize failed");
Assertions.fail("DynamicTable.resize failed");
}
}
}
@ -299,7 +300,7 @@ public class DynamicTableTest {
MethodType mt = MethodType.methodType(void.class, int.class);
return DT_LOOKUP.findVirtual(DynamicTable.class, "resize", mt);
} catch (Exception e) {
Assert.fail("Failed to initialize DynamicTable.resize MH", e);
Assertions.fail("Failed to initialize DynamicTable.resize MH", e);
return null;
}
}
@ -308,7 +309,7 @@ public class DynamicTableTest {
try {
return DT_LOOKUP.findVarHandle(DynamicTable.class, fieldName, fieldType);
} catch (Exception e) {
Assert.fail("Failed to initialize DynamicTable private Lookup instance", e);
Assertions.fail("Failed to initialize DynamicTable private Lookup instance", e);
return null;
}
}
@ -318,7 +319,7 @@ public class DynamicTableTest {
var vh = DT_LOOKUP.findStaticVarHandle(DynamicTable.class, fieldName, fieldType);
return (T) vh.get();
} catch (Exception e) {
Assert.fail("Failed to read DynamicTable static field value", e);
Assertions.fail("Failed to read DynamicTable static field value", e);
return null;
}
}
@ -327,7 +328,7 @@ public class DynamicTableTest {
try {
return MethodHandles.privateLookupIn(DynamicTable.class, MethodHandles.lookup());
} catch (IllegalAccessException e) {
Assert.fail("Failed to initialize DynamicTable private Lookup instance", e);
Assertions.fail("Failed to initialize DynamicTable private Lookup instance", e);
return null;
}
}

View File

@ -27,12 +27,12 @@ import jdk.internal.net.http.http3.frames.SettingsFrame;
import jdk.internal.net.http.qpack.TableEntry;
import jdk.internal.net.http.qpack.writers.EncoderInstructionsWriter;
import jdk.internal.net.http.qpack.writers.HeaderFrameWriter;
import org.testng.Assert;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
/*
* @test
@ -48,7 +48,7 @@ import java.util.concurrent.atomic.AtomicReference;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA
* EncoderDecoderConnectionTest
*/
public class EncoderDecoderConnectionTest {
@ -77,17 +77,17 @@ public class EncoderDecoderConnectionTest {
encoder.setTableCapacity(capacityToSet);
// Check that no errors observed
Assert.assertNull(encoderErrorHandler.error.get());
Assert.assertNull(encoderErrorHandler.http3Error.get());
Assert.assertNull(decoderErrorHandler.error.get());
Assert.assertNull(decoderErrorHandler.http3Error.get());
Assertions.assertNull(encoderErrorHandler.error.get());
Assertions.assertNull(encoderErrorHandler.http3Error.get());
Assertions.assertNull(decoderErrorHandler.error.get());
Assertions.assertNull(decoderErrorHandler.http3Error.get());
// Check that encoder's table capacity is updated
Assert.assertEquals(conn.encoderTable().capacity(), capacityToSet);
Assertions.assertEquals(capacityToSet, conn.encoderTable().capacity());
// Since encoder/decoder streams are cross-wired we expect see dynamic
// table capacity updated for the decoder too
Assert.assertEquals(conn.decoderTable().capacity(),
conn.encoderTable().capacity());
Assertions.assertEquals(conn.encoderTable().capacity(),
conn.decoderTable().capacity());
}
@Test
@ -122,10 +122,10 @@ public class EncoderDecoderConnectionTest {
var encoderInstructionWriter = new EncoderInstructionsWriter();
// Check that no errors observed
Assert.assertNull(encoderErrorHandler.error.get());
Assert.assertNull(encoderErrorHandler.http3Error.get());
Assert.assertNull(decoderErrorHandler.error.get());
Assert.assertNull(decoderErrorHandler.http3Error.get());
Assertions.assertNull(encoderErrorHandler.error.get());
Assertions.assertNull(encoderErrorHandler.http3Error.get());
Assertions.assertNull(decoderErrorHandler.error.get());
Assertions.assertNull(decoderErrorHandler.http3Error.get());
// Issue the insert instruction on encoder stream
conn.encoderTable().insertWithEncoderStreamUpdate(entryToInsert,
@ -133,8 +133,8 @@ public class EncoderDecoderConnectionTest {
encoder.newEncodingContext(0, 0, new HeaderFrameWriter()));
var encoderHeader = conn.encoderTable().get(0);
var decoderHeader = conn.decoderTable().get(0);
Assert.assertEquals(encoderHeader.name(), decoderHeader.name());
Assert.assertEquals(encoderHeader.value(), decoderHeader.value());
Assertions.assertEquals(decoderHeader.name(), encoderHeader.name());
Assertions.assertEquals(decoderHeader.value(), encoderHeader.value());
}
@Test
@ -160,12 +160,12 @@ public class EncoderDecoderConnectionTest {
// QPACK_ENCODER_STREAM_ERROR is expected on the decoder side
// since the decoder dynamic table capacity was not updated
Assert.assertEquals(decoderErrorHandler.http3Error.get(),
Http3Error.QPACK_ENCODER_STREAM_ERROR);
Assertions.assertEquals(Http3Error.QPACK_ENCODER_STREAM_ERROR,
decoderErrorHandler.http3Error.get());
// It is expected that http3 error reported to
// the decoder error handler only
Assert.assertNull(encoderErrorHandler.http3Error.get());
Assertions.assertNull(encoderErrorHandler.http3Error.get());
}
@Test
@ -208,13 +208,13 @@ public class EncoderDecoderConnectionTest {
System.err.println("Decoder Http3 error: " + decoderHttp3Error);
if (encoderError == null || !(encoderError instanceof IOException)) {
Assert.fail("Incorrect encoder error type", encoderError);
Assertions.fail("Incorrect encoder error type", encoderError);
}
if (decoderError == null || !(decoderError instanceof IOException)) {
Assert.fail("Incorrect decoder error type", decoderError);
Assertions.fail("Incorrect decoder error type", decoderError);
}
Assert.assertEquals(encoderHttp3Error, Http3Error.QPACK_DECODER_STREAM_ERROR);
Assert.assertEquals(decoderHttp3Error, Http3Error.QPACK_ENCODER_STREAM_ERROR);
Assertions.assertEquals(Http3Error.QPACK_DECODER_STREAM_ERROR, encoderHttp3Error);
Assertions.assertEquals(Http3Error.QPACK_ENCODER_STREAM_ERROR, decoderHttp3Error);
}
private static ByteBuffer instructionWithOverflowInteger(int N, int payload) {

View File

@ -44,7 +44,6 @@ import jdk.internal.net.http.quic.streams.QuicSenderStream;
import jdk.internal.net.http.quic.streams.QuicStream;
import jdk.internal.net.http.quic.streams.QuicStreamWriter;
import jdk.internal.net.quic.QuicTLSEngine;
import org.testng.Assert;
import java.io.IOException;
import java.lang.invoke.MethodHandles;
@ -58,6 +57,7 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
/**
* Instance of this class provides a stubbed Quic Connection implementation that
@ -175,7 +175,7 @@ public class EncoderDecoderConnector {
try {
return MethodHandles.privateLookupIn(clz, MethodHandles.lookup());
} catch (IllegalAccessException e) {
Assert.fail("Failed to initialize private Lookup instance", e);
Assertions.fail("Failed to initialize private Lookup instance", e);
return null;
}
}
@ -185,7 +185,7 @@ public class EncoderDecoderConnector {
try {
return lookup.findVarHandle(recv, "dynamicTable", DynamicTable.class);
} catch (Exception e) {
Assert.fail("Failed to acquire dynamic table VarHandle instance", e);
Assertions.fail("Failed to acquire dynamic table VarHandle instance", e);
return null;
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -27,8 +27,6 @@ import jdk.internal.net.http.qpack.Encoder;
import jdk.internal.net.http.qpack.HeaderField;
import jdk.internal.net.http.hpack.QuickHuffman;
import jdk.internal.net.http.qpack.StaticTable;
import org.testng.annotations.Test;
import org.testng.annotations.DataProvider;
import java.io.IOException;
import java.nio.ByteBuffer;
@ -41,10 +39,13 @@ import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertNotEquals;
import static org.testng.Assert.assertTrue;
import static org.testng.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -60,8 +61,9 @@ import static org.testng.Assert.fail;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm EncoderDecoderTest
* @run junit/othervm EncoderDecoderTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class EncoderDecoderTest {
private final Random random = new Random();
@ -72,7 +74,6 @@ public class EncoderDecoderTest {
fail(http3Error + "QPACK error:" + http3Error, error);
}
@DataProvider(name = "indexProvider")
public Object[][] indexProvider() {
AtomicLong index = new AtomicLong();
return StaticTable.HTTP3_HEADER_FIELDS.stream()
@ -81,7 +82,6 @@ public class EncoderDecoderTest {
.toArray(Object[][]::new);
}
@DataProvider(name = "nameReferenceProvider")
public Object[][] nameReferenceProvider() {
AtomicLong tableIndex = new AtomicLong();
Map<String, List<Long>> map = new HashMap<>();
@ -98,7 +98,6 @@ public class EncoderDecoderTest {
.map(List::toArray).toArray(Object[][]::new);
}
@DataProvider(name = "literalProvider")
public Object[][] literalProvider() {
var output = new String[100][];
for (int i = 0; i < 100; i++) {
@ -112,7 +111,8 @@ public class EncoderDecoderTest {
if (error != null) throw new AssertionError(error);
}
@Test(dataProvider = "indexProvider")
@ParameterizedTest
@MethodSource("indexProvider")
public void encodeDecodeIndexedOnStaticTable(long index, HeaderField h) throws IOException {
var actual = allocateIndexTestBuffer(index);
List<ByteBuffer> buffers = new ArrayList<>();
@ -148,7 +148,7 @@ public class EncoderDecoderTest {
// Write the header
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
buffers.add(actual);
@ -161,7 +161,8 @@ public class EncoderDecoderTest {
assertNotFailed(error);
}
@Test(dataProvider = "nameReferenceProvider")
@ParameterizedTest
@MethodSource("nameReferenceProvider")
public void encodeDecodeLiteralWithNameRefOnStaticTable(String name, String value, List<Long> validIndices) throws IOException {
long index = Collections.max(validIndices);
boolean sensitive = random.nextBoolean();
@ -194,7 +195,7 @@ public class EncoderDecoderTest {
// Write the header
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
buffers.add(actual);
@ -207,7 +208,8 @@ public class EncoderDecoderTest {
assertNotFailed(error);
}
@Test(dataProvider = "literalProvider")
@ParameterizedTest
@MethodSource("literalProvider")
public void encodeDecodeLiteralWithLiteralNameOnStaticTable(String name, String value) throws IOException {
boolean sensitive = random.nextBoolean();
List<ByteBuffer> buffers = new ArrayList<>();
@ -237,7 +239,7 @@ public class EncoderDecoderTest {
encoder.header(context, name, value, sensitive);
// Write the header
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
buffers.add(actual);
@ -412,9 +414,9 @@ public class EncoderDecoderTest {
@Override
public void onIndexed(long actualIndex, CharSequence actualName, CharSequence actualValue) {
assertEquals(actualIndex, index);
assertEquals(actualName, name);
assertEquals(actualValue, value);
assertEquals(index, actualIndex);
assertEquals(name, actualName);
assertEquals(value, actualValue);
}
@Override
@ -422,21 +424,21 @@ public class EncoderDecoderTest {
CharSequence actualValue, boolean huffmanValue,
boolean actualHideIntermediary) {
assertTrue(validIndices.contains(actualIndex));
assertEquals(actualName.toString(), name);
assertEquals(actualValue.toString(), value);
assertEquals(name, actualName.toString());
assertEquals(value, actualValue.toString());
assertEquals(huffmanValue, huffmanValue);
assertEquals(actualHideIntermediary, sensitive);
assertEquals(sensitive, actualHideIntermediary);
}
@Override
public void onLiteralWithLiteralName(CharSequence actualName, boolean actualHuffmanName,
CharSequence actualValue, boolean actualHuffmanValue,
boolean actualHideIntermediary) {
assertEquals(actualName.toString(), name);
assertEquals(actualHuffmanName, huffmanName);
assertEquals(actualValue.toString(), value);
assertEquals(actualHuffmanValue, huffmanValue);
assertEquals(actualHideIntermediary, sensitive);
assertEquals(name, actualName.toString());
assertEquals(huffmanName, actualHuffmanName);
assertEquals(value, actualValue.toString());
assertEquals(huffmanValue, actualHuffmanValue);
assertEquals(sensitive, actualHideIntermediary);
}
}
}

View File

@ -46,8 +46,6 @@ import jdk.internal.net.http.quic.streams.QuicSenderStream.SendingStreamState;
import jdk.internal.net.http.quic.streams.QuicStream;
import jdk.internal.net.http.quic.streams.QuicStreamWriter;
import jdk.internal.net.quic.QuicTLSEngine;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.InetSocketAddress;
@ -69,7 +67,10 @@ import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Stream;
import static org.testng.Assert.*;
import static org.junit.jupiter.api.Assertions.*;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -84,15 +85,15 @@ import static org.testng.Assert.*;
* java.net.http/jdk.internal.net.http.http3.streams
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @run testng/othervm EncoderTest
* @run junit/othervm EncoderTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class EncoderTest {
private final Random random = new Random();
private final IntegerWriter intWriter = new IntegerWriter();
private final StringWriter stringWriter = new StringWriter();
private static final int TEST_STR_MAX_LENGTH = 10;
@DataProvider(name = "indexProvider")
public Object[][] indexProvider() {
AtomicInteger tableIndex = new AtomicInteger();
return StaticTable.HTTP3_HEADER_FIELDS.stream()
@ -101,7 +102,6 @@ public class EncoderTest {
.toArray(Object[][]::new);
}
@DataProvider
public Object[][] staticNameReferenceProvider() {
AtomicInteger tableIndex = new AtomicInteger();
Map<String, List<Integer>> map = new HashMap<>();
@ -117,7 +117,6 @@ public class EncoderTest {
.map(List::toArray).toArray(Object[][]::new);
}
@DataProvider
public Object[][] literalsProvider() {
var output = new String[100][];
for (int i = 0; i < 100; i++) {
@ -161,7 +160,8 @@ public class EncoderTest {
fail(http3Error + "QPACK error:" + http3Error, error);
}
@Test(dataProvider = "indexProvider")
@ParameterizedTest
@MethodSource("indexProvider")
public void testFieldLineWriterWithStaticIndex(int index, HeaderField h) {
var actual = allocateIndexBuffer(index);
var expected = writeIndex(index);
@ -177,14 +177,15 @@ public class EncoderTest {
encoder.header(context, h.name(), h.value(), false);
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
assertEquals(actual, expected, debug(h.name(), h.value(), actual, expected));
assertEquals(expected, actual, debug(h.name(), h.value(), actual, expected));
assertNotFailed(error);
}
@Test(dataProvider = "staticNameReferenceProvider")
@ParameterizedTest
@MethodSource("staticNameReferenceProvider")
public void testInsertWithStaticTableNameReference(String name, String value, List<Integer> validIndices) {
int index = Collections.max(validIndices);
@ -203,7 +204,7 @@ public class EncoderTest {
encoder.newEncodingContext(0, 0, headerFrameWriter);
encoder.header(context, name, value, false);
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
TestQuicStreamWriter quicStreamWriter = quicConnection.sender.writer;
@ -212,7 +213,8 @@ public class EncoderTest {
assertNotFailed(error);
}
@Test(dataProvider = "staticNameReferenceProvider")
@ParameterizedTest
@MethodSource("staticNameReferenceProvider")
public void testFieldLineWithStaticTableNameReference(String name, String value, List<Integer> validIndices) {
int index = Collections.max(validIndices);
boolean sensitive = random.nextBoolean();
@ -231,14 +233,15 @@ public class EncoderTest {
encoder.newEncodingContext(0, 0, headerFrameWriter);
encoder.header(context, name, value, sensitive);
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
assertTrue(expected.contains(actual), debug(name, value, actual, expected));
assertNotFailed(error);
}
@Test(dataProvider = "literalsProvider")
@ParameterizedTest
@MethodSource("literalsProvider")
public void testInsertWithLiterals(String name, String value) {
var expected = writeInsertLiteral(name, value);
var actual = allocateInsertLiteralBuffer(name, value);
@ -255,14 +258,15 @@ public class EncoderTest {
encoder.newEncodingContext(0, 0, headerFrameWriter);
encoder.header(context, name, value, false);
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
TestQuicStreamWriter quicStreamWriter = quicConnection.sender.writer;
assertEquals(quicStreamWriter.get(), expected, debug(name, value, quicStreamWriter.get(), expected));
assertEquals(expected, quicStreamWriter.get(), debug(name, value, quicStreamWriter.get(), expected));
assertNotFailed(error);
}
@Test(dataProvider = "literalsProvider")
@ParameterizedTest
@MethodSource("literalsProvider")
public void testFieldLineEncodingWithLiterals(String name, String value) {
boolean sensitive = random.nextBoolean();
@ -280,10 +284,10 @@ public class EncoderTest {
encoder.newEncodingContext(0, 0, headerFrameWriter);
encoder.header(context, name, value, sensitive);
headerFrameWriter.write(actual);
assertNotEquals(actual.position(), 0);
assertNotEquals(0, actual.position());
actual.flip();
assertEquals(actual, expected, debug(name, value, actual, expected));
assertEquals(expected, actual, debug(name, value, actual, expected));
assertNotFailed(error);
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -35,7 +35,7 @@
* java.net.http/jdk.internal.net.http.http3.streams
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA EntriesEvictionTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA EntriesEvictionTest
*/
import java.util.ArrayList;
@ -47,13 +47,16 @@ import jdk.internal.net.http.qpack.Encoder.SectionReference;
import jdk.internal.net.http.qpack.HeaderField;
import jdk.internal.net.http.qpack.QPACK;
import jdk.internal.net.http.qpack.QPACK.Logger;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class EntriesEvictionTest {
@Test(dataProvider = "evictionScenarios")
@ParameterizedTest
@MethodSource("evictionScenarios")
public void evictionInsertionTest(TestHeader headerToAdd,
SectionReference sectionReference,
long insertedId,
@ -71,12 +74,12 @@ public class EntriesEvictionTest {
// Insert last entry
long id = dynamicTable.insert(headerToAdd.name, headerToAdd.value, sectionReference);
Assert.assertEquals(id, insertedId);
Assertions.assertEquals(insertedId, id);
if (largestEvictedId != -1) {
// Check that evicted entry with the largest absolute index
// is not accessible
Assert.assertThrows(() -> dynamicTable.get(largestEvictedId));
Assertions.assertThrows(Throwable.class, () -> dynamicTable.get(largestEvictedId));
// Check that an entry after that can be acquired with its
// absolute index
dynamicTable.get(largestEvictedId + 1);
@ -84,12 +87,11 @@ public class EntriesEvictionTest {
if (insertedId != -1) {
HeaderField insertedField = dynamicTable.get(insertedId);
Assert.assertEquals(insertedField,
new HeaderField(headerToAdd.name(), headerToAdd.value()));
Assertions.assertEquals(new HeaderField(headerToAdd.name(), headerToAdd.value()),
insertedField);
}
}
@DataProvider
public static Object[][] evictionScenarios() {
// Header that requires only one entry to be evicted

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -30,7 +30,7 @@
* java.net.http/jdk.internal.net.http.http3.streams
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @run testng FieldSectionPrefixTest
* @run junit FieldSectionPrefixTest
*/
@ -41,21 +41,26 @@ import jdk.internal.net.http.qpack.FieldSectionPrefix;
import jdk.internal.net.http.qpack.QPACK;
import jdk.internal.net.http.qpack.readers.HeaderFrameReader;
import jdk.internal.net.http.qpack.writers.FieldLineSectionPrefixWriter;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Stream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class FieldSectionPrefixTest {
private static final long DT_CAPACITY = 220L;
private static final long MAX_ENTRIES = DT_CAPACITY / 32L;
@Test(dataProvider = "encodingCases")
@ParameterizedTest
@MethodSource("encodingCases")
public void encodingTest(long base, long requiredInsertCount,
byte expectedRic, byte expectedBase) {
var fieldSectionPrefix = new FieldSectionPrefix(requiredInsertCount, base);
@ -64,23 +69,23 @@ public class FieldSectionPrefixTest {
var byteBuffer = ByteBuffer.allocate(bytesNeeded);
writer.write(byteBuffer);
byteBuffer.flip();
Assert.assertEquals(byteBuffer.get(0), expectedRic);
Assert.assertEquals(byteBuffer.get(1), expectedBase);
Assertions.assertEquals(expectedRic, byteBuffer.get(0));
Assertions.assertEquals(expectedBase, byteBuffer.get(1));
}
@DataProvider(name = "encodingCases")
public Object[][] encodingCases() {
var cases = new ArrayList<Object[]>();
// Simple with 0 values
cases.add(new Object[]{0L, 0L, (byte) 0x0, (byte) 0x0});
// Based on RFC-9204: "B.2. Dynamic Table example"
cases.add(new Object[]{0L, 2L, (byte) 0x3, (byte) 0x81});
// Based on RFC-9204: "Duplicate Instruction, Stream Cancellation"
cases.add(new Object[]{4L, 4L, (byte) 0x5, (byte) 0x0});
return cases.toArray(Object[][]::new);
public Stream<Arguments> encodingCases() {
return Stream.of(
// Simple with 0 values
Arguments.of(0L, 0L, (byte) 0x0, (byte) 0x0),
// Based on RFC-9204: "B.2. Dynamic Table example"
Arguments.of(0L, 2L, (byte) 0x3, (byte) 0x81),
// Based on RFC-9204: "Duplicate Instruction, Stream Cancellation"
Arguments.of(4L, 4L, (byte) 0x5, (byte) 0x0)
);
}
@Test(dataProvider = "decodingCases")
@ParameterizedTest
@MethodSource("decodingCases")
public void decodingTest(long expectedRIC, long expectedBase, byte... bytes) throws IOException {
var logger = QPACK.getLogger().subLogger("decodingTest");
var dt = new DynamicTable(logger, false);
@ -117,17 +122,16 @@ public class FieldSectionPrefixTest {
System.err.println("Required Insert Count:" + fsp.requiredInsertCount());
System.err.println("Base:" + fsp.base());
Assert.assertEquals(fsp.requiredInsertCount(), expectedRIC);
Assert.assertEquals(fsp.base(), expectedBase);
Assertions.assertEquals(expectedRIC, fsp.requiredInsertCount());
Assertions.assertEquals(expectedBase, fsp.base());
}
@DataProvider(name = "decodingCases")
public Object[][] decodingCases() {
var cases = new ArrayList<Object[]>();
cases.add(new Object[]{0L, 0L, (byte) 0x0, (byte) 0x0});
cases.add(new Object[]{4L, 4L, (byte) 0x5, (byte) 0x0});
cases.add(new Object[]{2L, 0L, (byte) 0x3, (byte) 0x81});
return cases.toArray(Object[][]::new);
public Stream<Arguments> decodingCases() {
return Stream.of(
Arguments.of(0L, 0L, new byte[]{0x0, 0x0}),
Arguments.of(4L, 4L, new byte[]{0x5, 0x0}),
Arguments.of(2L, 0L, new byte[]{0x3, (byte) 0x81})
);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,12 +24,13 @@
import jdk.internal.net.http.qpack.QPackException;
import jdk.internal.net.http.qpack.readers.IntegerReader;
import jdk.internal.net.http.qpack.writers.IntegerWriter;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.util.stream.IntStream;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -39,11 +40,11 @@ import java.util.stream.IntStream;
* java.net.http/jdk.internal.net.http.qpack
* java.net.http/jdk.internal.net.http.qpack.readers
* java.net.http/jdk.internal.net.http.qpack.writers
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=INFO
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=INFO
* IntegerReaderMaxValuesTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class IntegerReaderMaxValuesTest {
@DataProvider
public Object[][] nValues() {
return IntStream.range(1, 8)
.boxed()
@ -51,7 +52,8 @@ public class IntegerReaderMaxValuesTest {
.toArray(Object[][]::new);
}
@Test(dataProvider = "nValues")
@ParameterizedTest
@MethodSource("nValues")
public void maxIntegerWriteRead(int N) {
IntegerWriter writer = new IntegerWriter();
writer.configure(IntegerReader.QPACK_MAX_INTEGER_VALUE, N, 0);
@ -62,23 +64,26 @@ public class IntegerReaderMaxValuesTest {
buffer.flip();
reader.read(buffer);
long result = reader.get();
Assert.assertEquals(result, IntegerReader.QPACK_MAX_INTEGER_VALUE);
Assertions.assertEquals(IntegerReader.QPACK_MAX_INTEGER_VALUE, result);
}
@Test(dataProvider = "nValues", expectedExceptions = QPackException.class)
@ParameterizedTest
@MethodSource("nValues")
public void overflowInteger(int N) {
// Construct buffer with overflowed integer
ByteBuffer overflowBuffer = ByteBuffer.allocate(11);
Assertions.assertThrows(QPackException.class, () -> {
// Construct buffer with overflowed integer
ByteBuffer overflowBuffer = ByteBuffer.allocate(11);
overflowBuffer.put((byte) ((2 << (N - 1)) - 1));
for (int i = 0; i < 9; i++) {
overflowBuffer.put((byte) 128);
}
overflowBuffer.put((byte) 10);
overflowBuffer.flip();
// Read the buffer with IntegerReader
IntegerReader reader = new IntegerReader();
reader.configure(N);
reader.read(overflowBuffer);
overflowBuffer.put((byte) ((2 << (N - 1)) - 1));
for (int i = 0; i < 9; i++) {
overflowBuffer.put((byte) 128);
}
overflowBuffer.put((byte) 10);
overflowBuffer.flip();
// Read the buffer with IntegerReader
IntegerReader reader = new IntegerReader();
reader.configure(N);
reader.read(overflowBuffer);
});
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2021, 2023, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2021, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,21 +24,23 @@
/*
* @test
* @modules java.net.http/jdk.internal.net.http.qpack
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL StaticTableFieldsTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=NORMAL StaticTableFieldsTest
*/
import jdk.internal.net.http.qpack.StaticTable;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.List;
import static org.testng.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class StaticTableFieldsTest {
@BeforeTest
@BeforeAll
public void setUp() {
// Populate expected table as defined by RFC
expectedTable = new ArrayList<>();
@ -66,10 +68,10 @@ public class StaticTableFieldsTest {
@Test
public void testStaticTable() {
assertEquals(actualTable.size(), expectedTable.size());
assertEquals(expectedTable.size(), actualTable.size());
for (int i = 0; i < expectedTable.size(); i++) {
assertEquals(actualTable.get(i).name(), expectedTable.get(i).name());
assertEquals(actualTable.get(i).value(), expectedTable.get(i).value());
assertEquals(expectedTable.get(i).name(), actualTable.get(i).name());
assertEquals(expectedTable.get(i).value(), actualTable.get(i).value());
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -34,9 +34,6 @@ import jdk.internal.net.http.qpack.readers.StringReader;
import jdk.internal.net.http.qpack.writers.HeaderFrameWriter;
import jdk.internal.net.http.qpack.writers.IntegerWriter;
import jdk.internal.net.http.qpack.writers.StringWriter;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.ProtocolException;
@ -44,6 +41,10 @@ import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -59,12 +60,12 @@ import java.util.concurrent.atomic.AtomicReference;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.http.qpack.allowBlockingEncoding=true
* @run junit/othervm -Djdk.http.qpack.allowBlockingEncoding=true
* StringLengthLimitsTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class StringLengthLimitsTest {
@DataProvider
Object[][] stringReaderLimitsData() {
return new Object[][]{
{STRING_READER_STRING_LENGTH, STRING_READER_STRING_LENGTH, false, false},
@ -74,7 +75,8 @@ public class StringLengthLimitsTest {
};
}
@Test(dataProvider = "stringReaderLimitsData")
@ParameterizedTest
@MethodSource("stringReaderLimitsData")
public void stringReaderLimits(int length, int limit, boolean huffmanBit,
boolean exceptionExpected) throws IOException {
IntegerWriter intWriter = new IntegerWriter();
@ -82,26 +84,25 @@ public class StringLengthLimitsTest {
var byteBuffer = ByteBuffer.allocate(2);
if (!intWriter.write(byteBuffer)) {
Assert.fail("Error with test buffer preparations");
Assertions.fail("Error with test buffer preparations");
}
byteBuffer.flip();
StringReader stringReader = new StringReader();
StringBuilder unusedOutput = new StringBuilder();
if (exceptionExpected) {
QPackException exception = Assert.expectThrows(QPackException.class,
QPackException exception = Assertions.assertThrows(QPackException.class,
() -> stringReader.read(byteBuffer, unusedOutput, limit));
Throwable cause = exception.getCause();
Assert.assertNotNull(cause);
Assert.assertTrue(cause instanceof ProtocolException);
Assertions.assertNotNull(cause);
Assertions.assertTrue(cause instanceof ProtocolException);
System.err.println("Got expected ProtocolException: " + cause);
} else {
boolean done = stringReader.read(byteBuffer, unusedOutput, limit);
Assert.assertFalse(done, "read done");
Assertions.assertFalse(done, "read done");
}
}
@DataProvider
Object[][] encoderInstructionLimitsData() {
int maxEntrySize = ENCODER_INSTRUCTIONS_DT_CAPACITY - 32;
return new Object[][]{
@ -144,7 +145,8 @@ public class StringLengthLimitsTest {
};
}
@Test(dataProvider = "encoderInstructionLimitsData")
@ParameterizedTest
@MethodSource("encoderInstructionLimitsData")
public void encoderInstructionLimits(EncoderInstruction instruction,
int nameLength, boolean nameHuffman,
int valueLength, boolean valueHuffman,
@ -177,9 +179,9 @@ public class StringLengthLimitsTest {
}
Throwable error = observedError.get();
if (successExpected && error != null) {
Assert.fail("Unexpected error", error);
Assertions.fail("Unexpected error", error);
} else if (error == null && !successExpected) {
Assert.fail("Expected error");
Assertions.fail("Expected error");
}
}
@ -244,7 +246,6 @@ public class StringLengthLimitsTest {
return instructionBuffers;
}
@DataProvider
Object[][] fieldLineLimitsData() {
return new Object[][]{
// Post-Base Index
@ -273,7 +274,8 @@ public class StringLengthLimitsTest {
};
}
@Test(dataProvider = "fieldLineLimitsData")
@ParameterizedTest
@MethodSource("fieldLineLimitsData")
public void fieldLineLimits(int nameLength, int valueLength,
String name, String value,
boolean isPostBase, boolean successExpected) throws IOException {
@ -385,9 +387,9 @@ public class StringLengthLimitsTest {
var error = decodingCallbackError.get();
System.err.println("Decoding callback error: " + error);
if (successExpected && error != null) {
Assert.fail("Unexpected error", error);
Assertions.fail("Unexpected error", error);
} else if (error == null && !successExpected) {
Assert.fail("Error expected");
Assertions.fail("Error expected");
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,7 @@
/*
* @test
* @modules java.net.http/jdk.internal.net.http.qpack
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=INFO TablesIndexerTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=INFO TablesIndexerTest
*/
import jdk.internal.net.http.qpack.DynamicTable;
@ -33,9 +33,6 @@ import jdk.internal.net.http.qpack.QPACK;
import jdk.internal.net.http.qpack.StaticTable;
import jdk.internal.net.http.qpack.TableEntry;
import jdk.internal.net.http.qpack.TablesIndexer;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.util.ArrayList;
import java.util.List;
@ -44,10 +41,14 @@ import java.util.concurrent.atomic.AtomicLong;
import java.util.stream.Collectors;
import static jdk.internal.net.http.qpack.TableEntry.EntryType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class TablesIndexerTest {
@DataProvider(name = "indicesLookupData")
public Object[][] indicesData() {
List<Object[]> tcs = new ArrayList<>();
@ -68,7 +69,8 @@ public class TablesIndexerTest {
return tcs.toArray(Object[][]::new);
}
@Test(dataProvider = "indicesLookupData")
@ParameterizedTest
@MethodSource("indicesData")
public void checkIndicesLookup(String name, String value,
String dynamicTableValue,
Set<Long> indices, EntryType type) {
@ -88,45 +90,46 @@ public class TablesIndexerTest {
IGNORE_RECEIVED_COUNT_CHECK);
// TableEntry should be for static table only
Assert.assertTrue(tableEntry.isStaticTable());
Assertions.assertTrue(tableEntry.isStaticTable());
// If value is not equal to dynamicTableValue, the full name:dynamicTableValue
// should be found in the dynamic table with index 0
if (!value.equals(dynamicTableValue)) {
TableEntry dtEntry = tablesIndexer.entryOf(name, dynamicTableValue,
IGNORE_RECEIVED_COUNT_CHECK);
Assert.assertFalse(dtEntry.isStaticTable());
Assert.assertEquals(dtEntry.type(), EntryType.NAME_VALUE);
Assert.assertEquals(dtEntry.index(), 0L);
Assertions.assertFalse(dtEntry.isStaticTable());
Assertions.assertEquals(EntryType.NAME_VALUE, dtEntry.type());
Assertions.assertEquals(0L, dtEntry.index());
}
// Check that found index is contained in a set and returned indices match
Assert.assertTrue(indices.contains(tableEntry.index()));
Assertions.assertTrue(indices.contains(tableEntry.index()));
// Check that entry type matches
Assert.assertEquals(tableEntry.type(), type);
Assertions.assertEquals(type, tableEntry.type());
var headerField = STATIC_TABLE.get(tableEntry.index());
// Check that name and/or value matches the one that can be acquired by
// using looked-up index
if (tableEntry.type() == EntryType.NAME) {
Assert.assertEquals(headerField.name(), name);
Assertions.assertEquals(name, headerField.name());
// If only name entry is found huffmanName should be set to false
Assert.assertFalse(tableEntry.huffmanName());
Assertions.assertFalse(tableEntry.huffmanName());
} else if (tableEntry.type() == EntryType.NAME_VALUE) {
Assert.assertEquals(headerField.name(), name);
Assert.assertEquals(headerField.value(), value);
Assertions.assertEquals(name, headerField.name());
Assertions.assertEquals(value, headerField.value());
// If "name:value" match is found huffmanName and huffmanValue should
// be set to false
Assert.assertFalse(tableEntry.huffmanName());
Assert.assertFalse(tableEntry.huffmanValue());
Assertions.assertFalse(tableEntry.huffmanName());
Assertions.assertFalse(tableEntry.huffmanValue());
} else {
Assert.fail("Unexpected TableEntry type returned:" + tableEntry);
Assertions.fail("Unexpected TableEntry type returned:" + tableEntry);
}
}
@Test(dataProvider = "unacknowledgedEntriesLookupData")
@ParameterizedTest
@MethodSource("unacknowledgedEntriesLookupData")
public void unacknowledgedEntryLookup(String headerName, String headerValue,
boolean staticEntryExpected,
EntryType expectedType) {
@ -137,12 +140,11 @@ public class TablesIndexerTest {
// Search for an entry in the dynamic and the static tables
var entry = tablesIndexer.entryOf(headerName, headerValue, TEST_KNOWN_RECEIVED_COUNT);
// Check that entry references expected table
Assert.assertEquals(entry.isStaticTable(), staticEntryExpected);
Assertions.assertEquals(staticEntryExpected, entry.isStaticTable());
// And the type of found entry matches expectations
Assert.assertEquals(entry.type(), expectedType);
Assertions.assertEquals(expectedType, entry.type());
}
@DataProvider
public Object[][] unacknowledgedEntriesLookupData() {
List<Object[]> data = new ArrayList<>();
data.add(new Object[]{USER_AGENT_ST_NAME, "not-in-dynamic", true, EntryType.NAME});

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2023, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -26,9 +26,6 @@ import jdk.internal.net.http.http3.Http3Error;
import jdk.internal.net.http.http3.frames.SettingsFrame;
import jdk.internal.net.http.qpack.DecodingCallback;
import jdk.internal.net.http.qpack.Encoder;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import java.nio.ByteBuffer;
import java.util.ArrayList;
@ -38,7 +35,11 @@ import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
import static org.testng.Assert.assertNotEquals;
import org.junit.jupiter.api.Assertions;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.TestInstance;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
/*
* @test
@ -56,11 +57,13 @@ import static org.testng.Assert.assertNotEquals;
* java.net.http/jdk.internal.net.http.http3.frames
* java.net.http/jdk.internal.net.http.http3
* @build EncoderDecoderConnector
* @run testng/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA UnacknowledgedInsertionTest
* @run junit/othervm -Djdk.internal.httpclient.qpack.log.level=EXTRA UnacknowledgedInsertionTest
*/
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class UnacknowledgedInsertionTest {
@Test(dataProvider = "duplicateEntryInsertions")
@ParameterizedTest
@MethodSource("duplicateEntryInsertionsData")
public void unacknowledgedDoubleInsertion(long knownReceiveCount, List<EncodingType> expectedHeadersEncodingType) throws Exception {
// When knownReceiveCount is set to -1 the Encoder.knownReceiveCount()
// value is used to encode headers - otherwise the provided value is used
@ -101,10 +104,10 @@ public class UnacknowledgedInsertionTest {
}
// Only two entries are expected to be inserted to the dynamic table
Assert.assertEquals(ed.decoderTable().insertCount(), 2);
Assertions.assertEquals(2, ed.decoderTable().insertCount());
// Check that headers byte buffer is not empty
assertNotEquals(headersBb.position(), 0);
assertNotEquals(0, headersBb.position());
headersBb.flip();
buffers.add(headersBb);
@ -119,11 +122,10 @@ public class UnacknowledgedInsertionTest {
.stream()
.map(DecodedHeader::encodingType)
.toList();
Assert.assertEquals(actualHeaderEncodingTypes, expectedHeadersEncodingType);
Assertions.assertEquals(expectedHeadersEncodingType, actualHeaderEncodingTypes);
}
@DataProvider(name = "duplicateEntryInsertions")
private Object[][] duplicateEntryInsertionsData() {
return new Object[][]{
{0, List.of(EncodingType.LITERAL, EncodingType.LITERAL, EncodingType.LITERAL)},
@ -167,7 +169,7 @@ public class UnacknowledgedInsertionTest {
@Override
public void onDecoded(CharSequence name, CharSequence value) {
Assert.fail("onDecoded not expected to be called");
Assertions.fail("onDecoded not expected to be called");
}
@Override