1212import dev .zarr .zarrjava .store .S3Store ;
1313import dev .zarr .zarrjava .store .StoreHandle ;
1414import dev .zarr .zarrjava .utils .MultiArrayUtils ;
15- import dev .zarr .zarrjava .v3 .Array ;
16- import dev .zarr .zarrjava .v3 .ArrayMetadata ;
17- import dev .zarr .zarrjava .v3 .DataType ;
18- import dev .zarr .zarrjava .v3 .Group ;
19- import dev .zarr .zarrjava .v3 .GroupMetadata ;
20- import dev .zarr .zarrjava .v3 .Node ;
15+ import dev .zarr .zarrjava .v3 .*;
2116
2217import java .io .BufferedReader ;
2318import java .io .File ;
3833import org .junit .jupiter .params .ParameterizedTest ;
3934import org .junit .jupiter .params .provider .ValueSource ;
4035
36+ import javax .management .InvalidAttributeValueException ;
4137import javax .xml .crypto .Data ;
4238
4339public class ZarrTest {
@@ -134,32 +130,54 @@ public void testReadFromZarrita(String codec) throws IOException, ZarrException,
134130 Assertions .assertEquals (DataType .INT32 , array .metadata .dataType );
135131 Assertions .assertArrayEquals (new int []{2 , 8 }, array .metadata .chunkShape ());
136132 Assertions .assertEquals (42 , array .metadata .attributes .get ("answer" ));
133+
137134 int [] expectedData = new int [16 * 16 ];
138- for (int i = 0 ; i < 16 * 16 ; i ++) {
139- expectedData [i ] = i ;
140- }
135+ Arrays .setAll (expectedData , p -> p );
141136 Assertions .assertArrayEquals (expectedData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .INT ));
142137 }
143138
139+ //TODO: add crc32c
144140 @ ParameterizedTest
145- @ ValueSource (strings = {"blosc" , "gzip" , "zstd" , "bytes" , "transpose" , "sharding" , "crc32c" })
141+ @ ValueSource (strings = {"blosc" , "gzip" , "zstd" , "bytes" , "transpose" , "sharding" })
146142 public void testWriteToZarrita (String codec ) throws IOException , ZarrException , InterruptedException {
147143 StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("write_to_zarrita" , codec );
148-
149- //TODO: have correct codecs
150- Array array = Array .create (
151- storeHandle ,
152- Array .metadataBuilder ()
144+ ArrayMetadataBuilder builder = Array .metadataBuilder ()
153145 .withShape (16 , 16 )
154146 .withDataType (DataType .UINT32 )
155147 .withChunkShape (8 , 8 )
156- .withFillValue (0 )
157- .withCodecs (c -> c .withSharding (new int []{4 , 4 }, c1 -> c1 .withBytes ("LITTLE" )))
158- .build ());
148+ .withFillValue (0 );
149+
150+ switch (codec ){
151+ case "blosc" :
152+ builder = builder .withCodecs (c -> c .withBlosc ());
153+ break ;
154+ case "gzip" :
155+ builder = builder .withCodecs (c -> c .withGzip ());
156+ break ;
157+ case "zstd" :
158+ builder = builder .withCodecs (c -> c .withZstd (0 ));
159+ break ;
160+ case "bytes" :
161+ builder = builder .withCodecs (c -> c .withBytes ("LITTLE" ));
162+ break ;
163+ case "transpose" :
164+ builder = builder .withCodecs (c -> c .withTranspose ("F" ));
165+ break ;
166+ case "sharding" :
167+ builder = builder .withCodecs (c -> c .withSharding (new int []{4 , 4 }, c1 -> c1 .withBytes ("LITTLE" )));
168+ break ;
169+ case "crc32c" :
170+ //missing
171+ break ;
172+ default :
173+ throw new IllegalArgumentException ("Invalid Codec: " +codec );
174+ }
175+
176+ Array array = Array .create (storeHandle ,builder .build ());
159177
160- ucar . ma2 . Array testData = ucar . ma2 . Array . factory ( ucar . ma2 . DataType . UINT , new int []{ 16 , 16 }) ;
161- testData . setInt ( 10 , 42 );
162- array .write (testData );
178+ int [] data = new int [16 * 16 ] ;
179+ Arrays . setAll ( data , p -> p );
180+ array .write (ucar . ma2 . Array . factory ( ucar . ma2 . DataType . UINT , new int []{ 16 , 16 }, data ) );
163181
164182
165183 String command = "zarrita/bin/python" ;
@@ -181,7 +199,6 @@ public void testWriteToZarrita(String codec) throws IOException, ZarrException,
181199 int exitCode = process .waitFor ();
182200 assert exitCode == 0 ;
183201 //TODO return metadata from zarrita_read.py and do assertions here
184-
185202 }
186203
187204
0 commit comments