Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,24 @@ jobs:
- name: Install uv
uses: astral-sh/setup-uv@v6

- name: Cache testdata
id: cache-testdata
uses: actions/cache@v4
with:
path: testdata/l4_sample
key: testdata-l4_sample-v1

- name: Download testdata
if: steps.cache-testdata.outputs.cache-hit != 'true'
run: |
mkdir testoutput
curl https://static.webknossos.org/data/zarr_v3/l4_sample.zip -o testdata/l4_sample.zip
curl -fL --retry 5 --retry-delay 10 --retry-all-errors \
https://static.webknossos.org/data/zarr_v3/l4_sample.zip -o testdata/l4_sample.zip
cd testdata
unzip l4_sample.zip
unzip -q l4_sample.zip
rm l4_sample.zip

- name: Create testoutput
run: mkdir -p testoutput

- name: Build
run: mvn compile
Expand Down
40 changes: 40 additions & 0 deletions src/test/java/dev/zarr/zarrjava/ZarrTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package dev.zarr.zarrjava;

import dev.zarr.zarrjava.core.Attributes;
import dev.zarr.zarrjava.store.StoreHandle;
import dev.zarr.zarrjava.v3.Array;
import dev.zarr.zarrjava.v3.ArrayMetadataBuilder;
import dev.zarr.zarrjava.v3.DataType;
import dev.zarr.zarrjava.v3.codec.CodecBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;

Expand All @@ -12,8 +16,11 @@
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;
import java.util.stream.Stream;

import static dev.zarr.zarrjava.utils.Utils.toLongArray;

public class ZarrTest {

public static final Path TESTDATA = Paths.get("testdata");
Expand Down Expand Up @@ -231,5 +238,38 @@ protected void assertIsTestdata(ucar.ma2.Array result, dev.zarr.zarrjava.core.Da
}
}

/**
* Writes {@link #testdata(dev.zarr.zarrjava.core.DataType)} through the given codec pipeline,
* reopens the array from the store and asserts the data round-trips unchanged.
* Uses the array's default chunk shape.
*/
protected void assertCodecRoundtrip(StoreHandle storeHandle, DataType dataType,
Function<CodecBuilder, CodecBuilder> codecs) throws ZarrException, IOException {
assertCodecRoundtrip(storeHandle, dataType, null, codecs);
}

/**
* Writes {@link #testdata(dev.zarr.zarrjava.core.DataType)} through the given codec pipeline,
* reopens the array from the store and asserts the data round-trips unchanged.
*
* @param chunkShape chunk shape to use, or {@code null} for the default chunk shape
*/
protected void assertCodecRoundtrip(StoreHandle storeHandle, DataType dataType, int[] chunkShape,
Function<CodecBuilder, CodecBuilder> codecs) throws ZarrException, IOException {
ucar.ma2.Array testData = testdata(dataType);
ArrayMetadataBuilder builder = Array.metadataBuilder()
.withShape(toLongArray(testData.getShape()))
.withDataType(dataType)
.withCodecs(codecs);
if (chunkShape != null) {
builder = builder.withChunkShape(chunkShape);
}
Array array = Array.create(storeHandle, builder.build());
array.write(testData);

Array reopenedArray = Array.open(storeHandle);
assertIsTestdata(reopenedArray.read(), dataType);
}


}
Loading
Loading