|
19 | 19 | import org.junit.jupiter.api.Test;
|
20 | 20 | import org.junit.jupiter.params.ParameterizedTest;
|
21 | 21 | import org.junit.jupiter.params.provider.CsvSource;
|
| 22 | +import org.junit.jupiter.params.provider.MethodSource; |
22 | 23 | import org.junit.jupiter.params.provider.ValueSource;
|
23 | 24 | import ucar.ma2.MAMath;
|
24 | 25 |
|
@@ -230,6 +231,60 @@ public void testWriteReadWithZarrita(String codec, String codecParam) throws Exc
|
230 | 231 | assert exitCode == 0;
|
231 | 232 | }
|
232 | 233 |
|
| 234 | + static Stream<int[]> invalidchunkSizes() { |
| 235 | + return Stream.of( |
| 236 | + new int[] {1} , |
| 237 | + new int[] {1, 1, 1}, |
| 238 | + new int[] {5, 1}, |
| 239 | + new int[] {1, 5} |
| 240 | + ); |
| 241 | + } |
| 242 | + |
| 243 | + @ParameterizedTest |
| 244 | + @MethodSource("invalidchunkSizes") |
| 245 | + public void testCheckInvalidChunkBounds(int[] chunkSize) throws Exception { |
| 246 | + long[] shape = new long[] {4, 4}; |
| 247 | + |
| 248 | + StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("invalid_chunksize"); |
| 249 | + ArrayMetadataBuilder builder = Array.metadataBuilder() |
| 250 | + .withShape(shape) |
| 251 | + .withDataType(DataType.UINT32) |
| 252 | + .withChunkShape(chunkSize); |
| 253 | + |
| 254 | + assertThrows(ZarrException.class, builder::build); |
| 255 | + } |
| 256 | + |
| 257 | + @ParameterizedTest |
| 258 | + @ValueSource(strings = {"large", "small", "nested", "wrong dims", "correct"}) |
| 259 | + public void testCheckShardingBounds(String scenario) throws Exception { |
| 260 | + long[] shape = new long[] {4, 4}; |
| 261 | + int[] shardSize = new int[] {2, 2}; |
| 262 | + int[] chunkSize = new int[] {2, 2}; |
| 263 | + |
| 264 | + if (scenario.equals("large")) |
| 265 | + shardSize = new int[] {8, 8}; |
| 266 | + if (scenario.equals("small")) |
| 267 | + shardSize = new int[] {1, 1}; |
| 268 | + if (scenario.equals("wrong dims")) |
| 269 | + shardSize = new int[] {1}; |
| 270 | + StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("illegal_shardsize"); |
| 271 | + ArrayMetadataBuilder builder = Array.metadataBuilder() |
| 272 | + .withShape(shape) |
| 273 | + .withDataType(DataType.UINT32).withChunkShape(shardSize); |
| 274 | + |
| 275 | + if (scenario.equals("nested")) { |
| 276 | + int[] nestedChunkSize = new int[]{4, 4}; |
| 277 | + builder = builder.withCodecs(c -> c.withSharding(chunkSize, c1 -> c1.withSharding(nestedChunkSize, c2 -> c2.withBytes("LITTLE")))); |
| 278 | + } else { |
| 279 | + builder = builder.withCodecs(c -> c.withSharding(chunkSize, c1 -> c1.withBytes("LITTLE"))); |
| 280 | + } |
| 281 | + if (scenario.equals("correct")){ |
| 282 | + builder.build(); |
| 283 | + }else{ |
| 284 | + assertThrows(ZarrException.class, builder::build); |
| 285 | + } |
| 286 | + } |
| 287 | + |
233 | 288 | @ParameterizedTest
|
234 | 289 | @CsvSource({"0,true", "0,false", "5, true", "5, false"})
|
235 | 290 | public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrException, IOException {
|
|
0 commit comments