internal: Support JDK21 (#510)
* Test with JDK21 * Use setup-java * fix test
This commit is contained in:
parent
9f8c3cf742
commit
681b2e1b96
|
@ -36,9 +36,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: olafurpg/setup-scala@v14
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: adopt@1.11
|
distribution: 'zulu'
|
||||||
|
java-version: '11'
|
||||||
- uses: actions/cache@v3
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.cache
|
path: ~/.cache
|
||||||
|
@ -51,9 +52,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: olafurpg/setup-scala@v14
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: adopt@1.8
|
distribution: 'zulu'
|
||||||
|
java-version: '8'
|
||||||
- uses: actions/cache@v3
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.cache
|
path: ~/.cache
|
||||||
|
@ -66,9 +68,10 @@ jobs:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- uses: olafurpg/setup-scala@v14
|
- uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: 17
|
distribution: 'zulu'
|
||||||
|
java-version: '17'
|
||||||
- uses: actions/cache@v3
|
- uses: actions/cache@v3
|
||||||
with:
|
with:
|
||||||
path: ~/.cache
|
path: ~/.cache
|
||||||
|
@ -76,3 +79,19 @@ jobs:
|
||||||
restore-keys: ${{ runner.os }}-jdk17-
|
restore-keys: ${{ runner.os }}-jdk17-
|
||||||
- name: Test
|
- name: Test
|
||||||
run: ./sbt test
|
run: ./sbt test
|
||||||
|
test_jdk21:
|
||||||
|
name: test jdk21
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- uses: actions/setup-java@v3
|
||||||
|
with:
|
||||||
|
distribution: 'zulu'
|
||||||
|
java-version: '21'
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: ~/.cache
|
||||||
|
key: ${{ runner.os }}-jdk21-${{ hashFiles('**/*.sbt') }}
|
||||||
|
restore-keys: ${{ runner.os }}-jdk21-
|
||||||
|
- name: Test
|
||||||
|
run: ./sbt test
|
||||||
|
|
8
sbt
8
sbt
|
@ -34,11 +34,11 @@
|
||||||
|
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
declare -r sbt_release_version="1.8.2"
|
declare -r sbt_release_version="1.9.6"
|
||||||
declare -r sbt_unreleased_version="1.8.2"
|
declare -r sbt_unreleased_version="1.9.6"
|
||||||
|
|
||||||
declare -r latest_213="2.13.10"
|
declare -r latest_213="2.13.12"
|
||||||
declare -r latest_212="2.12.17"
|
declare -r latest_212="2.12.18"
|
||||||
declare -r latest_211="2.11.12"
|
declare -r latest_211="2.11.12"
|
||||||
declare -r latest_210="2.10.7"
|
declare -r latest_210="2.10.7"
|
||||||
declare -r latest_29="2.9.3"
|
declare -r latest_29="2.9.3"
|
||||||
|
|
|
@ -1,184 +1,188 @@
|
||||||
package org.xerial.snappy.pool;
|
package org.xerial.snappy.pool;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
import static org.junit.Assert.assertNotEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertSame;
|
import static org.junit.Assert.assertSame;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.lang.ref.Reference;
|
import java.lang.ref.Reference;
|
||||||
import java.lang.ref.WeakReference;
|
import java.lang.ref.WeakReference;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class CachingBufferPoolTest {
|
public class CachingBufferPoolTest {
|
||||||
|
|
||||||
private static final int LIST_COUNT = 2048;
|
private static final int LIST_COUNT = 2048;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAdjustSize() {
|
public void testAdjustSize() {
|
||||||
assertEquals(4 * 1024, CachingBufferPool.adjustSize(2));
|
assertEquals(4 * 1024, CachingBufferPool.adjustSize(2));
|
||||||
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1023));
|
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1023));
|
||||||
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1024));
|
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1024));
|
||||||
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1025));
|
assertEquals(4 * 1024, CachingBufferPool.adjustSize(1025));
|
||||||
assertEquals(4 * 1024, CachingBufferPool.adjustSize(4 * 1024));
|
assertEquals(4 * 1024, CachingBufferPool.adjustSize(4 * 1024));
|
||||||
assertEquals((4 + 2) * 1024, CachingBufferPool.adjustSize((4 * 1024) + 1));
|
assertEquals((4 + 2) * 1024, CachingBufferPool.adjustSize((4 * 1024) + 1));
|
||||||
assertEquals(6 * 1024, CachingBufferPool.adjustSize(5 * 1024));
|
assertEquals(6 * 1024, CachingBufferPool.adjustSize(5 * 1024));
|
||||||
assertEquals(6 * 1024, CachingBufferPool.adjustSize((5 * 1024) + 1));
|
assertEquals(6 * 1024, CachingBufferPool.adjustSize((5 * 1024) + 1));
|
||||||
|
|
||||||
assertEquals(32 * 1024, CachingBufferPool.adjustSize(32 * 1024));
|
assertEquals(32 * 1024, CachingBufferPool.adjustSize(32 * 1024));
|
||||||
assertEquals((32 + 16) * 1024, CachingBufferPool.adjustSize((32 * 1024) + 1));
|
assertEquals((32 + 16) * 1024, CachingBufferPool.adjustSize((32 * 1024) + 1));
|
||||||
|
|
||||||
assertEquals(2 * 1024 * 1024, CachingBufferPool.adjustSize(2 * 1024 * 1024));
|
assertEquals(2 * 1024 * 1024, CachingBufferPool.adjustSize(2 * 1024 * 1024));
|
||||||
assertEquals(((2 * 1024) + 512) * 1024, CachingBufferPool.adjustSize((2 * 1024 * 1024) + 1));
|
assertEquals(((2 * 1024) + 512) * 1024, CachingBufferPool.adjustSize((2 * 1024 * 1024) + 1));
|
||||||
|
|
||||||
assertEquals(16 * 1024 * 1024, CachingBufferPool.adjustSize(16 * 1024 * 1024));
|
assertEquals(16 * 1024 * 1024, CachingBufferPool.adjustSize(16 * 1024 * 1024));
|
||||||
assertEquals((16 + 4) * 1024 * 1024, CachingBufferPool.adjustSize((16 * 1024 * 1024) + 1));
|
assertEquals((16 + 4) * 1024 * 1024, CachingBufferPool.adjustSize((16 * 1024 * 1024) + 1));
|
||||||
|
|
||||||
assertEquals(128 * 1024 * 1024, CachingBufferPool.adjustSize(128 * 1024 * 1024));
|
assertEquals(128 * 1024 * 1024, CachingBufferPool.adjustSize(128 * 1024 * 1024));
|
||||||
assertEquals((128 + 16) * 1024 * 1024, CachingBufferPool.adjustSize((128 * 1024 * 1024) + 1));
|
assertEquals((128 + 16) * 1024 * 1024, CachingBufferPool.adjustSize((128 * 1024 * 1024) + 1));
|
||||||
|
|
||||||
assertEquals(512 * 1024 * 1024, CachingBufferPool.adjustSize(512 * 1024 * 1024));
|
assertEquals(512 * 1024 * 1024, CachingBufferPool.adjustSize(512 * 1024 * 1024));
|
||||||
assertEquals((512 + 128) * 1024 * 1024, CachingBufferPool.adjustSize((512 * 1024 * 1024) + 1));
|
assertEquals((512 + 128) * 1024 * 1024, CachingBufferPool.adjustSize((512 * 1024 * 1024) + 1));
|
||||||
assertEquals(0x6000_0000, CachingBufferPool.adjustSize(0x6000_0000));
|
assertEquals(0x6000_0000, CachingBufferPool.adjustSize(0x6000_0000));
|
||||||
assertEquals(0x6000_0000, CachingBufferPool.adjustSize(0x6000_0000 - 1));
|
assertEquals(0x6000_0000, CachingBufferPool.adjustSize(0x6000_0000 - 1));
|
||||||
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(0x6000_0001));
|
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(0x6000_0001));
|
||||||
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(Integer.MAX_VALUE));
|
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(Integer.MAX_VALUE));
|
||||||
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(Integer.MAX_VALUE - 1));
|
assertEquals(Integer.MAX_VALUE, CachingBufferPool.adjustSize(Integer.MAX_VALUE - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDirectByteBuffers() throws Exception {
|
public void testDirectByteBuffers() throws Exception {
|
||||||
|
|
||||||
BufferPool pool = CachingBufferPool.getInstance();
|
BufferPool pool = CachingBufferPool.getInstance();
|
||||||
|
|
||||||
ByteBuffer bb1 = pool.allocateDirect(12 * 1024);
|
ByteBuffer bb1 = pool.allocateDirect(12 * 1024);
|
||||||
assertNotNull(bb1);
|
assertNotNull(bb1);
|
||||||
assertEquals(12 * 1024, bb1.limit());
|
assertEquals(12 * 1024, bb1.limit());
|
||||||
assertEquals(12 * 1024, bb1.capacity());
|
assertEquals(12 * 1024, bb1.capacity());
|
||||||
assertEquals(0, bb1.position());
|
assertEquals(0, bb1.position());
|
||||||
|
|
||||||
ByteBuffer bb2 = pool.allocateDirect(12 * 1024);
|
ByteBuffer bb2 = pool.allocateDirect(12 * 1024);
|
||||||
assertNotNull(bb2);
|
assertNotNull(bb2);
|
||||||
assertEquals(12 * 1024, bb2.limit());
|
assertEquals(12 * 1024, bb2.limit());
|
||||||
assertEquals(12 * 1024, bb2.capacity());
|
assertEquals(12 * 1024, bb2.capacity());
|
||||||
assertEquals(0, bb2.position());
|
assertEquals(0, bb2.position());
|
||||||
|
|
||||||
assertNotSame(bb1, bb2);
|
assertNotSame(bb1, bb2);
|
||||||
|
|
||||||
bb2.position(18);
|
bb2.position(18);
|
||||||
pool.releaseDirect(bb2);
|
pool.releaseDirect(bb2);
|
||||||
|
|
||||||
ByteBuffer bb3 = pool.allocateDirect(12 * 1024);
|
ByteBuffer bb3 = pool.allocateDirect(12 * 1024);
|
||||||
assertNotNull(bb3);
|
assertNotNull(bb3);
|
||||||
assertEquals(12 * 1024, bb3.limit());
|
assertEquals(12 * 1024, bb3.limit());
|
||||||
assertEquals(12 * 1024, bb3.capacity());
|
assertEquals(12 * 1024, bb3.capacity());
|
||||||
assertEquals(0, bb3.position());
|
assertEquals(0, bb3.position());
|
||||||
|
|
||||||
assertNotSame(bb1, bb2);
|
assertNotSame(bb1, bb2);
|
||||||
assertSame(bb2, bb3);
|
assertSame(bb2, bb3);
|
||||||
|
|
||||||
pool.releaseDirect(bb1);
|
pool.releaseDirect(bb1);
|
||||||
|
|
||||||
ByteBuffer bb4 = pool.allocateDirect((12 * 1024) - 1);
|
ByteBuffer bb4 = pool.allocateDirect((12 * 1024) - 1);
|
||||||
assertNotNull(bb4);
|
assertNotNull(bb4);
|
||||||
assertEquals(12 * 1024, bb4.limit());
|
assertEquals(12 * 1024, bb4.limit());
|
||||||
assertEquals(12 * 1024, bb4.capacity());
|
assertEquals(12 * 1024, bb4.capacity());
|
||||||
assertEquals(0, bb4.position());
|
assertEquals(0, bb4.position());
|
||||||
|
|
||||||
assertSame(bb1, bb4);
|
assertSame(bb1, bb4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testArrays() throws Exception {
|
public void testArrays() throws Exception {
|
||||||
|
|
||||||
BufferPool pool = CachingBufferPool.getInstance();
|
BufferPool pool = CachingBufferPool.getInstance();
|
||||||
|
|
||||||
byte[] bb1 = pool.allocateArray(12 * 1024);
|
byte[] bb1 = pool.allocateArray(12 * 1024);
|
||||||
assertNotNull(bb1);
|
assertNotNull(bb1);
|
||||||
assertEquals(12 * 1024, bb1.length);
|
assertEquals(12 * 1024, bb1.length);
|
||||||
|
|
||||||
byte[] bb2 = pool.allocateArray(12 * 1024);
|
byte[] bb2 = pool.allocateArray(12 * 1024);
|
||||||
assertNotNull(bb2);
|
assertNotNull(bb2);
|
||||||
assertEquals(12 * 1024, bb2.length);
|
assertEquals(12 * 1024, bb2.length);
|
||||||
|
|
||||||
assertNotSame(bb1, bb2);
|
assertNotSame(bb1, bb2);
|
||||||
|
|
||||||
pool.releaseArray(bb2);
|
pool.releaseArray(bb2);
|
||||||
|
|
||||||
byte[] bb3 = pool.allocateArray(12 * 1024);
|
byte[] bb3 = pool.allocateArray(12 * 1024);
|
||||||
assertNotNull(bb3);
|
assertNotNull(bb3);
|
||||||
assertEquals(12 * 1024, bb3.length);
|
assertEquals(12 * 1024, bb3.length);
|
||||||
|
|
||||||
assertNotSame(bb1, bb2);
|
assertNotSame(bb1, bb2);
|
||||||
assertSame(bb2, bb3);
|
assertSame(bb2, bb3);
|
||||||
|
|
||||||
pool.releaseArray(bb1);
|
pool.releaseArray(bb1);
|
||||||
|
|
||||||
byte[] bb4 = pool.allocateArray((12 * 1024) - 1);
|
byte[] bb4 = pool.allocateArray((12 * 1024) - 1);
|
||||||
assertNotNull(bb4);
|
assertNotNull(bb4);
|
||||||
assertEquals(12 * 1024, bb4.length);
|
assertEquals(12 * 1024, bb4.length);
|
||||||
|
|
||||||
assertSame(bb1, bb4);
|
assertSame(bb1, bb4);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSoftReferences() {
|
public void testSoftReferences() {
|
||||||
|
|
||||||
BufferPool pool = CachingBufferPool.getInstance();
|
BufferPool pool = CachingBufferPool.getInstance();
|
||||||
byte[] bb1 = pool.allocateArray(8 * 1024);
|
byte[] bb1 = pool.allocateArray(8 * 1024);
|
||||||
Reference<byte[]> ref = new WeakReference<byte[]>(bb1);
|
Reference<byte[]> ref = new WeakReference<byte[]>(bb1);
|
||||||
bb1[0] = 123;
|
bb1[0] = 123;
|
||||||
bb1[8000] = -74;
|
bb1[8000] = -74;
|
||||||
int bb1HC = System.identityHashCode(bb1);
|
int bb1HC = System.identityHashCode(bb1);
|
||||||
|
|
||||||
pool.releaseArray(bb1);
|
pool.releaseArray(bb1);
|
||||||
|
|
||||||
byte[] bb1_copy = pool.allocateArray(8 * 1024);
|
byte[] bb1_copy = pool.allocateArray(8 * 1024);
|
||||||
assertSame(bb1, bb1_copy);
|
assertSame(bb1, bb1_copy);
|
||||||
assertEquals(123, bb1_copy[0]);
|
assertEquals(123, bb1_copy[0]);
|
||||||
assertEquals(-74, bb1_copy[8000]);
|
assertEquals(-74, bb1_copy[8000]);
|
||||||
assertEquals(bb1HC, System.identityHashCode(bb1_copy));
|
assertEquals(bb1HC, System.identityHashCode(bb1_copy));
|
||||||
|
|
||||||
//release back into pool (again)
|
//release back into pool (again)
|
||||||
pool.releaseArray(bb1);
|
pool.releaseArray(bb1);
|
||||||
|
|
||||||
//release strong references
|
//release strong references
|
||||||
bb1_copy = null;
|
bb1_copy = null;
|
||||||
bb1 = null;
|
bb1 = null;
|
||||||
assertNotNull(ref.get());
|
assertNotNull(ref.get());
|
||||||
|
|
||||||
//force an OOME to for SoftReferences to be collected
|
//force an OOME to for SoftReferences to be collected
|
||||||
List<byte[]> vals = forceOOMEGC(LIST_COUNT);
|
try {
|
||||||
assertTrue("count: " + vals.size(), vals.size() < LIST_COUNT);
|
List<byte[]> vals = forceOOMEGC(LIST_COUNT);
|
||||||
|
assertTrue("count: " + vals.size(), vals.size() < LIST_COUNT);
|
||||||
//assert that our test reference has been cleared
|
} catch (OutOfMemoryError e) {
|
||||||
assertNull(ref.get());
|
//
|
||||||
|
}
|
||||||
//get another value from the pool
|
|
||||||
byte[] bb2 = pool.allocateArray(8 * 1024);
|
//assert that our test reference has been cleared
|
||||||
//assert that it is indeed a new value, and not same from previous
|
assertNull(ref.get());
|
||||||
assertNotEquals(123, bb2[0]);
|
|
||||||
assertNotEquals(-74, bb2[8000]);
|
//get another value from the pool
|
||||||
assertNotEquals(bb1HC, System.identityHashCode(bb2));
|
byte[] bb2 = pool.allocateArray(8 * 1024);
|
||||||
}
|
//assert that it is indeed a new value, and not same from previous
|
||||||
|
assertNotEquals(123, bb2[0]);
|
||||||
private static List<byte[]> forceOOMEGC(int count) {
|
assertNotEquals(-74, bb2[8000]);
|
||||||
final List<byte[]> vals = new ArrayList<>(count);
|
assertNotEquals(bb1HC, System.identityHashCode(bb2));
|
||||||
|
}
|
||||||
try {
|
|
||||||
for (int i=0; i<count; ++i) {
|
private static List<byte[]> forceOOMEGC(int count) {
|
||||||
vals.add(new byte[10 * 1024 * 1024]);
|
final List<byte[]> vals = new ArrayList<>(count);
|
||||||
}
|
|
||||||
} catch(Error e) {
|
try {
|
||||||
|
for (int i = 0; i < count; ++i) {
|
||||||
}
|
vals.add(new byte[10 * 1024 * 1024]);
|
||||||
return vals;
|
}
|
||||||
}
|
} catch (Error e) {
|
||||||
}
|
|
||||||
|
}
|
||||||
|
return vals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue