Skip to content

Commit 127f0b9

Browse files
committed
Merged branch 'jetty-12.1.x' into 'jetty-12.1.x-quic-streams'.
Signed-off-by: Simone Bordet <[email protected]>
2 parents 7e40a57 + 6b7da3c commit 127f0b9

File tree

187 files changed

+5450
-1388
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+5450
-1388
lines changed

build/scripts/release-jetty.sh

+4
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,10 @@ if proceedyn "Are you sure you want to release using above? (y/N)" n; then
187187
git push $GIT_REMOTE_ID $GIT_BRANCH_ID
188188
git push $GIT_REMOTE_ID $TAG_NAME
189189
fi
190+
191+
if proceedyn "Do you want to build aggregated Javadoc in target/reports/apidocs/? (Y/n)" y; then
192+
mvn mvn clean install -Pjavadoc-aggregate javadoc:aggregate -DskipTests
193+
fi
190194
else
191195
echo "Not performing release"
192196
fi

jetty-core/jetty-compression/jetty-compression-brotli/src/main/java/org/eclipse/jetty/compression/brotli/internal/BrotliDecoderSource.java

+1
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ protected Content.Chunk transform(Content.Chunk inputChunk)
9696
@Override
9797
protected void release()
9898
{
99+
super.release();
99100
decoder.destroy();
100101
}
101102
}

jetty-core/jetty-compression/jetty-compression-brotli/src/test/java/org/eclipse/jetty/compression/brotli/AbstractBrotliTest.java

-50
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,19 @@
1717
import java.io.ByteArrayOutputStream;
1818
import java.io.IOException;
1919
import java.io.InputStream;
20-
import java.io.OutputStream;
21-
import java.nio.ByteBuffer;
2220
import java.util.List;
2321

2422
import org.eclipse.jetty.io.ArrayByteBufferPool;
2523
import org.eclipse.jetty.io.ByteBufferPool;
26-
import org.eclipse.jetty.util.BufferUtil;
2724
import org.eclipse.jetty.util.IO;
2825
import org.eclipse.jetty.util.component.LifeCycle;
2926
import org.junit.jupiter.api.AfterEach;
3027
import org.junit.jupiter.api.BeforeEach;
3128

32-
import static java.nio.charset.StandardCharsets.UTF_8;
3329
import static org.junit.jupiter.api.Assertions.assertEquals;
3430

3531
public abstract class AbstractBrotliTest
3632
{
37-
// Signed Integer Max
38-
protected static final long INT_MAX = Integer.MAX_VALUE;
39-
// Unsigned Integer Max == 2^32
40-
protected static final long UINT_MAX = 0xFFFFFFFFL;
41-
4233
protected ArrayByteBufferPool.Tracking pool;
4334
protected ByteBufferPool.Sized sizedPool;
4435
protected BrotliCompression brotli;
@@ -51,16 +42,8 @@ public void initPool()
5142
}
5243

5344
protected void startBrotli() throws Exception
54-
{
55-
startBrotli(-1);
56-
}
57-
58-
protected void startBrotli(int bufferSize) throws Exception
5945
{
6046
brotli = new BrotliCompression();
61-
if (bufferSize > 0)
62-
brotli.setBufferSize(bufferSize);
63-
6447
brotli.setByteBufferPool(pool);
6548
brotli.start();
6649
}
@@ -77,26 +60,6 @@ public static List<String> textResources()
7760
return List.of("texts/logo.svg", "texts/long.txt", "texts/quotes.txt");
7861
}
7962

