Skip to content

Commit

Permalink
CURATOR-672. Ensure JDK 17 support (apache#461)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun authored May 8, 2023
1 parent 447878f commit 1e82d0c
Show file tree
Hide file tree
Showing 10 changed files with 166 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [8, 11]
java: [8, 11, 17]
env:
GRADLE_ENTERPRISE_ACCESS_KEY: ${{ secrets.GE_ACCESS_TOKEN }}
steps:
Expand Down
5 changes: 2 additions & 3 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,5 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.1/apache-maven-3.9.1-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
package org.apache.curator;

import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,19 @@ public class GzipCompressionProvider implements CompressionProvider
/** GZIP header magic number. */
private static final int GZIP_MAGIC = 0x8b1f;

// The value of the OS bit has changed in JDK 16;
// see https://bugs.openjdk.org/browse/JDK-8244706 for details.
private static final byte OS_BIT;
static {
final String version = System.getProperty("java.specification.version");
if (version.contains(".")) {
// before or equal to 1.8
OS_BIT = 0;
} else {
OS_BIT = (Float.parseFloat(version) >= 16 ? (byte) -1 : 0);
}
}

/** See {@code java.util.zip.GZIPOutputStream.writeHeader()} */
private static final byte[] GZIP_HEADER = new byte[] {
(byte) GZIP_MAGIC, // Magic number (byte 0)
Expand All @@ -57,7 +70,7 @@ public class GzipCompressionProvider implements CompressionProvider
0, // Modification time MTIME (byte 2)
0, // Modification time MTIME (byte 3)
0, // Extra flags (XFLG)
0 // Operating system (OS)
OS_BIT // Operating system (OS)
};

/** GZip flags, {@link #GZIP_HEADER}'s 4th byte */
Expand Down Expand Up @@ -85,7 +98,7 @@ public class GzipCompressionProvider implements CompressionProvider

/** The value verified in GzipCompressionProviderTest.testEmpty() */
private static final byte[] COMPRESSED_EMPTY_BYTES = new byte[] {
31, -117, 8, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0
31, -117, 8, 0, 0, 0, 0, 0, 0, OS_BIT, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0
};

private static Deflater acquireDeflater()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@

package org.apache.curator.framework.imps;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.ThreadLocalRandom;
import java.util.zip.GZIPOutputStream;
import org.junit.jupiter.api.Test;

public class TestGzipCompressionProvider
{
Expand All @@ -38,9 +38,9 @@ public void testSimple() throws IOException
byte[] data = "Hello, world!".getBytes();
byte[] compressedData = provider.compress(null, data);
byte[] jdkCompressedData = jdkCompress(data);
assertTrue(Arrays.equals(compressedData, jdkCompressedData));
assertArrayEquals(compressedData, jdkCompressedData);
byte[] decompressedData = provider.decompress(null, compressedData);
assertTrue(Arrays.equals(decompressedData, data));
assertArrayEquals(decompressedData, data);
}

@Test
Expand All @@ -51,8 +51,8 @@ public void testEmpty() throws IOException
byte[] compressedData2 = GzipCompressionProvider.doCompress(new byte[0]);
byte[] jdkCompress = jdkCompress(new byte[0]);
// Ensures GzipCompressionProvider.COMPRESSED_EMPTY_BYTES value is valid
assertTrue(Arrays.equals(compressedData, compressedData2));
assertTrue(Arrays.equals(compressedData, jdkCompress));
assertArrayEquals(compressedData, compressedData2);
assertArrayEquals(compressedData, jdkCompress);
byte[] decompressedData = provider.decompress(null, compressedData);
assertEquals(0, decompressedData.length);
}
Expand Down Expand Up @@ -106,9 +106,9 @@ public void smokeTestRandomDataWithJdk() throws IOException
for (int i = 0; i < 100; i++) {
byte[] compressedData = provider.compress(null, data);
byte[] jdkCompressedData = jdkCompress(data);
assertTrue(Arrays.equals(compressedData, jdkCompressedData));
assertArrayEquals(compressedData, jdkCompressedData);
byte[] decompressedData = provider.decompress(null, compressedData);
assertTrue(Arrays.equals(decompressedData, data));
assertArrayEquals(decompressedData, data);
// in the end of the iteration to test empty array first
random.nextBytes(data);
}
Expand All @@ -117,6 +117,7 @@ public void smokeTestRandomDataWithJdk() throws IOException

private static byte[] jdkCompress(byte[] data) throws IOException
{

ByteArrayOutputStream bytes = new ByteArrayOutputStream();
try (GZIPOutputStream out = new GZIPOutputStream(bytes)) {
out.write(data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.mockito.Matchers.any;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;

public class TestWatcherIdentity extends BaseClassForTests
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ public void marshallJson(ObjectNode node, String fieldName, T payload) throws Ex
if ( payload == null )
{
//noinspection unchecked
payload = (T)payloadType.getRawType().newInstance();
payload = (T)payloadType.getRawType().getDeclaredConstructor().newInstance();
}

node.putPOJO(fieldName, payload);
}

Expand Down
Loading

0 comments on commit 1e82d0c

Please sign in to comment.