diff --git a/pom.xml b/pom.xml
index a5ab62239..f70224b77 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,12 +25,6 @@ under the License.
4.0.0
-
- org.apache
- apache
- 35
-
-
org.apache.datasketches
datasketches-java
9.0.1-SNAPSHOT
@@ -82,7 +76,7 @@ under the License.
- 7.11.0
+ 7.12.0
generate_java_files
check_cpp_files
@@ -90,30 +84,49 @@ under the License.
check_cpp_historical_files
- 3.9.11
+ 3.9.12
25
-
- -Xmx4g
+ ${java.version}
+ -Xmx4g
+ -Duser.language=en
+ -Duser.country=US
+ -Dfile.encoding=UTF-8
+ ${jvm.mem} ${jvm.locale.language} ${jvm.locale.country} ${jvm.locale.encoding}
UTF-8
${charset.encoding}
${charset.encoding}
${charset.encoding}
yyyy-MM-dd'T'HH-mm-ss'Z'
-
+
+
+ 3.8.0
+ 3.15.0
+ 3.1.4
+ 3.6.2
+ 3.2.8
+ 3.5.0
3.12.0
+ 3.3.1
+ 3.4.0
+ 3.5.4
+
+
+ 0.17
+
+
3.2.0
-
- 4.9.10
-
- 0.17
-
+
+
- 4.3.0
+ 5.0.0
+
+
+ 9.0.2
+
0.8.14
-
- 2.19.1
+
1.0.0
@@ -129,22 +142,258 @@ under the License.
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
-
- ${testng.generate-java-files},${testng.check-cpp-files},${testng.check-go-files},${testng.check-cpp-historical-files}
-
-
-
-
+
+
+ org.apache.maven.plugins
+ maven-assembly-plugin
+ ${maven-assembly-plugin.version}
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+ ${maven-compiler-plugin.version}
+
+ true
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-deploy-plugin
+ ${maven-deploy-plugin.version}
+
+
+
+ org.apache.maven.plugins
+ maven-enforcer-plugin
+ ${maven-enforcer-plugin.version}
+
+
+ enforce-banned-dependencies
+
+ enforce
+
+
+
+
+
+ [${maven.version},4.0.0)
+
+
+
+
+ com.google.code.findbugs:annotations
+
+
+
+ true
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ ${maven-jar-plugin.version}
+
+
+ default-jar
+ package
+
+ jar
+
+
+
+ default-test-jar
+ package
+
+ test-jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-javadoc-plugin
+ ${maven-javadoc-plugin.version}
+
+ true
+ public
+ all,-missing
+
+ -J${jvm.mem}
+ -J${jvm.locale.language}
+ -J${jvm.locale.country}
+ -J${jvm.locale.encoding}
+
+
+
+
+ attach-javadocs
+
+ jar
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-release-plugin
+ ${maven-release-plugin.version}
+
+
+
+ org.apache.maven.plugins
+ maven-source-plugin
+ ${maven-source-plugin.version}
+
+
+ attach-sources
+ package
+
+ jar-no-fork
+
+
+
+ attach-test-sources
+ package
+
+ test-jar-no-fork
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ ${maven-surefire-failsafe-plugins.version}
+
+ @{argLine} @{jvm.args}
+
+ ${java.version}
+
+ false
+ false
+ false
+ ${project.build.directory}/test-output
+
+ src/test/resources/testng.xml
+
+ false
+ ${testng.generate-java-files},${testng.check-cpp-files},${testng.check-go-files},${testng.check-cpp-historical-files}
+
+
+
+
+ org.apache.maven.plugins
+ maven-toolchains-plugin
+ ${maven-toolchains-plugin.version}
+
+
+
+ toolchain
+
+
+
+
+
+
+ ${java.version}
+
+
+
+
+
+
+ org.apache.rat
+ apache-rat-plugin
+ ${apache-rat-plugin.version}
+
+
+ verify
+
+ check
+
+
+
+
+ ${project.basedir}/rat
+ true
+
+
+ StandardCollection
+ **/*.yaml
+ **/*.yml
+ **/.*
+ **/test/resources/**/*.txt
+ **/git.properties
+ **/doc/**
+ **/*.sk
+ LICENSE
+ NOTICE
+ **/*.code-workspace
+
+
+
+
+
+
+ com.github.hazendaz.maven
+ coveralls-maven-plugin
+ ${coveralls-maven-plugin.version}
+
+ ${coveralls-repo-token}
+
+
+
+
+ io.github.git-commit-id
+ git-commit-id-maven-plugin
+ ${git-commit-id-maven-plugin.version}
+
+
+
+
+ org.jacoco
+ jacoco-maven-plugin
+ ${jacoco-maven-plugin.version}
+
+
+ default-prepare-agent
+
+ prepare-agent
+
+
+
+ default-report
+ test
+
+ report
+
+
+
+
+
+
+
+
+
+
org.apache.maven.plugins
maven-assembly-plugin
@@ -153,23 +402,9 @@ under the License.
org.apache.maven.plugins
maven-compiler-plugin
-
- true
- ${java.version}
-
- -J${jvm.options}
-
-
-
-
-
- org.apache.maven.plugins
- maven-dependency-plugin
-
-
org.apache.maven.plugins
maven-deploy-plugin
@@ -177,78 +412,16 @@ under the License.
org.apache.maven.plugins
maven-enforcer-plugin
-
-
- enforce-banned-dependencies
-
- enforce
-
-
-
-
- [25,)
-
-
- [${maven.version},)
-
-
-
-
-
- com.google.code.findbugs:annotations
-
-
-
- true
-
-
-
org.apache.maven.plugins
maven-jar-plugin
-
-
- default-jar
- package
-
- jar
-
-
-
- default-test-jar
- package
-
- test-jar
-
-
-
org.apache.maven.plugins
maven-javadoc-plugin
- ${maven-javadoc-plugin.version}
-
- ${project.reporting.outputDirectory}
- ${project.reporting.outputDirectory}
- true
- public
- all,-missing
- ${java.version}
-
- -J${jvm.options}
-
-
-
-
- attach-javadocs
-
- jar
-
-
-
@@ -259,132 +432,36 @@ under the License.
org.apache.maven.plugins
maven-source-plugin
-
-
- attach-sources
- package
-
- jar-no-fork
-
-
-
- attach-test-sources
- package
-
- test-jar-no-fork
-
-
-
org.apache.maven.plugins
maven-surefire-plugin
-
- 1
- true
- ${argLine} ${jvm.options}
- false
- false
- true
- ${project.build.directory}/test-output/${maven.build.timestamp}
-
org.apache.maven.plugins
maven-toolchains-plugin
- ${maven-toolchains-plugin.version}
-
-
-
- toolchain
-
-
-
-
-
-
- ${java.version}
-
-
-
org.apache.rat
apache-rat-plugin
- ${apache-rat-plugin.version}
-
-
- verify
-
- check
-
-
-
-
- ${project.basedir}/rat
- true
-
-
- StandardCollection
- **/*.yaml
- **/*.yml
- **/.*
- **/test/resources/**/*.txt
- **/git.properties
- **/doc/**
- **/*.sk
- LICENSE
- NOTICE
- **/*.code-workspace
-
-
- org.codehaus.mojo
- versions-maven-plugin
- ${versions-maven-plugin.version}
+ com.github.hazendaz.maven
+ coveralls-maven-plugin
-
- org.eluder.coveralls
- coveralls-maven-plugin
- ${coveralls-maven-plugin.version}
-
- ${coveralls-repo-token}
-
+ io.github.git-commit-id
+ git-commit-id-maven-plugin
-
org.jacoco
jacoco-maven-plugin
- ${jacoco-maven-plugin.version}
-
-
- default-prepare-agent
-
- prepare-agent
-
-
-
- default-report
- test
-
- report
-
-
-
-
-
-
- pl.project13.maven
- git-commit-id-plugin
- ${git-commit-id-plugin.version}
@@ -407,11 +484,12 @@ under the License.
- pl.project13.maven
- git-commit-id-plugin
- ${git-commit-id-plugin.version}
+ io.github.git-commit-id
+ git-commit-id-maven-plugin
+ ${git-commit-id-maven-plugin.version}
+ get-the-git-infos
revision
@@ -433,7 +511,7 @@ under the License.
git.branch
git.commit.id.full
-
+ git.commit.time
git.commit.user.email
git.tags
@@ -472,14 +550,13 @@ under the License.
false
false
- false
+ true
+ true
- ${java.version} (${java.vendor} ${java.vm.version})
- ${os.name} ${os.arch} ${os.version}
The Apache Software Foundation
${project.groupId}:${project.artifactId}
-
+
${git.branch}
@@ -499,6 +576,7 @@ under the License.
org.apache.maven.plugins
maven-gpg-plugin
+ ${maven-gpg-plugin.version}
sign-artifacts
@@ -521,8 +599,8 @@ under the License.
- pl.project13.maven
- git-commit-id-plugin
+ io.github.git-commit-id
+ git-commit-id-maven-plugin
org.apache.maven.plugins
@@ -536,6 +614,26 @@ under the License.
+
+
+ apache-release
+
+
+
+ maven-assembly-plugin
+ ${maven-assembly-plugin.version}
+
+
+ source-release-assembly
+ none
+
+
+
+
+
+
+
generate-java-files
@@ -614,4 +712,5 @@ under the License.
+
diff --git a/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java b/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java
new file mode 100644
index 000000000..97fe267ff
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/common/A_BeforeSuite.java
@@ -0,0 +1,33 @@
+/*
+ * 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 org.testng.annotations.BeforeSuite;
+
+public class A_BeforeSuite {
+
+ @BeforeSuite(alwaysRun = true)
+ public void printTestEnvironment() {
+ System.out.println("====================================================");
+ System.out.println("TEST JDK: " + System.getProperty("java.version"));
+ System.out.println("TEST JDK HOME: " + System.getProperty("java.home"));
+ System.out.println("=====================================================");
+ }
+}
diff --git a/src/test/java/org/apache/datasketches/common/TestUtil.java b/src/test/java/org/apache/datasketches/common/TestUtil.java
index 35180d003..dc4c9d5e7 100644
--- a/src/test/java/org/apache/datasketches/common/TestUtil.java
+++ b/src/test/java/org/apache/datasketches/common/TestUtil.java
@@ -19,20 +19,9 @@
package org.apache.datasketches.common;
-import java.io.File;
-import java.io.FileOutputStream;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
import java.util.Objects;
/**
@@ -40,227 +29,112 @@
*/
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);
- }
+ public enum Existence { MUST_EXIST, WARNING }
/**
- * 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 either throws an exception or writes a warning message to the console
+ * based on the state of the optional {@link #Existence Existence}.
+ * @param basePath the base directory path where the file is located
+ * @param fileName the simple file name of the file
+ * @param option an optional parameter. If option == Existence.MUST_EXIST and the file does not exist an exception will be thrown.
+ * If option == Existence.WARNING, or not given, and the file does not exist, it writes a warning message
+ * to {@link System.err.out System.err.out}.
+ * If option has more than one argument an exception will be thrown.
+ * @return a byte array. It may be empty.
+ * @throws RuntimeException for IO errors, or if resolved path is not a file or not readable or optionally not found.
*/
- 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, Existence... option) {
+ Objects.requireNonNull(basePath, "input parameter 'Path basePath' cannot be null.");
+ Objects.requireNonNull(fileName, "input parameter 'String fileName' cannot be null.");
+ if (option.length > 1) { throw new IllegalArgumentException("Existence option has a maximum of one argument"); }
+ Existence status = (option.length == 1) ? option[0] : Existence.WARNING;
+
+ Path path = Path.of(basePath.toString(), fileName);
+ Path absPath = path.toAbsolutePath(); //for error output
+ if (Files.notExists(path)) {
+ if (status == Existence.MUST_EXIST) {
+ throw new RuntimeException("File disappeared or not found: " + absPath);
+ } else {
+ System.err.println("WARNING: File disappeared or not found: " + absPath);
+ return new byte[0];
+ }
}
-
- 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);
+ byte[] 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;
- 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;
+ public static void putBytesToJavaPath(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.
+ * If the file exists it will be overwritten.
+ * @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 {
+ Files.createDirectories(basePath); //create the directory if it doesn't exist.
+ filePath = basePath.resolve(fileName);
+ Files.write(filePath, bytes);
+ } catch (IOException e) {
+ final String filePathDesc = String.valueOf(filePath);
+ throw new RuntimeException("System IO Error writing file: " + filePathDesc + " " + 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..e8051fe88
--- /dev/null
+++ b/src/test/java/org/apache/datasketches/common/TestUtilTest.java
@@ -0,0 +1,74 @@
+/*
+ * 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 java.nio.charset.StandardCharsets.UTF_8;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToFile;
+import static org.apache.datasketches.common.TestUtil.resPath;
+import static org.apache.datasketches.common.TestUtil.Existence.MUST_EXIST;
+import static org.apache.datasketches.common.TestUtil.Existence.WARNING;
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertNotNull;
+import static org.testng.Assert.assertTrue;
+
+import java.io.IOException;
+import java.nio.file.Path;
+
+import org.testng.annotations.Test;
+
+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_Warning() {
+ byte[] resultBytes = getFileBytes(resPath, "Test_NonExistentFile_OK", WARNING); //WARNING is the default
+ assertNotNull(resultBytes);
+ assertEquals(resultBytes.length, 0, "Should return empty array for missing file.");
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testGetFileBytes_MissingFile_MustExist() {
+ getFileBytes(resPath, "Test_NonExistentFile_OK", MUST_EXIST);
+ }
+
+ @Test(expectedExceptions = RuntimeException.class)
+ public void testGetFileBytes_NotRegular_NotReadable() throws IOException {
+ getFileBytes(resPath, "");
+ }
+
+ private static final Path testPath = Path.of(".", "target", "testDir");
+
+ @Test
+ public void testPutBytesToFile() {
+ byte[] gettysBytes = getFileBytes(resPath, "GettysburgAddress.txt");
+ putBytesToFile(testPath, "GettysburgAddressCopy.txt", gettysBytes);
+ byte[] gettysBytes2 = getFileBytes(testPath, "GettysburgAddressCopy.txt");
+ assertEquals(gettysBytes, gettysBytes2);
+ }
+
+}
diff --git a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
index 912ed3a68..b0f3ef77f 100644
--- a/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/cpc/CpcSketchCrossLanguageTest.java
@@ -23,13 +23,13 @@
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.cppPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
import static org.apache.datasketches.common.TestUtil.goPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
import org.testng.annotations.Test;
@@ -50,7 +50,7 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
sk.update(i);
}
assertEquals(sk.getFlavor(), flavorArr[flavorIdx++]);
- Files.newOutputStream(javaPath.resolve("cpc_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("cpc_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -66,7 +66,7 @@ void negativeIntEquivalence() throws Exception {
final long v4 = -1;
sk.update(v4);
assertEquals(sk.getEstimate(), 1, 0.01);
- Files.newOutputStream(javaPath.resolve("cpc_negative_one_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("cpc_negative_one_java.sk", sk.toByteArray());
}
@Test(groups = {CHECK_CPP_FILES})
@@ -75,7 +75,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 +88,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..4decdb91c 100644
--- a/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/filters/bloomfilter/BloomFilterCrossLanguageTest.java
@@ -22,16 +22,14 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
-import org.apache.datasketches.filters.bloomfilter.BloomFilter;
-import org.apache.datasketches.filters.bloomfilter.BloomFilterBuilder;
import org.testng.annotations.Test;
/**
@@ -41,7 +39,7 @@
public class BloomFilterCrossLanguageTest {
@Test(groups = {GENERATE_JAVA_FILES})
- public void generatBloomFilterBinariesForCompatibilityTesting() throws IOException {
+ public void generateBloomFilterBinariesForCompatibilityTesting() throws IOException {
final int[] nArr = {0, 10_000, 2_000_000, 300_000_00};
final short[] hArr = {3, 5};
for (final int n : nArr) {
@@ -54,7 +52,7 @@ public void generatBloomFilterBinariesForCompatibilityTesting() throws IOExcepti
if (n > 0) { bf.update(Float.NaN); }
assertEquals(bf.isEmpty(), n == 0);
assertTrue(bf.isEmpty() || (bf.getBitsUsed() > (n / 10)));
- Files.newOutputStream(javaPath.resolve("bf_n" + n + "_h" + numHashes + "_java.sk")).write(bf.toByteArray());
+ putBytesToJavaPath("bf_n" + n + "_h" + numHashes + "_java.sk", bf.toByteArray());
}
}
}
@@ -65,7 +63,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..49a735df7 100644
--- a/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/frequencies/FrequentItemsSketchCrossLanguageTest.java
@@ -22,18 +22,16 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
import org.apache.datasketches.common.ArrayOfStringsSerDe;
-import org.apache.datasketches.frequencies.FrequentItemsSketch;
-import org.apache.datasketches.frequencies.FrequentLongsSketch;
import org.testng.annotations.Test;
/**
@@ -53,7 +51,7 @@ public void generateBinariesForCompatibilityTestingLongsSketch() throws IOExcept
assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
if (n > 10) { assertTrue(sk.getMaximumError() > 0); }
else { assertEquals(sk.getMaximumError(), 0); }
- Files.newOutputStream(javaPath.resolve("frequent_long_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("frequent_long_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -68,8 +66,7 @@ public void generateBinariesForCompatibilityTestingStringsSketch() throws IOExce
assertTrue(n == 0 ? sk.isEmpty() : !sk.isEmpty());
if (n > 10) { assertTrue(sk.getMaximumError() > 0); }
else { assertEquals(sk.getMaximumError(), 0); }
- Files.newOutputStream(javaPath.resolve("frequent_string_n" + n + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("frequent_string_n" + n + "_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
}
@@ -80,8 +77,7 @@ public void generateBinariesForCompatibilityTestingStringsSketchAscii() throws I
sk.update("bbbbbbbbbbbbbbbbbbbbbbbbbbbbb", 2);
sk.update("ccccccccccccccccccccccccccccc", 3);
sk.update("ddddddddddddddddddddddddddddd", 4);
- Files.newOutputStream(javaPath.resolve("frequent_string_ascii_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("frequent_string_ascii_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -94,15 +90,14 @@ public void generateBinariesForCompatibilityTestingStringsSketchUtf8() throws IO
sk.update("уфхцч", 5);
sk.update("шщъыь", 6);
sk.update("эюя", 7);
- Files.newOutputStream(javaPath.resolve("frequent_string_utf8_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("frequent_string_utf8_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
@Test(groups = {CHECK_CPP_FILES})
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 +113,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 +127,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 +140,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..51932d554 100644
--- a/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/hll/HllSketchCrossLanguageTest.java
@@ -22,18 +22,17 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.apache.datasketches.hll.TgtHllType.HLL_4;
import static org.apache.datasketches.hll.TgtHllType.HLL_6;
import static org.apache.datasketches.hll.TgtHllType.HLL_8;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
-import org.apache.datasketches.hll.HllSketch;
import org.testng.annotations.Test;
/**
@@ -58,9 +57,9 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
for (int i = 0; i < n; i++) {
hll8.update(i);
}
- Files.newOutputStream(javaPath.resolve("hll4_n" + n + "_java.sk")).write(hll4.toCompactByteArray());
- Files.newOutputStream(javaPath.resolve("hll6_n" + n + "_java.sk")).write(hll6.toCompactByteArray());
- Files.newOutputStream(javaPath.resolve("hll8_n" + n + "_java.sk")).write(hll8.toCompactByteArray());
+ putBytesToJavaPath("hll4_n" + n + "_java.sk", hll4.toCompactByteArray());
+ putBytesToJavaPath("hll6_n" + n + "_java.sk", hll6.toCompactByteArray());
+ putBytesToJavaPath("hll8_n" + n + "_java.sk", hll8.toCompactByteArray());
}
}
@@ -68,7 +67,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 +79,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 +91,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 f1b578229..3ce30ec1e 100644
--- a/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/kll/KllCrossLanguageTest.java
@@ -23,24 +23,20 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
+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;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
import java.util.Comparator;
import org.apache.datasketches.common.ArrayOfStringsSerDe;
import org.apache.datasketches.common.TestUtil;
import org.apache.datasketches.common.Util;
-import org.apache.datasketches.kll.KllDoublesSketch;
-import org.apache.datasketches.kll.KllFloatsSketch;
-import org.apache.datasketches.kll.KllHeapItemsSketch;
-import org.apache.datasketches.kll.KllItemsSketch;
-import org.apache.datasketches.kll.KllLongsSketch;
import org.apache.datasketches.quantilescommon.QuantilesDoublesSketchIteratorAPI;
import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator;
import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIteratorAPI;
@@ -59,7 +55,7 @@ public void generateKllDoublesSketchBinaries() throws IOException {
for (final int n: nArr) {
final KllDoublesSketch sk = KllDoublesSketch.newHeapInstance();
for (int i = 1; i <= n; i++) { sk.update(i); }
- Files.newOutputStream(javaPath.resolve("kll_double_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("kll_double_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -69,7 +65,7 @@ public void generateKllFloatsSketchBinaries() throws IOException {
for (final int n: nArr) {
final KllFloatsSketch sk = KllFloatsSketch.newHeapInstance();
for (int i = 1; i <= n; i++) { sk.update(i); }
- Files.newOutputStream(javaPath.resolve("kll_float_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("kll_float_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -79,7 +75,7 @@ public void generateKllLongsSketchBinaries() throws IOException {
for (final int n: nArr) {
final KllLongsSketch sk = KllLongsSketch.newHeapInstance();
for (int i = 1; i <= n; i++) { sk.update(i); }
- Files.newOutputStream(javaPath.resolve("kll_long_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("kll_long_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -90,13 +86,13 @@ public void generateKllItemsSketchBinaries() throws IOException {
final int digits = Util.numDigits(n);
final KllItemsSketch sk = KllItemsSketch.newHeapInstance(Comparator.naturalOrder(), serDe);
for (int i = 1; i <= n; i++) { sk.update(Util.longToFixedLengthString(i, digits)); }
- Files.newOutputStream(javaPath.resolve("kll_string_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("kll_string_n" + n + "_java.sk", sk.toByteArray());
}
}
@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());
@@ -108,7 +104,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());
@@ -122,7 +118,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());
@@ -147,7 +143,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());
@@ -185,7 +181,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,
@@ -214,7 +210,7 @@ public int compare(final String s1, final String s2) {
public void kllLong() 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_long_n" + n + "_cpp.sk"));
+ final byte[] bytes = getFileBytes(cppPath,"kll_long_n" + n + "_cpp.sk");
final KllLongsSketch sketch = KllLongsSketch.heapify(MemorySegment.ofArray(bytes));
assertEquals(sketch.getK(), 200);
assertTrue(n == 0 ? sketch.isEmpty() : !sketch.isEmpty());
diff --git a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
index bb0b1bfde..53746c260 100644
--- a/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/quantiles/QuantilesSketchCrossLanguageTest.java
@@ -23,14 +23,15 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
+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;
import java.io.IOException;
import java.lang.foreign.MemorySegment;
-import java.nio.file.Files;
import java.util.Comparator;
import org.apache.datasketches.common.ArrayOfStringsSerDe;
@@ -55,7 +56,7 @@ public void generateDoublesSketch() throws IOException {
for (int i = 1; i <= n; i++) {
sk.update(i);
}
- Files.newOutputStream(javaPath.resolve("quantiles_double_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("quantiles_double_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -82,8 +83,7 @@ public int compare(final String s1, final String s2) {
assertEquals(sk.getMinItem(), "1");
assertEquals(sk.getMaxItem(), Integer.toString(n));
}
- Files.newOutputStream(javaPath.resolve("quantiles_string_n" + n + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("quantiles_string_n" + n + "_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
}
@@ -91,7 +91,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 +128,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 +242,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..0e7fbee59 100644
--- a/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/req/ReqSketchCrossLanguageTest.java
@@ -22,16 +22,15 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
import org.apache.datasketches.quantilescommon.QuantilesFloatsSketchIterator;
-import org.apache.datasketches.req.ReqSketch;
import org.testng.annotations.Test;
/**
@@ -48,7 +47,7 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
for (int i = 1; i <= n; i++) {
sk.update(i);
}
- Files.newOutputStream(javaPath.resolve("req_float_n" + n + "_java.sk")).write(sk.toByteArray());
+ putBytesToJavaPath("req_float_n" + n + "_java.sk", sk.toByteArray());
}
}
@@ -56,7 +55,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/ReservoirCrossLanguageTest.java b/src/test/java/org/apache/datasketches/sampling/ReservoirCrossLanguageTest.java
index 781fbebca..564f3b53b 100644
--- a/src/test/java/org/apache/datasketches/sampling/ReservoirCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/ReservoirCrossLanguageTest.java
@@ -19,19 +19,18 @@
package org.apache.datasketches.sampling;
+import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
+
+import java.io.IOException;
+import java.util.ArrayList;
+
import org.apache.datasketches.common.ArrayOfDoublesSerDe;
import org.apache.datasketches.common.ArrayOfLongsSerDe;
import org.apache.datasketches.common.ArrayOfStringsSerDe;
import org.apache.datasketches.common.ResizeFactor;
import org.testng.annotations.Test;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.util.ArrayList;
-
-import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
-import static org.apache.datasketches.common.TestUtil.javaPath;
-
/**
* Serialize binary sketches to be tested by other language code.
* Test deserialization of binary sketches serialized by other language code.
@@ -43,8 +42,7 @@ public void generateReservoirLongsSketchEmpty() throws IOException {
final int k = 128;
final ReservoirLongsSketch sk = ReservoirLongsSketch.newInstance(k);
- Files.newOutputStream(javaPath.resolve("reservoir_longs_empty_k" + k + "_java.sk"))
- .write(sk.toByteArray());
+ putBytesToJavaPath("reservoir_longs_empty_k" + k + "_java.sk", sk.toByteArray());
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -57,8 +55,7 @@ public void generateReservoirLongsSketchExact() throws IOException {
for (int i = 0; i < n; i++) {
sk.update(i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_longs_exact_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray());
+ putBytesToJavaPath("reservoir_longs_exact_n" + n + "_k" + k + "_java.sk", sk.toByteArray());
}
}
@@ -80,8 +77,7 @@ public void generateReservoirLongsSketchSampling() throws IOException {
k
);
- Files.newOutputStream(javaPath.resolve("reservoir_longs_sampling_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray());
+ putBytesToJavaPath("reservoir_longs_sampling_n" + n + "_k" + k + "_java.sk", sk.toByteArray());
}
}
@@ -90,8 +86,7 @@ public void generateReservoirLongsUnionEmpty() throws IOException {
int maxK = 128;
ReservoirLongsUnion union = ReservoirLongsUnion.newInstance(maxK);
- Files.newOutputStream(javaPath.resolve("reservoir_longs_union_empty_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray());
+ putBytesToJavaPath("reservoir_longs_union_empty_maxk" + maxK + "_java.sk", union.toByteArray());
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -104,8 +99,7 @@ public void generateReservoirLongsUnionExact() throws IOException {
for (int i = 0; i < n; i++) {
union.update(i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_longs_union_exact_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray());
+ putBytesToJavaPath("reservoir_longs_union_exact_n" + n + "_maxk" + maxK + "_java.sk", union.toByteArray());
}
}
@@ -130,8 +124,7 @@ public void generateReservoirLongsUnionSampling() throws IOException {
ReservoirLongsUnion union = ReservoirLongsUnion.newInstance(maxK);
union.update(sk);
- Files.newOutputStream(javaPath.resolve("reservoir_longs_union_sampling_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray());
+ putBytesToJavaPath("reservoir_longs_union_sampling_n" + n + "_maxk" + maxK + "_java.sk", union.toByteArray());
}
}
@@ -140,8 +133,7 @@ public void generateReservoirItemsSketchLongEmpty() throws IOException {
final int k = 128;
final ReservoirItemsSketch sk = ReservoirItemsSketch.newInstance(k);
- Files.newOutputStream(javaPath.resolve("reservoir_items_long_empty_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_long_empty_k" + k + "_java.sk", sk.toByteArray(new ArrayOfLongsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -154,8 +146,7 @@ public void generateReservoirItemsSketchLongExact() throws IOException {
for (int i = 0; i < n; i++) {
sk.update((long) i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_long_exact_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_long_exact_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfLongsSerDe()));
}
}
@@ -177,8 +168,7 @@ public void generateReservoirItemsSketchLongSampling() throws IOException {
k
);
- Files.newOutputStream(javaPath.resolve("reservoir_items_long_sampling_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_long_sampling_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfLongsSerDe()));
}
}
@@ -187,8 +177,7 @@ public void generateReservoirItemsSketchDoubleEmpty() throws IOException {
final int k = 128;
final ReservoirItemsSketch sk = ReservoirItemsSketch.newInstance(k);
- Files.newOutputStream(javaPath.resolve("reservoir_items_double_empty_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_double_empty_k" + k + "_java.sk", sk.toByteArray(new ArrayOfDoublesSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -201,8 +190,7 @@ public void generateReservoirItemsSketchDoubleExact() throws IOException {
for (int i = 0; i < n; i++) {
sk.update((double) i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_double_exact_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_double_exact_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfDoublesSerDe()));
}
}
@@ -224,8 +212,7 @@ public void generateReservoirItemsSketchDoubleSampling() throws IOException {
k
);
- Files.newOutputStream(javaPath.resolve("reservoir_items_double_sampling_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_double_sampling_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfDoublesSerDe()));
}
}
@@ -234,8 +221,7 @@ public void generateReservoirItemsSketchStringEmpty() throws IOException {
final int k = 128;
final ReservoirItemsSketch sk = ReservoirItemsSketch.newInstance(k);
- Files.newOutputStream(javaPath.resolve("reservoir_items_string_empty_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_string_empty_k" + k + "_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -248,8 +234,7 @@ public void generateReservoirItemsSketchStringExact() throws IOException {
for (int i = 0; i < n; i++) {
sk.update("item" + i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_string_exact_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_string_exact_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
}
@@ -271,8 +256,7 @@ public void generateReservoirItemsSketchStringSampling() throws IOException {
k
);
- Files.newOutputStream(javaPath.resolve("reservoir_items_string_sampling_n" + n + "_k" + k + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_string_sampling_n" + n + "_k" + k + "_java.sk", sk.toByteArray(new ArrayOfStringsSerDe()));
}
}
@@ -281,8 +265,7 @@ public void generateReservoirItemsUnionLongEmpty() throws IOException {
int maxK = 128;
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_long_empty_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_long_empty_maxk" + maxK + "_java.sk", union.toByteArray(new ArrayOfLongsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -295,8 +278,8 @@ public void generateReservoirItemsUnionLongExact() throws IOException {
for (int i = 0; i < n; i++) {
union.update((long) i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_long_exact_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_long_exact_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfLongsSerDe()));
}
}
@@ -321,8 +304,8 @@ public void generateReservoirItemsUnionLongSampling() throws IOException {
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
union.update(sk);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_long_sampling_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_long_sampling_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfLongsSerDe()));
}
}
@@ -331,8 +314,7 @@ public void generateReservoirItemsUnionDoubleEmpty() throws IOException {
int maxK = 128;
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_double_empty_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_union_double_empty_maxk" + maxK + "_java.sk", union.toByteArray(new ArrayOfDoublesSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -345,8 +327,8 @@ public void generateReservoirItemsUnionDoubleExact() throws IOException {
for (int i = 0; i < n; i++) {
union.update((double) i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_double_exact_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_union_double_exact_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfDoublesSerDe()));
}
}
@@ -371,8 +353,8 @@ public void generateReservoirItemsUnionDoubleSampling() throws IOException {
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
union.update(sk);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_double_sampling_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("reservoir_items_union_double_sampling_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfDoublesSerDe()));
}
}
@@ -381,8 +363,7 @@ public void generateReservoirItemsUnionStringEmpty() throws IOException {
int maxK = 128;
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_string_empty_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_string_empty_maxk" + maxK + "_java.sk", union.toByteArray(new ArrayOfStringsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -395,8 +376,8 @@ public void generateReservoirItemsUnionStringExact() throws IOException {
for (int i = 0; i < n; i++) {
union.update("item" + i);
}
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_string_exact_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_string_exact_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfStringsSerDe()));
}
}
@@ -421,8 +402,8 @@ public void generateReservoirItemsUnionStringSampling() throws IOException {
ReservoirItemsUnion union = ReservoirItemsUnion.newInstance(maxK);
union.update(sk);
- Files.newOutputStream(javaPath.resolve("reservoir_items_union_string_sampling_n" + n + "_maxk" + maxK + "_java.sk"))
- .write(union.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("reservoir_items_union_string_sampling_n" + n + "_maxk" + maxK + "_java.sk",
+ union.toByteArray(new ArrayOfStringsSerDe()));
}
}
}
diff --git a/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
index dd759b05d..c8db54da8 100644
--- a/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/sampling/VarOptCrossLanguageTest.java
@@ -22,20 +22,17 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.lang.foreign.MemorySegment;
-import java.nio.file.Files;
import org.apache.datasketches.common.ArrayOfDoublesSerDe;
import org.apache.datasketches.common.ArrayOfLongsSerDe;
import org.apache.datasketches.common.ArrayOfStringsSerDe;
-import org.apache.datasketches.sampling.SampleSubsetSummary;
-import org.apache.datasketches.sampling.VarOptItemsSketch;
-import org.apache.datasketches.sampling.VarOptItemsUnion;
import org.testng.annotations.Test;
/**
@@ -53,8 +50,7 @@ public void generateSketchesLong() throws IOException {
for (int i = 1; i <= n; i++) {
sk.update(Long.valueOf(i), 1.0);
}
- Files.newOutputStream(javaPath.resolve("varopt_sketch_long_n" + n + "_java.sk"))
- .write(sk.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("varopt_sketch_long_n" + n + "_java.sk", sk.toByteArray(new ArrayOfLongsSerDe()));
}
}
@@ -64,8 +60,7 @@ public void generateSketchStringExact() throws IOException {
for (int i = 1; i <= 200; ++i) {
sketch.update(Integer.toString(i), 1000.0 / i);
}
- Files.newOutputStream(javaPath.resolve("varopt_sketch_string_exact_java.sk"))
- .write(sketch.toByteArray(new ArrayOfStringsSerDe()));
+ putBytesToJavaPath("varopt_sketch_string_exact_java.sk", sketch.toByteArray(new ArrayOfStringsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -78,8 +73,7 @@ public void generateSketchLongSampling() throws IOException {
sketch.update(-1L, 100000.0);
sketch.update(-2L, 110000.0);
sketch.update(-3L, 120000.0);
- Files.newOutputStream(javaPath.resolve("varopt_sketch_long_sampling_java.sk"))
- .write(sketch.toByteArray(new ArrayOfLongsSerDe()));
+ putBytesToJavaPath("varopt_sketch_long_sampling_java.sk", sketch.toByteArray(new ArrayOfLongsSerDe()));
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -106,15 +100,14 @@ public void generateUnionDoubleSampling() throws IOException {
sketch.update(1.0 * i, 1.0);
}
union.update(sketch);
- Files.newOutputStream(javaPath.resolve("varopt_union_double_sampling_java.sk"))
- .write(union.toByteArray(new ArrayOfDoublesSerDe()));
+ putBytesToJavaPath("varopt_union_double_sampling_java.sk", union.toByteArray(new ArrayOfDoublesSerDe()));
}
@Test(groups = {CHECK_CPP_FILES})
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 +117,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 +132,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 +149,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..99d88b429 100644
--- a/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tdigest/TDigestCrossLanguageTest.java
@@ -22,12 +22,14 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
+
import java.io.IOException;
import java.lang.foreign.MemorySegment;
-import java.nio.file.Files;
+
import org.testng.annotations.Test;
public class TDigestCrossLanguageTest {
@@ -40,9 +42,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 +72,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());
@@ -100,7 +102,7 @@ public void generateForCppDouble() throws IOException {
for (int i = 1; i <= n; i++) {
td.update(i);
}
- Files.newOutputStream(javaPath.resolve("tdigest_double_n" + n + "_java.sk")).write(td.toByteArray());
+ putBytesToJavaPath("tdigest_double_n" + n + "_java.sk", td.toByteArray());
}
}
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..c9cf0361b 100644
--- a/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/theta/ThetaSketchCrossLanguageTest.java
@@ -22,18 +22,15 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.io.IOException;
import java.lang.foreign.MemorySegment;
-import java.nio.file.Files;
-import org.apache.datasketches.theta.CompactThetaSketch;
-import org.apache.datasketches.theta.HashIterator;
-import org.apache.datasketches.theta.UpdatableThetaSketch;
import org.testng.annotations.Test;
/**
@@ -50,7 +47,7 @@ public void generateBinariesForCompatibilityTesting() throws IOException {
for (int i = 0; i < n; i++) {
sk.update(i);
}
- Files.newOutputStream(javaPath.resolve("theta_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("theta_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -62,7 +59,7 @@ public void generateBinariesForCompatibilityTestingCompressed() throws IOExcepti
for (int i = 0; i < n; i++) {
sk.update(i);
}
- Files.newOutputStream(javaPath.resolve("theta_compressed_n" + n + "_java.sk")).write(sk.compact().toByteArrayCompressed());
+ putBytesToJavaPath("theta_compressed_n" + n + "_java.sk", sk.compact().toByteArrayCompressed());
}
}
@@ -72,14 +69,14 @@ public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IO
sk.update(1);
assertFalse(sk.isEmpty());
assertEquals(sk.getRetainedEntries(), 0);
- Files.newOutputStream(javaPath.resolve("theta_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("theta_non_empty_no_entries_java.sk", sk.compact().toByteArray());
}
@Test(groups = {CHECK_CPP_FILES})
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 +95,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 +114,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 +133,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 +150,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 +158,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..6c182baa2 100644
--- a/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tuple/TupleCrossLanguageTest.java
@@ -23,20 +23,17 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
+import static org.apache.datasketches.common.TestUtil.resPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.TestUtil;
-import org.apache.datasketches.tuple.TupleSketch;
-import org.apache.datasketches.tuple.TupleSketchIterator;
-import org.apache.datasketches.tuple.UpdatableTupleSketch;
-import org.apache.datasketches.tuple.UpdatableTupleSketchBuilder;
import org.apache.datasketches.tuple.adouble.DoubleSummary;
import org.apache.datasketches.tuple.adouble.DoubleSummaryDeserializer;
import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUnion;
@@ -47,7 +44,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 +60,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 +85,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());
@@ -111,19 +108,19 @@ public void generateForCppIntegerSummary() throws IOException {
for (int i = 0; i < n; i++) {
sk.update(i, i);
}
- Files.newOutputStream(javaPath.resolve("tuple_int_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("tuple_int_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@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..121b8f52d 100644
--- a/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tuple/arrayofdoubles/AodSketchCrossLanguageTest.java
@@ -22,19 +22,15 @@
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.cppPath;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.getFileBytes;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
-import java.lang.foreign.MemorySegment;
import java.io.IOException;
-import java.nio.file.Files;
+import java.lang.foreign.MemorySegment;
-import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketch;
-import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesSketchIterator;
-import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketch;
-import org.apache.datasketches.tuple.arrayofdoubles.ArrayOfDoublesUpdatableSketchBuilder;
import org.testng.annotations.Test;
/**
@@ -51,7 +47,7 @@ public void generateBinariesForCompatibilityTestingOneValue() throws IOException
for (int i = 0; i < n; i++) {
sk.update(i, new double[] {i});
}
- Files.newOutputStream(javaPath.resolve("aod_1_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aod_1_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -63,7 +59,7 @@ public void generateBinariesForCompatibilityTestingThreeValues() throws IOExcept
for (int i = 0; i < n; i++) {
sk.update(i, new double[] {i, i, i});
}
- Files.newOutputStream(javaPath.resolve("aod_3_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aod_3_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -74,14 +70,14 @@ public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IO
sk.update(1, new double[] {1});
assertFalse(sk.isEmpty());
assertEquals(sk.getRetainedEntries(), 0);
- Files.newOutputStream(javaPath.resolve("aod_1_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aod_1_non_empty_no_entries_java.sk", sk.compact().toByteArray());
}
@Test(groups = {CHECK_CPP_FILES})
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 +93,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 +109,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/java/org/apache/datasketches/tuple/strings/AosSketchCrossLanguageTest.java b/src/test/java/org/apache/datasketches/tuple/strings/AosSketchCrossLanguageTest.java
index dd425abfa..973f4bf80 100644
--- a/src/test/java/org/apache/datasketches/tuple/strings/AosSketchCrossLanguageTest.java
+++ b/src/test/java/org/apache/datasketches/tuple/strings/AosSketchCrossLanguageTest.java
@@ -20,12 +20,11 @@
package org.apache.datasketches.tuple.strings;
import static org.apache.datasketches.common.TestUtil.GENERATE_JAVA_FILES;
-import static org.apache.datasketches.common.TestUtil.javaPath;
+import static org.apache.datasketches.common.TestUtil.putBytesToJavaPath;
import static org.testng.Assert.assertEquals;
import static org.testng.Assert.assertFalse;
import java.io.IOException;
-import java.nio.file.Files;
import org.apache.datasketches.common.ResizeFactor;
import org.testng.annotations.Test;
@@ -44,7 +43,7 @@ public void generateBinariesForCompatibilityTestingOneString() throws IOExceptio
for (int i = 0; i < n; i++) {
sk.update(new String[] {String.valueOf(i)}, new String[] {"value" + i});
}
- Files.newOutputStream(javaPath.resolve("aos_1_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_1_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -56,7 +55,7 @@ public void generateBinariesForCompatibilityTestingThreeStrings() throws IOExcep
for (int i = 0; i < n; i++) {
sk.update(new String[] {String.valueOf(i)}, new String[] {"a" + i, "b" + i, "c" + i});
}
- Files.newOutputStream(javaPath.resolve("aos_3_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_3_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -67,7 +66,7 @@ public void generateBinariesForCompatibilityTestingNonEmptyNoEntries() throws IO
sk.update(new String[] {"key1"}, new String[] {"value1"});
assertFalse(sk.isEmpty());
assertEquals(sk.getRetainedEntries(), 0);
- Files.newOutputStream(javaPath.resolve("aos_1_non_empty_no_entries_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_1_non_empty_no_entries_java.sk", sk.compact().toByteArray());
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -78,7 +77,7 @@ public void generateBinariesForCompatibilityTestingMultiKeyStrings() throws IOEx
for (int i = 0; i < n; i++) {
sk.update(new String[] {"key" + i, "subkey" + (i % 10)}, new String[] {"value" + i});
}
- Files.newOutputStream(javaPath.resolve("aos_multikey_n" + n + "_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_multikey_n" + n + "_java.sk", sk.compact().toByteArray());
}
}
@@ -93,7 +92,7 @@ public void generateBinariesForCompatibilityTestingUnicodeStrings() throws IOExc
assertFalse(sk.isEmpty());
assertEquals(sk.getRetainedEntries(), 3);
- Files.newOutputStream(javaPath.resolve("aos_unicode_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_unicode_java.sk", sk.compact().toByteArray());
}
@Test(groups = {GENERATE_JAVA_FILES})
@@ -107,6 +106,6 @@ public void generateBinariesForCompatibilityTestingEmptyStrings() throws IOExcep
assertFalse(sk.isEmpty());
assertEquals(sk.getRetainedEntries(), 3);
- Files.newOutputStream(javaPath.resolve("aos_empty_strings_java.sk")).write(sk.compact().toByteArray());
+ putBytesToJavaPath("aos_empty_strings_java.sk", sk.compact().toByteArray());
}
}
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.
diff --git a/src/test/resources/testng.xml b/src/test/resources/testng.xml
new file mode 100644
index 000000000..a78e300f5
--- /dev/null
+++ b/src/test/resources/testng.xml
@@ -0,0 +1,28 @@
+
+
+
+
+
+
+
+
+
+
+
diff --git a/tools/SketchesCheckstyle.xml b/tools/SketchesCheckstyle.xml
index 53726a2c1..f51987dc5 100644
--- a/tools/SketchesCheckstyle.xml
+++ b/tools/SketchesCheckstyle.xml
@@ -1,7 +1,4 @@
-
@@ -53,14 +50,14 @@ under the License.
-
+
-
+
-
+
@@ -68,16 +65,16 @@ under the License.
-
+
-
+
-
+
@@ -88,7 +85,7 @@ under the License.
-
+
@@ -101,44 +98,44 @@ under the License.
-
+
-
+
-
+
-
-
+
+
-
+
-
+
-
+
@@ -146,51 +143,51 @@ under the License.
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
@@ -198,11 +195,11 @@ under the License.
-
+
-
+
-
+
@@ -211,21 +208,21 @@ under the License.
-
+
-
+
-
+
@@ -233,19 +230,19 @@ under the License.
-
+
-
+
-
+
-
+
@@ -259,12 +256,12 @@ under the License.
-
+
-
+
@@ -275,27 +272,27 @@ under the License.
-
+
-
+
-
+
-
+
-
+
@@ -369,13 +366,13 @@ under the License.
-
+
-
+
@@ -386,26 +383,26 @@ under the License.
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/tools/testng.xml b/tools/testng.xml
deleted file mode 100644
index 6571f092c..000000000
--- a/tools/testng.xml
+++ /dev/null
@@ -1,51 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file