diff --git a/src/test/java/org/apache/datasketches/common/TestUtil.java b/src/test/java/org/apache/datasketches/common/TestUtil.java
index 35180d003..3306790e8 100644
--- a/src/test/java/org/apache/datasketches/common/TestUtil.java
+++ b/src/test/java/org/apache/datasketches/common/TestUtil.java
@@ -28,6 +28,8 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.NoSuchFileException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -40,227 +42,98 @@
*/
public final class TestUtil {
- private static final String userDir = System.getProperty("user.dir");
-
/**
* TestNG group constants
*/
public static final String GENERATE_JAVA_FILES = "generate_java_files";
public static final String CHECK_CPP_FILES = "check_cpp_files";
public static final String CHECK_GO_FILES = "check_go_files";
+ public static final String CHECK_RUST_FILES = "check_rust_files";
public static final String CHECK_CPP_HISTORICAL_FILES = "check_cpp_historical_files";
/**
- * The full target Path for Java serialized sketches to be tested by other languages.
+ * The project relative Path for Java serialized sketches to be tested by other languages.
*/
- public static final Path javaPath = createPath("serialization_test_data/java_generated_files");
+ public static final Path javaPath = Path.of(".", "serialization_test_data", "java_generated_files");
/**
- * The full target Path for C++ serialized sketches to be tested by Java.
+ * The project relative Path for C++ serialized sketches to be tested by Java.
*/
- public static final Path cppPath = createPath("serialization_test_data/cpp_generated_files");
+ public static final Path cppPath = Path.of(".", "serialization_test_data", "cpp_generated_files");
/**
- * The full target Path for Go serialized sketches to be tested by Java.
+ * The project relative Path for Go serialized sketches to be tested by Java.
*/
- public static final Path goPath = createPath("serialization_test_data/go_generated_files");
-
- private static Path createPath(final String projectLocalDir) {
- try {
- return Files.createDirectories(Paths.get(userDir, projectLocalDir));
- } catch (IOException e) { throw new SketchesArgumentException(e.getCause().toString()); }
- }
-
- //Get Resources
-
- private static final int BUF_SIZE = 1 << 13;
-
+ public static final Path goPath = Path.of(".", "serialization_test_data", "go_generated_files");
+
/**
- * Gets the file defined by the given resource file's shortFileName.
- * @param shortFileName the last name in the pathname's name sequence.
- * @return the file defined by the given resource file's shortFileName.
+ * The project relative Path for Rust serialized sketches to be tested by Java.
*/
- public static File getResourceFile(final String shortFileName) {
- Objects.requireNonNull(shortFileName, "input parameter 'String shortFileName' cannot be null.");
- final String slashName = (shortFileName.charAt(0) == '/') ? shortFileName : '/' + shortFileName;
- final URL url = TestUtil.class.getResource(slashName);
- Objects.requireNonNull(url, "resource " + slashName + " returns null URL.");
- File file;
- file = createTempFile(slashName);
- if (url.getProtocol().equals("jar")) { //definitely a jar
- try (final InputStream input = TestUtil.class.getResourceAsStream(slashName);
- final OutputStream out = new FileOutputStream(file)) {
- Objects.requireNonNull(input, "InputStream is null.");
- int numRead = 0;
- final byte[] buf = new byte[1024];
- while ((numRead = input.read(buf)) != -1) { out.write(buf, 0, numRead); }
- } catch (final IOException e ) { throw new RuntimeException(e); }
- } else { //protocol says resource is not a jar, must be a file
- file = new File(getResourcePath(url));
- }
- if (!file.setReadable(false, true)) {
- throw new IllegalStateException("Failed to set owner only 'Readable' on file");
- }
- if (!file.setWritable(false, false)) {
- throw new IllegalStateException("Failed to set everyone 'Not Writable' on file");
- }
- return file;
- }
-
+ public static final Path rustPath = Path.of(".", "serialization_test_data", "rust_generated_files");
+
/**
- * Returns a byte array of the contents of the file defined by the given resource file's shortFileName.
- * @param shortFileName the last name in the pathname's name sequence.
- * @return a byte array of the contents of the file defined by the given resource file's shortFileName.
- * @throws IllegalArgumentException if resource cannot be read.
+ * The project relative Path for /src/test/resources
*/
- public static byte[] getResourceBytes(final String shortFileName) {
- Objects.requireNonNull(shortFileName, "input parameter 'String shortFileName' cannot be null.");
- final String slashName = (shortFileName.charAt(0) == '/') ? shortFileName : '/' + shortFileName;
- final URL url = TestUtil.class.getResource(slashName);
- Objects.requireNonNull(url, "resource " + slashName + " returns null URL.");
- final byte[] out;
- if (url.getProtocol().equals("jar")) { //definitely a jar
- try (final InputStream input = TestUtil.class.getResourceAsStream(slashName)) {
- out = readAllBytesFromInputStream(input);
- } catch (final IOException e) { throw new RuntimeException(e); }
- } else { //protocol says resource is not a jar, must be a file
- try {
- out = Files.readAllBytes(Paths.get(getResourcePath(url)));
- } catch (final IOException e) { throw new RuntimeException(e); }
- }
- return out;
- }
+ public static final Path resPath = Path.of(".","src","test","resources");
- /**
- * Note: This is only needed in Java 8 as it is part of Java 9+.
- * Read all bytes from the given InputStream.
- * This is limited to streams that are no longer than the maximum allocatable byte array determined by the VM.
- * This may be a little smaller than Integer.MAX_VALUE.
- * @param in the Input Stream
- * @return byte array
- */
- public static byte[] readAllBytesFromInputStream(final InputStream in) {
- return readBytesFromInputStream(Integer.MAX_VALUE, in);
- }
/**
- * Note: This is only needed in Java 8 as is part of Java 9+.
- * Read numBytesToRead bytes from an input stream into a single byte array.
- * This is limited to streams that are no longer than the maximum allocatable byte array determined by the VM.
- * This may be a little smaller than Integer.MAX_VALUE.
- * @param numBytesToRead number of bytes to read
- * @param in the InputStream
- * @return the filled byte array from the input stream
- * @throws IllegalArgumentException if array size grows larger than what can be safely allocated by some VMs.
-
+ * Gets all the bytes of a file as a byte array.
+ * If the file is missing, this writes a warning message to the console.
+ * @param basePath the base directory path where the file is located
+ * @param fileName the simple file name of the file
+ * @return a byte array
+ * @throws RuntimeException for IO errors, or if resolved path is not a file or not readable.
*/
- public static byte[] readBytesFromInputStream(final int numBytesToRead, final InputStream in) {
- if (numBytesToRead < 0) { throw new IllegalArgumentException("numBytesToRead must be positive or zero."); }
-
- List buffers = null;
- byte[] result = null;
- int totalBytesRead = 0;
- int remaining = numBytesToRead;
- int chunkCnt;
- do {
- final byte[] partialBuffer = new byte[Math.min(remaining, BUF_SIZE)];
- int numRead = 0;
-
- try {
- // reads input stream in chunks of partial buffers, stops at EOF or when remaining is zero.
- while ((chunkCnt =
- in.read(partialBuffer, numRead, Math.min(partialBuffer.length - numRead, remaining))) > 0) {
- numRead += chunkCnt;
- remaining -= chunkCnt;
- }
- } catch (final IOException e) { throw new RuntimeException(e); }
-
- if (numRead > 0) {
- if (Integer.MAX_VALUE - Long.BYTES - totalBytesRead < numRead) {
- throw new IllegalArgumentException(
- "Input stream is larger than what can be safely allocated as a byte[] in some VMs."); }
- totalBytesRead += numRead;
- if (result == null) {
- result = partialBuffer;
- } else {
- if (buffers == null) {
- buffers = new ArrayList<>();
- buffers.add(result);
- }
- buffers.add(partialBuffer);
- }
- }
- } while (chunkCnt >= 0 && remaining > 0);
-
- final byte[] out;
- if (buffers == null) {
- if (result == null) {
- out = new byte[0];
- } else {
- out = result.length == totalBytesRead ? result : Arrays.copyOf(result, totalBytesRead);
- }
- return out;
+ public static byte[] getFileBytes(final Path basePath, final String fileName) throws RuntimeException {
+ Objects.requireNonNull(basePath, "input parameter 'Path basePath' cannot be null.");
+ Objects.requireNonNull(fileName, "input parameter 'String fileName' cannot be null.");
+ Path path = Path.of(basePath.toString(), fileName);
+ Path absPath = path.toAbsolutePath(); //for error output
+ byte[] bytes = new byte[0]; //or null
+ if (Files.notExists(path)) { //In this specific case, just issue warning.
+ System.err.println("File disappeared or not found: " + absPath);
+ return bytes; //empty
}
-
- result = new byte[totalBytesRead];
- int offset = 0;
- remaining = totalBytesRead;
- for (byte[] b : buffers) {
- final int count = Math.min(b.length, remaining);
- System.arraycopy(b, 0, result, offset, count);
- offset += count;
- remaining -= count;
+ if (!Files.isRegularFile(path) || !Files.isReadable(path)) {
+ throw new RuntimeException("Path is not a regular file or not readable: " + absPath);
}
- return result;
- }
-
- private static String getResourcePath(final URL url) { //must not be null
try {
- final URI uri = url.toURI();
- //decodes any special characters
- final String path = uri.isAbsolute() ? Paths.get(uri).toAbsolutePath().toString() : uri.getPath();
- return path;
- } catch (final URISyntaxException e) {
- throw new IllegalArgumentException("Cannot find resource: " + url.toString() + Util.LS + e);
+ bytes = Files.readAllBytes(path);
+ return bytes;
+ } catch (IOException e) {
+ throw new RuntimeException("System IO Error reading file: " + absPath + " " + e);
}
}
-
+
/**
- * Create an empty temporary file.
- * On a Mac these files are stored at the system variable $TMPDIR. They should be cleared on a reboot.
- * @param shortFileName the name before prefixes and suffixes are added here and by the OS.
- * The final extension will be the current extension. The prefix "temp_" is added here.
- * @return a temp file,which will be eventually deleted by the OS
+ * Puts all the bytes of the given byte array to a file with the given fileName.
+ * This assumes that the base directory path is {@link #javaPath javaPath}.
+ * @param fileName the name of the target file
+ * @param bytes the given byte array
*/
- private static File createTempFile(final String shortFileName) {
- //remove any leading slash
- final String resName = (shortFileName.charAt(0) == '/') ? shortFileName.substring(1) : shortFileName;
- final String suffix;
- final String name;
- final int lastIdx = resName.length() - 1;
- final int lastIdxOfDot = resName.lastIndexOf('.');
- if (lastIdxOfDot == -1) {
- suffix = ".tmp";
- name = resName;
- } else if (lastIdxOfDot == lastIdx) {
- suffix = ".tmp";
- name = resName.substring(0, lastIdxOfDot);
- } else { //has a real suffix
- suffix = resName.substring(lastIdxOfDot);
- name = resName.substring(0, lastIdxOfDot);
- }
- final File file;
+ public static void putBytesToJavaPathFile(final String fileName, final byte[] bytes) {
+ putBytesToFile(javaPath, fileName, bytes);
+ }
+
+ /**
+ * Puts all the bytes of the given byte array to a basePath file with the given fileName.
+ * @param basePath the directory path for the given fileName
+ * @param fileName the name of the target file
+ * @param bytes the given byte array
+ * @throws RuntimeException for IO errors,
+ */
+ public static void putBytesToFile(final Path basePath, final String fileName, final byte[] bytes) {
+ Objects.requireNonNull(basePath, "input parameter 'Path basePath' cannot be null.");
+ Objects.requireNonNull(fileName, "input parameter 'String fileName' cannot be null.");
+ Objects.requireNonNull(bytes, "input parameter 'byte[] bytes' cannot be null.");
+ Path filePath = null;
try {
- file = File.createTempFile("temp_" + name, suffix);
- if (!file.setReadable(false, true)) {
- throw new IllegalStateException("Failed to set only owner 'Readable' on file");
- }
- if (!file.setWritable(false, true)) {
- throw new IllegalStateException("Failed to set only owner 'Writable' on file");
- }
-
- } catch (final IOException e) { throw new RuntimeException(e); }
- return file;
+ Files.createDirectories(basePath); //create the directory if it doesn't exist.
+ filePath = basePath.resolve(fileName);
+ Files.write(filePath, bytes);
+ } catch (IOException e) {
+ throw new RuntimeException("System IO Error writing file: " + filePath.toString() + " " + e);
+ }
}
-
}
diff --git a/src/test/java/org/apache/datasketches/common/TestUtilTest.java b/src/test/java/org/apache/datasketches/common/TestUtilTest.java
new file mode 100644
index 000000000..420b05c12
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/common/TestUtilTest.java
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.datasketches.common;
+
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.resPath;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertTrue;
+//import static org.testng.internal.EclipseInterface.ASSERT_LEFT; // Ignore, standard imports
+import static org.testng.Assert.assertNotNull;
+
+import org.testng.annotations.AfterMethod;
+import org.testng.annotations.BeforeMethod;
+import org.testng.annotations.Test;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.Arrays;
+import static java.nio.charset.StandardCharsets.UTF_8;
+
+public class TestUtilTest {
+
+ @Test
+ public void testGetFileBytes_Success() throws IOException {
+ byte[] resultBytes = getFileBytes(resPath, "GettysburgAddress.txt");
+ assertNotNull(resultBytes);
+ String resultString = new String(resultBytes, UTF_8);
+ assertTrue(resultString.startsWith("Abraham Lincoln's Gettysburg Address:"));
+ }
+
+ @Test
+ public void testGetFileBytes_MissingFile() {
+ byte[] resultBytes = getFileBytes(resPath, "NonExistentFile");
+ assertNotNull(resultBytes);
+ assertEquals(resultBytes.length, 0, "Should return empty array for missing file.");
+ }
+
+ @Test
+ public void testGetFileBytes_NotRegular_NotReadable() throws IOException {
+ try {
+ getFileBytes(resPath, "");
+ } catch (RuntimeException e) {
+ System.out.println(e.toString());
+ }
+ }
+
+
+
+
+}
diff --git a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
index 912ed3a68..3389f99d3 100644
--- a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
@@ -22,6 +22,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_GO_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.goPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
@@ -75,7 +76,7 @@ public void allFlavors() throws IOException {
final Flavor[] flavorArr = {Flavor.EMPTY, Flavor.SPARSE, Flavor.HYBRID, Flavor.PINNED, Flavor.SLIDING};
int flavorIdx = 0;
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("cpc_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "cpc_n" + n + "_cpp.sk");
final CpcSketch sketch = CpcSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getFlavor(), flavorArr[flavorIdx++]);
assertEquals(sketch.getEstimate(), n, n * 0.02);
@@ -88,7 +89,7 @@ public void checkAllFlavorsGo() throws IOException {
final Flavor[] flavorArr = {Flavor.EMPTY, Flavor.SPARSE, Flavor.HYBRID, Flavor.PINNED, Flavor.SLIDING};
int flavorIdx = 0;
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(goPath.resolve("cpc_n" + n + "_go.sk"));
+ final byte[] bytes = getFileBytes(goPath, "cpc_n" + n + "_go.sk");
final CpcSketch sketch = CpcSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getFlavor(), flavorArr[flavorIdx++]);
assertEquals(sketch.getEstimate(), n, n * 0.02);
diff --git a/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java b/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java
index 0ecc060b8..bb2e9ccd1 100644
--- a/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -65,7 +66,7 @@ public void readBloomFilterBinariesForCompatibilityTesting() throws IOException
final short[] hArr = {3, 5};
for (final int n : nArr) {
for (final short numHashes : hArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("bf_n" + n + "_h" + numHashes + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath,"bf_n" + n + "_h" + numHashes + "_cpp.sk");
final BloomFilter bf = BloomFilter.heapify(MemorySegment.ofArray(bytes));
assertEquals(bf.isEmpty(), n == 0);
assertTrue(bf.isEmpty() || (bf.getBitsUsed() > (n / 10)));
diff --git a/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java
index 109d468be..74f417c38 100644
--- a/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -102,7 +103,7 @@ public void generateBinariesForCompatibilityTestingStringsSketchUtf8() throws IO
public void longs() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("frequent_long_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "frequent_long_n" + n + "_cpp.sk");
final FrequentLongsSketch sketch = FrequentLongsSketch.getInstance(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
if (n > 10) {
@@ -118,7 +119,7 @@ public void longs() throws IOException {
public void strings() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("frequent_string_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "frequent_string_n" + n + "_cpp.sk");
final FrequentItemsSketch sketch = FrequentItemsSketch.getInstance(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe());
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
if (n > 10) {
@@ -132,7 +133,7 @@ public void strings() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void stringsAscii() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("frequent_string_ascii_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "frequent_string_ascii_cpp.sk");
final FrequentItemsSketch sketch = FrequentItemsSketch.getInstance(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe());
assertFalse(sketch.isEmpty());
assertEquals(sketch.getMaximumError(), 0);
@@ -145,7 +146,7 @@ public void stringsAscii() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void stringsUtf8() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("frequent_string_utf8_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "frequent_string_utf8_cpp.sk");
final FrequentItemsSketch sketch = FrequentItemsSketch.getInstance(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe());
assertFalse(sketch.isEmpty());
assertEquals(sketch.getMaximumError(), 0);
diff --git a/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java
index e69d01621..51966007b 100644
--- a/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.apache.datasketches.hll.TgtHllType.HLL_4;
@@ -68,7 +69,7 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
public void hll4() throws IOException {
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("hll4_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "hll4_n" + n + "_cpp.sk");
final HllSketch sketch = HllSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getLgConfigK(), 12);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
@@ -80,7 +81,7 @@ public void hll4() throws IOException {
public void hll6() throws IOException {
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("hll6_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "hll6_n" + n + "_cpp.sk");
final HllSketch sketch = HllSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getLgConfigK(), 12);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
@@ -92,7 +93,7 @@ public void hll6() throws IOException {
public void hll8() throws IOException {
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("hll8_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "hll8_n" + n + "_cpp.sk");
final HllSketch sketch = HllSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getLgConfigK(), 12);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
diff --git a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java
index 45fb4d8c9..392e667c9 100644
--- a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java
@@ -22,8 +22,10 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_HISTORICAL_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.resPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
@@ -95,7 +97,7 @@ public void generateKllItemsSketchBinaries() throws IOException {
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void checkCppKllDoublesSketchOneItemVersion1() {
- final byte[] byteArr = TestUtil.getResourceBytes("kll_sketch_double_one_item_v1.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "kll_sketch_double_one_item_v1.sk");
final KllDoublesSketch sk = KllDoublesSketch.heapify(MemorySegment.ofArray(byteArr));
assertFalse(sk.isEmpty());
assertFalse(sk.isEstimationMode());
@@ -107,7 +109,7 @@ public void checkCppKllDoublesSketchOneItemVersion1() {
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void checkCppKllFloatsSketchOneItemVersion1() {
- final byte[] byteArr = TestUtil.getResourceBytes("kll_sketch_float_one_item_v1.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "kll_sketch_float_one_item_v1.sk");
final KllFloatsSketch sk = KllFloatsSketch.heapify(MemorySegment.ofArray(byteArr));
assertFalse(sk.isEmpty());
assertFalse(sk.isEstimationMode());
@@ -121,7 +123,7 @@ public void checkCppKllFloatsSketchOneItemVersion1() {
public void kllFloat() throws IOException {
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("kll_float_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "kll_float_n" + n + "_cpp.sk");
final KllFloatsSketch sketch = KllFloatsSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getK(), 200);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
@@ -146,7 +148,7 @@ public void kllFloat() throws IOException {
public void kllDouble() throws IOException {
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("kll_double_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "kll_double_n" + n + "_cpp.sk");
final KllDoublesSketch sketch = KllDoublesSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getK(), 200);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
@@ -184,7 +186,7 @@ public int compare(final String s1, final String s2) {
};
final int[] nArr = {0, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("kll_string_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "kll_string_n" + n + "_cpp.sk");
final KllHeapItemsSketch sketch = new KllHeapItemsSketch<>(
MemorySegment.ofArray(bytes),
numericOrder,
diff --git a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
index bb0b1bfde..0ef9c83d3 100644
--- a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
@@ -22,8 +22,10 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_HISTORICAL_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.resPath;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.EXCLUSIVE;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -91,7 +93,7 @@ public int compare(final String s1, final String s2) {
public void checkDoublesSketch() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] byteArr = Files.readAllBytes(cppPath.resolve("quantiles_double_n" + n + "_cpp.sk"));
+ final byte[] byteArr = getFileBytes(cppPath, "quantiles_double_n" + n + "_cpp.sk");
final QuantilesDoublesSketch sk = QuantilesDoublesSketch.wrap(MemorySegment.ofArray(byteArr));
assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
assertTrue(n > 128 ? sk.isEstimationMode() : !sk.isEstimationMode());
@@ -128,7 +130,7 @@ public int compare(final String s1, final String s2) {
};
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] byteArr = Files.readAllBytes(cppPath.resolve("quantiles_string_n" + n + "_cpp.sk"));
+ final byte[] byteArr = getFileBytes(cppPath, "quantiles_string_n" + n + "_cpp.sk");
final QuantilesItemsSketch sk = QuantilesItemsSketch.heapify(
String.class,
MemorySegment.ofArray(byteArr),
@@ -242,7 +244,7 @@ private static void getAndCheck(final String ver, final int n, final double quan
println("fullName: "+ fileName);
println("Old Median: " + quantile);
//Read File bytes
- final byte[] byteArr = TestUtil.getResourceBytes(fileName);
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, fileName);
final MemorySegment srcSeg = MemorySegment.ofArray(byteArr);
// heapify as update sketch
diff --git a/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
index e126f9b46..198dffe36 100644
--- a/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -56,7 +57,7 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
public void deserializeFromCpp() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("req_float_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "req_float_n" + n + "_cpp.sk");
final ReqSketch sk = ReqSketch.heapify(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
assertTrue(n > 10 ? sk.isEstimationMode() : !sk.isEstimationMode());
diff --git a/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
index dd759b05d..265f3ca90 100644
--- a/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -114,7 +115,7 @@ public void generateUnionDoubleSampling() throws IOException {
public void deserializeFromCppSketchLongs() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("varopt_sketch_long_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "varopt_sketch_long_n" + n + "_cpp.sk");
final VarOptItemsSketch sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfLongsSerDe());
assertEquals(sk.getK(), 32);
assertEquals(sk.getN(), n);
@@ -124,7 +125,7 @@ public void deserializeFromCppSketchLongs() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppSketchStringsExact() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("varopt_sketch_string_exact_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "varopt_sketch_string_exact_cpp.sk");
final VarOptItemsSketch sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe());
assertEquals(sk.getK(), 1024);
assertEquals(sk.getN(), 200);
@@ -139,7 +140,7 @@ public void deserializeFromCppSketchStringsExact() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppSketchLongsSampling() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("varopt_sketch_long_sampling_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "varopt_sketch_long_sampling_cpp.sk");
final VarOptItemsSketch sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfLongsSerDe());
assertEquals(sk.getK(), 1024);
assertEquals(sk.getN(), 2003);
@@ -156,7 +157,7 @@ public void deserializeFromCppSketchLongsSampling() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppUnionDoubleSampling() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("varopt_union_double_sampling_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "varopt_union_double_sampling_cpp.sk");
final VarOptItemsUnion u = VarOptItemsUnion.heapify(MemorySegment.ofArray(bytes), new ArrayOfDoublesSerDe());
// must reduce k in the process
diff --git a/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java b/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java
index 1ce3f7555..a46c06515 100644
--- a/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -40,9 +41,9 @@ public void deserializeFromCppDouble() throws IOException {
for (final int n : nArr) {
final byte[] bytes;
if (buffered) {
- bytes = Files.readAllBytes(cppPath.resolve("tdigest_double_buf_n" + n + "_cpp.sk"));
+ bytes = getFileBytes(cppPath, "tdigest_double_buf_n" + n + "_cpp.sk");
} else {
- bytes = Files.readAllBytes(cppPath.resolve("tdigest_double_n" + n + "_cpp.sk"));
+ bytes = getFileBytes(cppPath, "tdigest_double_n" + n + "_cpp.sk");
}
final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty());
@@ -70,9 +71,9 @@ public void deserializeFromCppFloat() throws IOException {
for (final int n : nArr) {
final byte[] bytes;
if (buffered) {
- bytes = Files.readAllBytes(cppPath.resolve("tdigest_float_buf_n" + n + "_cpp.sk"));
+ bytes = getFileBytes(cppPath, "tdigest_float_buf_n" + n + "_cpp.sk");
} else {
- bytes = Files.readAllBytes(cppPath.resolve("tdigest_float_n" + n + "_cpp.sk"));
+ bytes = getFileBytes(cppPath, "tdigest_float_n" + n + "_cpp.sk");
}
final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes), true);
assertTrue(n == 0 ? td.isEmpty() : !td.isEmpty());
diff --git a/src/test/java/org/apache/datasketches/tdigest/TDigestDoubleTest.java b/src/test/java/org/apache/datasketches/tdigest/TDigestDoubleTest.java
index b7a414d27..c940648be 100644
--- a/src/test/java/org/apache/datasketches/tdigest/TDigestDoubleTest.java
+++ b/src/test/java/org/apache/datasketches/tdigest/TDigestDoubleTest.java
@@ -19,6 +19,7 @@
package org.apache.datasketches.tdigest;
+import static org.apache.datasketches.common.TestUtil.resPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertThrows;
@@ -152,7 +153,7 @@ public void serializeDeserializeNonEmpty() {
@Test
public void deserializeFromReferenceImplementationDouble() {
- final byte[] bytes = TestUtil.getResourceBytes("tdigest_ref_k100_n10000_double.sk");
+ final byte[] bytes = TestUtil.getFileBytes(resPath, "tdigest_ref_k100_n10000_double.sk");
final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes));
final int n = 10000;
assertEquals(td.getK(), 100);
@@ -168,7 +169,7 @@ public void deserializeFromReferenceImplementationDouble() {
@Test
public void deserializeFromReferenceImplementationFloat() {
- final byte[] bytes = TestUtil.getResourceBytes("tdigest_ref_k100_n10000_float.sk");
+ final byte[] bytes = TestUtil.getFileBytes(resPath, "tdigest_ref_k100_n10000_float.sk");
final TDigestDouble td = TDigestDouble.heapify(MemorySegment.ofArray(bytes));
final int n = 10000;
assertEquals(td.getK(), 100);
diff --git a/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
index 3bfa8bc2c..1c27b56e6 100644
--- a/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -79,7 +80,7 @@ public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IO
public void deserializeFromCppSegment() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_n" + n + "_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -98,7 +99,7 @@ public void deserializeFromCppSegment() throws IOException {
public void deserializeFromCppBytes() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_n" + n + "_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(bytes);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -117,7 +118,7 @@ public void deserializeFromCppBytes() throws IOException {
public void deserializeFromCppCompressedSegment() throws IOException {
final int[] nArr = {10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_compressed_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_compressed_n" + n + "_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -136,7 +137,7 @@ public void deserializeFromCppCompressedSegment() throws IOException {
public void deserializeFromCppCompressedBytes() throws IOException {
final int[] nArr = {10, 100, 1000, 10000, 100000, 1000000};
for (final int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_compressed_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_compressed_n" + n + "_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(bytes);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -153,7 +154,7 @@ public void deserializeFromCppCompressedBytes() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppNonEmptyNoEntriesSegment() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_non_empty_no_entries_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_non_empty_no_entries_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(MemorySegment.ofArray(bytes));
assertFalse(sketch.isEmpty());
assertEquals(sketch.getRetainedEntries(), 0);
@@ -161,7 +162,7 @@ public void deserializeFromCppNonEmptyNoEntriesSegment() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppNonEmptyNoEntriesBytes() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("theta_non_empty_no_entries_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "theta_non_empty_no_entries_cpp.sk");
final CompactThetaSketch sketch = CompactThetaSketch.wrap(bytes);
assertFalse(sketch.isEmpty());
assertEquals(sketch.getRetainedEntries(), 0);
diff --git a/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java b/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java
index b2f70b7bb..b58905b2b 100644
--- a/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java
@@ -22,8 +22,10 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_HISTORICAL_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.resPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
@@ -47,7 +49,7 @@ public class TupleCrossLanguageTest {
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void serialVersion1Compatibility() {
- final byte[] byteArr = TestUtil.getResourceBytes("CompactSketchWithDoubleSummary4K_serialVersion1.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "CompactSketchWithDoubleSummary4K_serialVersion1.sk");
TupleSketch sketch = TupleSketch.heapifySketch(MemorySegment.ofArray(byteArr), new DoubleSummaryDeserializer());
Assert.assertTrue(sketch.isEstimationMode());
Assert.assertEquals(sketch.getEstimate(), 8192, 8192 * 0.99);
@@ -63,7 +65,7 @@ public void serialVersion1Compatibility() {
@Test(groups = {CHECK_CPP_HISTORICAL_FILES})
public void version2Compatibility() {
- final byte[] byteArr = TestUtil.getResourceBytes("TupleWithTestIntegerSummary4kTrimmedSerVer2.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "TupleWithTestIntegerSummary4kTrimmedSerVer2.sk");
TupleSketch sketch1 = TupleSketch.heapifySketch(MemorySegment.ofArray(byteArr), new IntegerSummaryDeserializer());
// construct the same way
@@ -88,7 +90,7 @@ public void version2Compatibility() {
public void deserializeFromCppIntegerSummary() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10_000, 100_000, 1_000_000};
for (int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("tuple_int_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "tuple_int_n" + n + "_cpp.sk");
final TupleSketch sketch =
TupleSketch.heapifySketch(MemorySegment.ofArray(bytes), new IntegerSummaryDeserializer());
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
@@ -117,13 +119,13 @@ public void generateForCppIntegerSummary() throws IOException {
@Test(expectedExceptions = SketchesArgumentException.class, groups = {CHECK_CPP_HISTORICAL_FILES})
public void noSupportHeapifyV0_9_1() throws Exception {
- final byte[] byteArr = TestUtil.getResourceBytes("ArrayOfDoublesUnion_v0.9.1.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "ArrayOfDoublesUnion_v0.9.1.sk");
ArrayOfDoublesUnion.heapify(MemorySegment.ofArray(byteArr));
}
@Test(expectedExceptions = SketchesArgumentException.class, groups = {CHECK_CPP_HISTORICAL_FILES})
public void noSupportWrapV0_9_1() throws Exception {
- final byte[] byteArr = TestUtil.getResourceBytes("ArrayOfDoublesUnion_v0.9.1.sk");
+ final byte[] byteArr = TestUtil.getFileBytes(resPath, "ArrayOfDoublesUnion_v0.9.1.sk");
ArrayOfDoublesUnion.wrap(MemorySegment.ofArray(byteArr));
}
diff --git a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
index faca658d8..bc751200f 100644
--- a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
@@ -21,6 +21,7 @@
import static org.apache.datasketches.common.TestUtil.CHECK_CPP_FILES;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.cppPath;
import static org.apache.datasketches.common.TestUtil.javaPath;
import static org.testng.Assert.assertEquals;
@@ -81,7 +82,7 @@ public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IO
public void deserializeFromCppOneValue() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("aod_1_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "aod_1_n" + n + "_cpp.sk");
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketch.wrap(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -97,7 +98,7 @@ public void deserializeFromCppOneValue() throws IOException {
public void deserializeFromCppThreeValues() throws IOException {
final int[] nArr = {0, 1, 10, 100, 1000, 10000, 100000, 1000000};
for (int n: nArr) {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("aod_3_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "aod_3_n" + n + "_cpp.sk");
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketch.wrap(MemorySegment.ofArray(bytes));
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
assertEquals(sketch.getEstimate(), n, n * 0.03);
@@ -113,7 +114,7 @@ public void deserializeFromCppThreeValues() throws IOException {
@Test(groups = {CHECK_CPP_FILES})
public void deserializeFromCppOneValueNonEmptyNoEntries() throws IOException {
- final byte[] bytes = Files.readAllBytes(cppPath.resolve("aod_1_non_empty_no_entries_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath, "aod_1_non_empty_no_entries_cpp.sk");
final ArrayOfDoublesSketch sketch = ArrayOfDoublesSketch.wrap(MemorySegment.ofArray(bytes));
assertFalse(sketch.isEmpty());
assertEquals(sketch.getRetainedEntries(), 0);
diff --git a/src/test/resources/GettysburgAddress.txt b/src/test/resources/GettysburgAddress.txt
new file mode 100644
index 000000000..3969d1766
--- /dev/null
+++ b/src/test/resources/GettysburgAddress.txt
@@ -0,0 +1,7 @@
+Abraham Lincoln's Gettysburg Address:
+
+ Four score and seven years ago our fathers brought forth on this continent, a new nation, conceived in Liberty, and dedicated to the proposition that all men are created equal.
+
+ Now we are engaged in a great civil war, testing whether that nation, or any nation so conceived and so dedicated, can long endure. We are met on a great battle-field of that war. We have come to dedicate a portion of that field, as a final resting place for those who here gave their lives that that nation might live. It is altogether fitting and proper that we should do this.
+
+ But, in a larger sense, we can not dedicate —- we can not consecrate —- we can not hallow —- this ground. The brave men, living and dead, who struggled here, have consecrated it, far above our poor power to add or detract. The world will little note, nor long remember what we say here, but it can never forget what they did here. It is for us the living, rather, to be dedicated here to the unfinished work which they who fought here have thus far so nobly advanced. It is rather for us to be here dedicated to the great task remaining before us -— that from these honored dead we take increased devotion to that cause for which they gave the last full measure of devotion -— that we here highly resolve that these dead shall not have died in vain -— that this nation, under God, shall have a new birth of freedom -— and that government of the people, by the people, for the people, shall not perish from the earth.