This is an automated email from the ASF dual-hosted git repository. leerho pushed a commit to branch Fix_get_file_bytes in repository https://gitbox.apache.org/repos/asf/datasketches-java.git
commit e693cfae4780c54f7e31043c0adad7d74d07e8a3 Author: Lee Rhodes <[email protected]> AuthorDate: Tue Feb 17 18:13:56 2026 -0800 This replaces a bunch of methods attempting to read file bytes with one method. They were not robust, especially in a Windows OS environment. --- .../org/apache/datasketches/common/TestUtil.java | 224 +++------------------ .../apache/datasketches/common/TestUtilTest.java | 66 ++++++ .../cpc/CpcSketchCrossLanguageTest.java | 5 +- .../bloomfilter/BloomFilterCrossLanguageTest.java | 3 +- .../FrequentItemsSketchCrossLanguageTest.java | 9 +- .../hll/HllSketchCrossLanguageTest.java | 7 +- .../datasketches/kll/KllCrossLanguageTest.java | 12 +- .../QuantilesSketchCrossLanguageTest.java | 8 +- .../req/ReqSketchCrossLanguageTest.java | 3 +- .../sampling/VarOptCrossLanguageTest.java | 9 +- .../tdigest/TDigestCrossLanguageTest.java | 9 +- .../datasketches/tdigest/TDigestDoubleTest.java | 5 +- .../theta/ThetaSketchCrossLanguageTest.java | 13 +- .../datasketches/tuple/TupleCrossLanguageTest.java | 12 +- .../arrayofdoubles/AodSketchCrossLanguageTest.java | 7 +- src/test/resources/GettysburgAddress.txt | 7 + 16 files changed, 161 insertions(+), 238 deletions(-) diff --git a/src/test/java/org/apache/datasketches/common/TestUtil.java b/src/test/java/org/apache/datasketches/common/TestUtil.java index 35180d003..e7017154a 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.URI; 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; @@ -51,216 +53,48 @@ public final class TestUtil { 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; - - /** - * 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. - */ - 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; - } - - /** - * 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. - */ - 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 goPath = Path.of(".", "serialization_test_data", "go_generated_files"); + /** - * Note: This is only needed in Java 8 as it is part of Java 9+. - * Read all bytes from the given <i>InputStream</i>. - * 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 <i>Integer.MAX_VALUE</i>. - * @param in the Input Stream - * @return byte array + * The project relative Path for /src/test/resources */ - public static byte[] readAllBytesFromInputStream(final InputStream in) { - return readBytesFromInputStream(Integer.MAX_VALUE, in); - } + public static final Path resPath = Path.of(".","src","test","resources"); - /** - * Note: This is only needed in Java 8 as is part of Java 9+. - * Read <i>numBytesToRead</i> 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 <i>Integer.MAX_VALUE</i>. - * @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. - - */ - public static byte[] readBytesFromInputStream(final int numBytesToRead, final InputStream in) { - if (numBytesToRead < 0) { throw new IllegalArgumentException("numBytesToRead must be positive or zero."); } - - List<byte[]> 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; - } + //Get Resources - 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; - } - return result; - } + private static final int BUF_SIZE = 1 << 13; - 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); + public static byte[] getFileBytes(Path basePath, 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 debugging + byte[] bytes = new byte[0]; //or null + if (Files.notExists(path)) { + System.err.println("File disappeared or not found: " + absPath); + return bytes; //or null } - } - - /** - * 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 - */ - 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); + if (!Files.isRegularFile(path) || !Files.isReadable(path)) { + throw new RuntimeException("Path is not a regular file or not readable: " + absPath); } - final File file; 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"); + bytes = Files.readAllBytes(path); + return bytes; + } catch (IOException e) { + throw new RuntimeException("System Error reading file: " + absPath + " " + e); } - - } catch (final IOException e) { throw new RuntimeException(e); } - return file; - } - + } } 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..d10b48a2f --- /dev/null +++ b/src/test/java/org/apache/datasketches/common/TestUtilTest.java @@ -0,0 +1,66 @@ +/* + * 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 { + byte[] resultBytes = 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 @@ package org.apache.datasketches.cpc; 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 class CpcSketchCrossLanguageTest { 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 class CpcSketchCrossLanguageTest { 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 @@ package org.apache.datasketches.filters.bloomfilter; 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 class BloomFilterCrossLanguageTest { 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 @@ package org.apache.datasketches.frequencies; 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 class FrequentItemsSketchCrossLanguageTest { 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 class FrequentItemsSketchCrossLanguageTest { 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<String> sketch = FrequentItemsSketch.getInstance(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe()); assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty()); if (n > 10) { @@ -132,7 +133,7 @@ public class FrequentItemsSketchCrossLanguageTest { @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<String> sketch = FrequentItemsSketch.getInstance(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe()); assertFalse(sketch.isEmpty()); assertEquals(sketch.getMaximumError(), 0); @@ -145,7 +146,7 @@ public class FrequentItemsSketchCrossLanguageTest { @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<String> 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 @@ package org.apache.datasketches.hll; 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 class HllSketchCrossLanguageTest { 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 class HllSketchCrossLanguageTest { 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 class HllSketchCrossLanguageTest { 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 @@ package org.apache.datasketches.kll; 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 class KllCrossLanguageTest { @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 class KllCrossLanguageTest { @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 class KllCrossLanguageTest { 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 class KllCrossLanguageTest { 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 class KllCrossLanguageTest { }; 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<String> 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 @@ package org.apache.datasketches.quantiles; 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 class QuantilesSketchCrossLanguageTest { 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 class QuantilesSketchCrossLanguageTest { }; 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<String> sk = QuantilesItemsSketch.heapify( String.class, MemorySegment.ofArray(byteArr), @@ -242,7 +244,7 @@ public class QuantilesSketchCrossLanguageTest { 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 @@ package org.apache.datasketches.req; 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 class ReqSketchCrossLanguageTest { 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 @@ package org.apache.datasketches.sampling; 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 class VarOptCrossLanguageTest { 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<Long> sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfLongsSerDe()); assertEquals(sk.getK(), 32); assertEquals(sk.getN(), n); @@ -124,7 +125,7 @@ public class VarOptCrossLanguageTest { @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<String> sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfStringsSerDe()); assertEquals(sk.getK(), 1024); assertEquals(sk.getN(), 200); @@ -139,7 +140,7 @@ public class VarOptCrossLanguageTest { @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<Long> sk = VarOptItemsSketch.heapify(MemorySegment.ofArray(bytes), new ArrayOfLongsSerDe()); assertEquals(sk.getK(), 1024); assertEquals(sk.getN(), 2003); @@ -156,7 +157,7 @@ public class VarOptCrossLanguageTest { @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<Double> 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 @@ package org.apache.datasketches.tdigest; 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 class TDigestCrossLanguageTest { 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 class TDigestCrossLanguageTest { 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 class TDigestDoubleTest { @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 class TDigestDoubleTest { @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 @@ package org.apache.datasketches.theta; 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 class ThetaSketchCrossLanguageTest { 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 class ThetaSketchCrossLanguageTest { 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 class ThetaSketchCrossLanguageTest { 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 class ThetaSketchCrossLanguageTest { 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 class ThetaSketchCrossLanguageTest { @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 class ThetaSketchCrossLanguageTest { @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 @@ package org.apache.datasketches.tuple; 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<DoubleSummary> 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 class TupleCrossLanguageTest { @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<IntegerSummary> sketch1 = TupleSketch.heapifySketch(MemorySegment.ofArray(byteArr), new IntegerSummaryDeserializer()); // construct the same way @@ -88,7 +90,7 @@ public class TupleCrossLanguageTest { 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<IntegerSummary> sketch = TupleSketch.heapifySketch(MemorySegment.ofArray(bytes), new IntegerSummaryDeserializer()); assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty()); @@ -117,13 +119,13 @@ public class TupleCrossLanguageTest { @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 @@ package org.apache.datasketches.tuple.arrayofdoubles; 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 class AodSketchCrossLanguageTest { 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 class AodSketchCrossLanguageTest { 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 class AodSketchCrossLanguageTest { @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 unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