80-
/**
81-
* Compress data using Brotli4j {@code BrotliOutputStream}.
82-
*
83-
* @param data the data to compress
84-
* @return the compressed bytes
85-
* @throws IOException if unable to compress input data
86-
*/
87-
public byte[] compress(String data) throws IOException
88-
{
89-
BrotliEncoderConfig brotliEncoderConfig = new BrotliEncoderConfig();
90-
try (ByteArrayOutputStream bytesOut = new ByteArrayOutputStream();
91-
OutputStream output = brotli.newEncoderOutputStream(bytesOut))
92-
{
93-
if (data != null)
94-
output.write(data.getBytes(UTF_8));
95-
output.close();
96-
return bytesOut.toByteArray();
97-
}
98-
}
99-
10063
/**
10164
* Decompress bytes using Brotli4j {@code BrotliInputStream}.
10265
*
@@ -115,17 +78,4 @@ public byte[] decompress(byte[] compressedBytes) throws IOException
11578
return output.toByteArray();
11679
}
11780
}
118-
119-
/**
120-
* Decompress ByteBuffer using Brotli4j {@code BrotliInputStream}.
121-
*
122-
* @param compressedBytes the data to decompress
123-
* @return the decompressed bytes
124-
* @throws IOException if unable to decompress
125-
*/
126-
public byte[] decompress(ByteBuffer compressedBytes) throws IOException
127-
{
128-
return decompress(BufferUtil.toArray(compressedBytes));
129-
}
130-
13181
}

jetty-core/jetty-compression/jetty-compression-brotli/src/test/java/org/eclipse/jetty/compression/brotli/BrotliDecoderSourceTest.java

+65-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
import java.nio.file.Files;
1717
import java.nio.file.Path;
1818

19+
import org.eclipse.jetty.compression.DecoderSource;
1920
import org.eclipse.jetty.io.Content;
2021
import org.eclipse.jetty.toolchain.test.MavenPaths;
2122
import org.junit.jupiter.params.ParameterizedTest;
2223
import org.junit.jupiter.params.provider.MethodSource;
2324

2425
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2529

2630
public class BrotliDecoderSourceTest extends AbstractBrotliTest
2731
{
@@ -35,10 +39,70 @@ public void testDecodeText(String textResourceName) throws Exception
3539
Path uncompressed = MavenPaths.findTestResourceFile(textResourceName);
3640

3741
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
38-
Content.Source decoderSource = brotli.newDecoderSource(fileSource);
42+
DecoderSource decoderSource = brotli.newDecoderSource(fileSource);
43+
assertFalse(decoderSource.isComplete());
3944

4045
String result = Content.Source.asString(decoderSource);
4146
String expected = Files.readString(uncompressed);
4247
assertEquals(expected, result);
48+
assertTrue(decoderSource.isComplete());
49+
50+
Content.Chunk eof = decoderSource.read();
51+
assertTrue(eof.isLast() && eof.isEmpty() && !Content.Chunk.isFailure(eof));
52+
53+
// Failed after EOF, too late.
54+
decoderSource.fail(new Throwable());
55+
56+
Content.Chunk chunk = decoderSource.read();
57+
assertTrue(chunk.isLast() && chunk.isEmpty() && !Content.Chunk.isFailure(chunk));
58+
}
59+
60+
@ParameterizedTest
61+
@MethodSource("textResources")
62+
public void testImmediateFailReleaseAllResources(String textResourceName) throws Exception
63+
{
64+
startBrotli();
65+
String compressedName = String.format("%s.%s", textResourceName, brotli.getFileExtensionNames().get(0));
66+
Path compressed = MavenPaths.findTestResourceFile(compressedName);
67+
68+
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
69+
DecoderSource decoderSource = brotli.newDecoderSource(fileSource);
70+
assertFalse(decoderSource.isComplete());
71+
72+
decoderSource.fail(new Throwable());
73+
assertTrue(decoderSource.isComplete());
74+
75+
Content.Chunk err = decoderSource.read();
76+
assertTrue(Content.Chunk.isFailure(err));
77+
}
78+
79+
@ParameterizedTest
80+
@MethodSource("textResources")
81+
public void testFailAfterReadReleaseAllResources(String textResourceName) throws Exception
82+
{
83+
startBrotli();
84+
String compressedName = String.format("%s.%s", textResourceName, brotli.getFileExtensionNames().get(0));
85+
Path compressed = MavenPaths.findTestResourceFile(compressedName);
86+
87+
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
88+
DecoderSource decoderSource = brotli.newDecoderSource(fileSource);
89+
assertFalse(decoderSource.isComplete());
90+
91+
Content.Chunk chunk = decoderSource.read();
92+
// skip empty chunks
93+
while (chunk.isEmpty() && !chunk.isLast())
94+
chunk = decoderSource.read();
95+
assertTrue(chunk.hasRemaining());
96+
chunk.release();
97+
// This test tests the behavior of
98+
// a failure before the last chunk.
99+
assumeFalse(chunk.isLast());
100+
assertFalse(decoderSource.isComplete());
101+
102+
decoderSource.fail(new Throwable());
103+
assertTrue(decoderSource.isComplete());
104+
105+
Content.Chunk err = decoderSource.read();
106+
assertTrue(Content.Chunk.isFailure(err));
43107
}
44108
}

