Skip to content

Commit e3e2208

Browse files
authored
Merge pull request #7 from scalableminds/check-sharding-bounds
2 parents b53e163 + 2b11db6 commit e3e2208

File tree

1 file changed

+60
-21
lines changed

1 file changed

+60
-21
lines changed

src/test/java/dev/zarr/zarrjava/ZarrTest.java

+60-21
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import dev.zarr.zarrjava.utils.MultiArrayUtils;
1414
import dev.zarr.zarrjava.v3.*;
1515
import dev.zarr.zarrjava.v3.codec.CodecBuilder;
16+
import dev.zarr.zarrjava.v3.codec.core.BytesCodec;
1617
import dev.zarr.zarrjava.v3.codec.core.TransposeCodec;
1718
import org.junit.jupiter.api.Assertions;
1819
import org.junit.jupiter.api.BeforeAll;
@@ -32,6 +33,7 @@
3233
import java.util.Comparator;
3334
import java.util.HashMap;
3435
import java.util.Map;
36+
import java.util.function.Function;
3537
import java.util.stream.Stream;
3638

3739
import static org.junit.Assert.assertThrows;
@@ -231,17 +233,39 @@ public void testWriteReadWithZarrita(String codec, String codecParam) throws Exc
231233
assert exitCode == 0;
232234
}
233235

234-
static Stream<int[]> invalidchunkSizes() {
236+
static Stream<Function<CodecBuilder, CodecBuilder>> invalidCodecBuilder(){
235237
return Stream.of(
236-
new int[] {1} ,
237-
new int[] {1, 1, 1},
238+
c -> c.withBytes(BytesCodec.Endian.LITTLE).withBytes(BytesCodec.Endian.LITTLE),
239+
c -> c.withBlosc().withBytes(BytesCodec.Endian.LITTLE),
240+
c -> c.withBytes(BytesCodec.Endian.LITTLE).withTranspose(new int[]{1,0}),
241+
c -> c.withTranspose(new int[]{1,0}).withBytes(BytesCodec.Endian.LITTLE).withTranspose(new int[]{1,0})
242+
);
243+
}
244+
245+
@ParameterizedTest
246+
@MethodSource("invalidCodecBuilder")
247+
public void testCheckInvalidCodecConfiguration(Function<CodecBuilder, CodecBuilder> codecBuilder) throws Exception {
248+
StoreHandle storeHandle = new FilesystemStore(TESTOUTPUT).resolve("invalid_codec_config", String.valueOf(codecBuilder.hashCode()));
249+
ArrayMetadataBuilder builder = Array.metadataBuilder()
250+
.withShape(new long[] {4, 4})
251+
.withDataType(DataType.UINT32)
252+
.withChunkShape(new int[]{2,2})
253+
.withCodecs(codecBuilder);
254+
255+
assertThrows(ZarrException.class, () -> Array.create(storeHandle, builder.build()));
256+
}
257+
258+
static Stream<int[]> invalidChunkSizes() {
259+
return Stream.of(
260+
new int[]{1},
261+
new int[]{1, 1, 1},
238262
new int[] {5, 1},
239263
new int[] {1, 5}
240264
);
241265
}
242266

243267
@ParameterizedTest
244-
@MethodSource("invalidchunkSizes")
268+
@MethodSource("invalidChunkSizes")
245269
public void testCheckInvalidChunkBounds(int[] chunkSize) throws Exception {
246270
long[] shape = new long[] {4, 4};
247271

@@ -310,31 +334,46 @@ public void testZstdCodecReadWrite(int clevel, boolean checksum) throws ZarrExce
310334
@Test
311335
public void testTransposeCodec() throws ZarrException {
312336
ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{2, 3, 3}, new int[]{
313-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17});
337+
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17});
314338
ucar.ma2.Array testDataTransposed120 = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{3, 3, 2}, new int[]{
315-
0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17});
339+
0, 9, 1, 10, 2, 11, 3, 12, 4, 13, 5, 14, 6, 15, 7, 16, 8, 17});
316340

317-
ArrayMetadata.CoreArrayMetadata metadata = new ArrayMetadata.CoreArrayMetadata(
318-
new long[]{2, 3, 3},
319-
new int[]{2, 3, 3},
320-
DataType.UINT32,
321-
null);
322341
TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 0}));
323-
TransposeCodec transposeCodecWrongOrder1 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 2}));
324-
TransposeCodec transposeCodecWrongOrder2 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3}));
325-
TransposeCodec transposeCodecWrongOrder3 = new TransposeCodec(new TransposeCodec.Configuration(new int[]{1, 2, 3, 0}));
326-
transposeCodec.setCoreArrayMetadata(metadata);
327-
transposeCodecWrongOrder1.setCoreArrayMetadata(metadata);
328-
transposeCodecWrongOrder2.setCoreArrayMetadata(metadata);
329-
transposeCodecWrongOrder3.setCoreArrayMetadata(metadata);
342+
transposeCodec.setCoreArrayMetadata(new ArrayMetadata.CoreArrayMetadata(
343+
new long[]{2, 3, 3},
344+
new int[]{2, 3, 3},
345+
DataType.UINT32,
346+
null));
330347

331348
assert MAMath.equals(testDataTransposed120, transposeCodec.encode(testData));
332349
assert MAMath.equals(testData, transposeCodec.decode(testDataTransposed120));
333-
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder1.encode(testData));
334-
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder2.encode(testData));
335-
assertThrows(ZarrException.class, () -> transposeCodecWrongOrder3.encode(testData));
336350
}
337351

352+
static Stream<int[]> invalidTransposeOrder() {
353+
return Stream.of(
354+
new int[]{1, 0, 0},
355+
new int[]{1, 2, 3},
356+
new int[]{1,2,3,0},
357+
new int[]{1,2}
358+
);
359+
}
360+
361+
@ParameterizedTest
362+
@MethodSource("invalidChunkSizes")
363+
public void testCheckInvalidTransposeOrder(int[] transposeOrder) throws Exception {
364+
int[] shapeInt = new int[]{2, 3, 3};
365+
long[] shapeLong = new long[]{2, 3, 3};
366+
367+
TransposeCodec transposeCodec = new TransposeCodec(new TransposeCodec.Configuration(transposeOrder));
368+
transposeCodec.setCoreArrayMetadata(new ArrayMetadata.CoreArrayMetadata(
369+
shapeLong,
370+
shapeInt,
371+
DataType.UINT32,
372+
null));
373+
374+
ucar.ma2.Array testData = ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, shapeInt);
375+
assertThrows(ZarrException.class, () -> transposeCodec.encode(testData));
376+
}
338377
@Test
339378
public void testFileSystemStores() throws IOException, ZarrException {
340379
FilesystemStore fsStore = new FilesystemStore(TESTDATA);

0 commit comments

Comments
 (0)