55import com .amazonaws .services .s3 .AmazonS3ClientBuilder ;
66import com .fasterxml .jackson .databind .ObjectMapper ;
77import com .github .luben .zstd .ZstdCompressCtx ;
8- import com .github .luben .zstd .ZstdInputStream ;
98import com .github .luben .zstd .ZstdOutputStream ;
109import dev .zarr .zarrjava .store .FilesystemStore ;
1110import dev .zarr .zarrjava .store .HttpStore ;
2726import java .io .FileOutputStream ;
2827import java .nio .ByteBuffer ;
2928import java .io .*;
30- import java .nio .ByteBuffer ;
3129import java .nio .file .Files ;
3230import java .nio .file .Path ;
3331import java .nio .file .Paths ;
@@ -42,11 +40,7 @@ public class ZarrTest {
4240
4341 final static Path TESTDATA = Paths .get ("testdata" );
4442 final static Path TESTOUTPUT = Paths .get ("testoutput" );
45- final static Path TEST_PATH = Paths .get ("src/test/java/dev/zarr/zarrjava/" );
46-
47- final static Path ZARRITA_WRITE_PATH = TEST_PATH .resolve ("zarrita_write.py" );
48- final static Path ZARRITA_READ_PATH = TEST_PATH .resolve ("zarrita_read.py" );
49- final static Path TEST_ZSTD_LIBRARY_PATH = TEST_PATH .resolve ("test_zstd_library.py" );
43+ final static Path PYTHON_TEST_PATH = Paths .get ("src/test/python-scripts/" );
5044
5145 public static String pythonPath () {
5246 if (System .getProperty ("os.name" ).startsWith ("Windows" )) {
@@ -70,7 +64,7 @@ public static void clearTestoutputFolder() throws IOException {
7064 public void testReadFromZarrita (String codec ) throws IOException , ZarrException , InterruptedException {
7165
7266 String command = pythonPath ();
73- ProcessBuilder pb = new ProcessBuilder (command , ZARRITA_WRITE_PATH .toString (), codec , TESTOUTPUT .toString ());
67+ ProcessBuilder pb = new ProcessBuilder (command , PYTHON_TEST_PATH . resolve ( "zarrita_write.py" ) .toString (), codec , TESTOUTPUT .toString ());
7468 Process process = pb .start ();
7569
7670 BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
@@ -109,9 +103,9 @@ private void copy(InputStream inputStream, OutputStream outputStream) throws IOE
109103 }
110104 }
111105
112- @ CsvSource ({"0,true" , "0,false" , "5, true" , "5 , false" })
106+ @ CsvSource ({"0,true" , "0,false" , "5, true" , "10 , false" })
113107 @ ParameterizedTest
114- public void testZstdLibrary2 (int clevel , boolean checksumFlag ) throws IOException , InterruptedException , ZarrException {
108+ public void testZstdLibrary (int clevel , boolean checksumFlag ) throws IOException , InterruptedException , ZarrException {
115109 //compress using ZstdCompressCtx
116110 int number = 123456 ;
117111 byte [] src = ByteBuffer .allocate (4 ).putInt (number ).array ();
@@ -135,49 +129,14 @@ public void testZstdLibrary2(int clevel, boolean checksumFlag) throws IOExceptio
135129 //decompress in python
136130 Process process = new ProcessBuilder (
137131 pythonPath (),
138- TEST_PATH .resolve ("decompress_print .py" ).toString (),
132+ PYTHON_TEST_PATH .resolve ("zstd_decompress .py" ).toString (),
139133 compressedDataPath ,
140134 Integer .toString (number )
141135 ).start ();
142136 int exitCode = process .waitFor ();
143137 assert exitCode == 0 ;
144138 }
145139
146-
147- @ ParameterizedTest
148- @ CsvSource ({"0,true" , "0,false" , "5, true" , "5, false" })
149- public void testZstdLibrary (int clevel , boolean checksum ) throws IOException , InterruptedException {
150- String zstd_file = TESTOUTPUT + "/testZstdLibrary" + clevel + checksum + ".zstd" ;
151-
152- ByteBuffer testBytes = ByteBuffer .allocate (1024 );
153- testBytes .putInt (42 );
154-
155- ByteArrayOutputStream outputStream = new ByteArrayOutputStream ();
156- ZstdOutputStream zstdStream = new ZstdOutputStream (outputStream , clevel );
157- zstdStream .setChecksum (checksum );
158- zstdStream .write (Utils .toArray (testBytes ));
159- zstdStream .close ();
160- ByteBuffer encodedBytes = ByteBuffer .wrap (outputStream .toByteArray ());
161- try (FileOutputStream fileOutputStream = new FileOutputStream (zstd_file )) {
162- fileOutputStream .write (encodedBytes .array ());
163- }
164- String command = pythonPath ();
165- ProcessBuilder pb = new ProcessBuilder (command , TEST_ZSTD_LIBRARY_PATH .toString (), zstd_file );
166- Process process = pb .start ();
167-
168- BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
169- String line ;
170- while ((line = reader .readLine ()) != null ) {
171- System .out .println (line );
172- }
173- BufferedReader readerErr = new BufferedReader (new InputStreamReader (process .getErrorStream ()));
174- while ((line = readerErr .readLine ()) != null ) {
175- System .err .println (line );
176- }
177- int exitCode = process .waitFor ();
178- assert exitCode == 0 ;
179- }
180-
181140 //TODO: add crc32c
182141 @ ParameterizedTest
183142 @ ValueSource (strings = {"blosc" , "gzip" , "zstd" , "bytes" , "transpose" , "sharding_start" , "sharding_end" })
@@ -226,7 +185,7 @@ public void testWriteToZarrita(String codec) throws IOException, ZarrException,
226185
227186 String command = pythonPath ();
228187
229- ProcessBuilder pb = new ProcessBuilder (command , ZARRITA_READ_PATH .toString (), codec , TESTOUTPUT .toString ());
188+ ProcessBuilder pb = new ProcessBuilder (command , PYTHON_TEST_PATH . resolve ( "zarrita_read.py" ) .toString (), codec , TESTOUTPUT .toString ());
230189 Process process = pb .start ();
231190
232191 BufferedReader reader = new BufferedReader (new InputStreamReader (process .getInputStream ()));
0 commit comments