jetty-core/jetty-compression/jetty-compression-gzip/src/main/java/org/eclipse/jetty/compression/gzip/internal/GzipDecoderSource.java

+1
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,7 @@ else if (inflater.finished())
274274
@Override
275275
protected void release()
276276
{
277+
super.release();
277278
inflaterEntry.release();
278279
}
279280
}

jetty-core/jetty-compression/jetty-compression-gzip/src/test/java/org/eclipse/jetty/compression/gzip/AbstractGzipTest.java

-22
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,22 @@
1616
import java.io.ByteArrayInputStream;
1717
import java.io.ByteArrayOutputStream;
1818
import java.io.IOException;
19-
import java.nio.ByteBuffer;
2019
import java.util.List;
2120
import java.util.zip.GZIPInputStream;
2221
import java.util.zip.GZIPOutputStream;
2322

2423
import org.eclipse.jetty.io.ArrayByteBufferPool;
2524
import org.eclipse.jetty.io.ByteBufferPool;
26-
import org.eclipse.jetty.util.BufferUtil;
2725
import org.eclipse.jetty.util.IO;
2826
import org.eclipse.jetty.util.component.LifeCycle;
2927
import org.junit.jupiter.api.AfterEach;
3028
import org.junit.jupiter.api.BeforeEach;
31-
import org.slf4j.Logger;
32-
import org.slf4j.LoggerFactory;
3329

3430
import static java.nio.charset.StandardCharsets.UTF_8;
3531
import static org.junit.jupiter.api.Assertions.assertEquals;
3632

3733
public abstract class AbstractGzipTest
3834
{
39-
// Signed Integer Max
40-
protected static final long INT_MAX = Integer.MAX_VALUE;
41-
// Unsigned Integer Max == 2^32
42-
protected static final long UINT_MAX = 0xFFFFFFFFL;
43-
private static final Logger LOG = LoggerFactory.getLogger(AbstractGzipTest.class);
4435
protected ArrayByteBufferPool.Tracking pool;
4536
protected ByteBufferPool.Sized sizedPool;
4637
protected GzipCompression gzip;
@@ -89,18 +80,6 @@ public byte[] decompress(byte[] compressedBytes) throws IOException
8980
}
9081
}
9182

92-
/**
93-
* Decompress ByteBuffer using JVM Built-In GZIP features.
94-
*
95-
* @param compressedBytes the data to decompress
96-
* @return the decompressed bytes
97-
* @throws IOException if unable to decompress
98-
*/
99-
public byte[] decompress(ByteBuffer compressedBytes) throws IOException
100-
{
101-
return decompress(BufferUtil.toArray(compressedBytes));
102-
}
103-
10483
@BeforeEach
10584
public void initPool()
10685
{
@@ -125,7 +104,6 @@ protected void startGzip(int bufferSize) throws Exception
125104
gzip = new GzipCompression();
126105
if (bufferSize > 0)
127106
gzip.setBufferSize(bufferSize);
128-
129107
gzip.setByteBufferPool(pool);
130108
gzip.start();
131109
}

jetty-core/jetty-compression/jetty-compression-gzip/src/test/java/org/eclipse/jetty/compression/gzip/GzipDecoderSourceTest.java

