@@ -255,18 +255,38 @@ public void testCheckInvalidCodecConfiguration(Function<CodecBuilder, CodecBuild
255
255
assertThrows (ZarrException .class , () -> Array .create (storeHandle , builder .build ()));
256
256
}
257
257
258
+ @ Test
259
+ public void testLargerChunkSizeThanArraySize () throws ZarrException , IOException {
260
+ int [] testData = new int [16 * 16 * 16 ];
261
+ Arrays .setAll (testData , p -> p );
262
+
263
+ StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("larger_chunk_size_than_array" );
264
+ ArrayMetadata metadata = Array .metadataBuilder ()
265
+ .withShape (16 , 16 , 16 )
266
+ .withDataType (DataType .UINT32 )
267
+ .withChunkShape (32 , 32 , 32 )
268
+ .withFillValue (0 )
269
+ .build ();
270
+ Array writeArray = Array .create (storeHandle , metadata );
271
+ writeArray .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{16 , 16 , 16 }, testData ));
272
+
273
+ //read in zarr-java
274
+ Array readArray = Array .open (storeHandle );
275
+ ucar .ma2 .Array result = readArray .read ();
276
+
277
+ Assertions .assertArrayEquals (testData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .INT ));
278
+ }
279
+
258
280
static Stream <int []> invalidChunkSizes () {
259
281
return Stream .of (
260
282
new int []{1 },
261
- new int []{1 , 1 , 1 },
262
- new int [] {5 , 1 },
263
- new int [] {1 , 5 }
283
+ new int []{1 , 1 , 1 }
264
284
);
265
285
}
266
286
267
287
@ ParameterizedTest
268
288
@ MethodSource ("invalidChunkSizes" )
269
- public void testCheckInvalidChunkBounds (int [] chunkSize ) throws Exception {
289
+ public void testCheckInvalidChunkDimensions (int [] chunkSize ) {
270
290
long [] shape = new long [] {4 , 4 };
271
291
272
292
StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("invalid_chunksize" );
@@ -278,35 +298,33 @@ public void testCheckInvalidChunkBounds(int[] chunkSize) throws Exception {
278
298
assertThrows (ZarrException .class , builder ::build );
279
299
}
280
300
301
+ static Stream <int []> invalidShardSizes () {
302
+ return Stream .of (
303
+ new int []{4 }, //wrong dims
304
+ new int []{4 , 4 , 4 }, //wrong dims
305
+ new int []{1 , 1 }, //smaller than inner chunk shape
306
+ new int []{5 , 5 }, //no exact multiple of inner chunk shape
307
+ new int []{2 , 1 }, //smaller than inner chunk shape in 2nd dimension
308
+ new int []{2 , 5 } //no exact multiple of inner chunk shape in 2nd dimension
309
+ );
310
+ }
311
+
281
312
@ ParameterizedTest
282
- @ ValueSource (strings = {"large" , "small" , "nested" , "wrong dims" , "correct" })
283
- public void testCheckShardingBounds (String scenario ) throws Exception {
284
- long [] shape = new long [] {4 , 4 };
285
- int [] shardSize = new int [] {2 , 2 };
286
- int [] chunkSize = new int [] {2 , 2 };
287
-
288
- if (scenario .equals ("large" ))
289
- shardSize = new int [] {8 , 8 };
290
- if (scenario .equals ("small" ))
291
- shardSize = new int [] {1 , 1 };
292
- if (scenario .equals ("wrong dims" ))
293
- shardSize = new int [] {1 };
294
- StoreHandle storeHandle = new FilesystemStore (TESTOUTPUT ).resolve ("illegal_shardsize" );
313
+ @ MethodSource ("invalidShardSizes" )
314
+ public void testCheckShardingBounds (int [] shardSize ) throws Exception {
315
+ long [] shape = new long [] {10 , 10 };
316
+ int [] innerChunkSize = new int [] {2 , 2 };
317
+
295
318
ArrayMetadataBuilder builder = Array .metadataBuilder ()
296
319
.withShape (shape )
297
320
.withDataType (DataType .UINT32 ).withChunkShape (shardSize );
298
321
299
- if (scenario . equals ( "nested" ) ) {
322
+ if (false ) {
300
323
int [] nestedChunkSize = new int []{4 , 4 };
301
- builder = builder .withCodecs (c -> c .withSharding (chunkSize , c1 -> c1 .withSharding (nestedChunkSize , c2 -> c2 .withBytes ("LITTLE" ))));
302
- } else {
303
- builder = builder .withCodecs (c -> c .withSharding (chunkSize , c1 -> c1 .withBytes ("LITTLE" )));
304
- }
305
- if (scenario .equals ("correct" )){
306
- builder .build ();
307
- }else {
308
- assertThrows (ZarrException .class , builder ::build );
324
+ builder = builder .withCodecs (c -> c .withSharding (new int []{2 , 2 }, c1 -> c1 .withSharding (nestedChunkSize , c2 -> c2 .withBytes ("LITTLE" ))));
309
325
}
326
+ builder = builder .withCodecs (c -> c .withSharding (innerChunkSize , c1 -> c1 .withBytes ("LITTLE" )));
327
+ assertThrows (ZarrException .class , builder ::build );
310
328
}
311
329
312
330
@ ParameterizedTest
0 commit comments