+62-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@
1616
import java.nio.file.Files;
1717
import java.nio.file.Path;
1818

19+
import org.eclipse.jetty.compression.DecoderSource;
1920
import org.eclipse.jetty.io.Content;
2021
import org.eclipse.jetty.toolchain.test.MavenPaths;
2122
import org.junit.jupiter.params.ParameterizedTest;
2223
import org.junit.jupiter.params.provider.MethodSource;
2324

2425
import static org.junit.jupiter.api.Assertions.assertEquals;
26+
import static org.junit.jupiter.api.Assertions.assertFalse;
27+
import static org.junit.jupiter.api.Assertions.assertTrue;
28+
import static org.junit.jupiter.api.Assumptions.assumeFalse;
2529

2630
public class GzipDecoderSourceTest extends AbstractGzipTest
2731
{
@@ -35,10 +39,67 @@ public void testDecodeText(String textResourceName) throws Exception
3539
Path uncompressed = MavenPaths.findTestResourceFile(textResourceName);
3640

3741
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
38-
Content.Source decoderSource = gzip.newDecoderSource(fileSource);
42+
DecoderSource decoderSource = gzip.newDecoderSource(fileSource);
43+
assertFalse(decoderSource.isComplete());
3944

4045
String result = Content.Source.asString(decoderSource);
4146
String expected = Files.readString(uncompressed);
4247
assertEquals(expected, result);
48+
assertTrue(decoderSource.isComplete());
49+
50+
Content.Chunk eof = decoderSource.read();
51+
assertTrue(eof.isLast() && eof.isEmpty() && !Content.Chunk.isFailure(eof));
52+
53+
// Failed after EOF, too late.
54+
decoderSource.fail(new Throwable());
55+
56+
Content.Chunk chunk = decoderSource.read();
57+
assertTrue(chunk.isLast() && chunk.isEmpty() && !Content.Chunk.isFailure(chunk));
58+
}
59+
60+
@ParameterizedTest
61+
@MethodSource("textResources")
62+
public void testImmediateFailReleaseAllResources(String textResourceName) throws Exception
63+
{
64+
startGzip();
65+
String compressedName = String.format("%s.%s", textResourceName, gzip.getFileExtensionNames().get(0));
66+
Path compressed = MavenPaths.findTestResourceFile(compressedName);
67+
68+
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
69+
DecoderSource decoderSource = gzip.newDecoderSource(fileSource);
70+
assertFalse(decoderSource.isComplete());
71+
72+
decoderSource.fail(new Throwable());
73+
assertTrue(decoderSource.isComplete());
74+
75+
Content.Chunk err = decoderSource.read();
76+
assertTrue(Content.Chunk.isFailure(err));
77+
}
78+
79+
@ParameterizedTest
80+
@MethodSource("textResources")
81+
public void testFailAfterReadReleaseAllResources(String textResourceName) throws Exception
82+
{
83+
startGzip();
84+
String compressedName = String.format("%s.%s", textResourceName, gzip.getFileExtensionNames().get(0));
85+
Path compressed = MavenPaths.findTestResourceFile(compressedName);
86+
87+
Content.Source fileSource = Content.Source.from(sizedPool, compressed);
88+
DecoderSource decoderSource = gzip.newDecoderSource(fileSource);
89+
assertFalse(decoderSource.isComplete());
90+
91+
Content.Chunk chunk = decoderSource.read();
92+
assertTrue(chunk.hasRemaining());
93+
chunk.release();
94+
// This test tests the behavior of
95+
// a failure before the last chunk.
96+
assumeFalse(chunk.isLast());
97+
assertFalse(decoderSource.isComplete());
98+
99+
decoderSource.fail(new Throwable());
100+
assertTrue(decoderSource.isComplete());
101+
102+
Content.Chunk err = decoderSource.read();
103+
assertTrue(Content.Chunk.isFailure(err));
43104
}
44105
}

0 commit comments

Comments
 (0)