-
Notifications
You must be signed in to change notification settings - Fork 22
Further tests and delete chunk data after resize #49
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a57b094
add tests
brokkoli71 a270e57
Merge branch 'main' into further-tests
brokkoli71 f9d4fd5
test resize and reopen array
brokkoli71 f7086e6
add resizeMetadataOnly argument for resize
brokkoli71 329e6e1
Merge branch 'refs/heads/main' into further-tests
brokkoli71 c726ff8
reformat
brokkoli71 7d2bafb
default to parallel read, write
brokkoli71 a24027b
Merge branch 'main' into further-tests
brokkoli71 567ae11
resize default to parallel and resizeMetadataOnly
brokkoli71 68c671a
Merge branch 'main' into further-tests
brokkoli71 4a6fa8c
update tests with long
brokkoli71 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,154 @@ | ||
| package dev.zarr.zarrjava; | ||
|
|
||
| import dev.zarr.zarrjava.store.FilesystemStore; | ||
| import dev.zarr.zarrjava.store.StoreHandle; | ||
| import dev.zarr.zarrjava.v3.Array; | ||
| import dev.zarr.zarrjava.v3.DataType; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.io.IOException; | ||
| import java.nio.file.Path; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.*; | ||
|
|
||
| public class ParallelWriteTest extends ZarrTest { | ||
|
|
||
| @Test | ||
| public void testParallelWriteDataSafety() throws IOException, ZarrException { | ||
| // Test internal parallelism of write method (using parallel=true) | ||
| Path path = TESTOUTPUT.resolve("parallel_write_safety"); | ||
| StoreHandle storeHandle = new FilesystemStore(path).resolve(); | ||
|
|
||
| int shape = 1000; | ||
| int chunk = 100; | ||
|
|
||
| Array array = Array.create(storeHandle, Array.metadataBuilder() | ||
| .withShape(shape, shape) | ||
| .withDataType(DataType.INT32) | ||
| .withChunkShape(chunk, chunk) | ||
| .withFillValue(0) | ||
| .build()); | ||
|
|
||
| int[] data = new int[shape * shape]; | ||
| // Fill with some deterministic pattern | ||
| for (int i = 0; i < shape * shape; i++) { | ||
| data[i] = i; | ||
| } | ||
|
|
||
| ucar.ma2.Array outputData = ucar.ma2.Array.factory(ucar.ma2.DataType.INT, new int[]{shape, shape}, data); | ||
|
|
||
| // Write in parallel | ||
| array.write(outputData, true); | ||
|
|
||
| // Read back | ||
| ucar.ma2.Array readData = array.read(); | ||
| int[] readArr = (int[]) readData.get1DJavaArray(ucar.ma2.DataType.INT); | ||
|
|
||
| Assertions.assertArrayEquals(data, readArr, "Data read back should match data written in parallel"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testParallelWriteWithSharding() throws IOException, ZarrException { | ||
| // Test internal parallelism with Sharding (nested chunks + shared codec state potential) | ||
| Path path = TESTOUTPUT.resolve("parallel_write_sharding"); | ||
| StoreHandle storeHandle = new FilesystemStore(path).resolve(); | ||
|
|
||
| int shape = 128; // 128x128 | ||
| int shardSize = 64; // Shards are 64x64 | ||
| int innerChunk = 32; // Inner chunks 32x32 | ||
|
|
||
| // Metadata with sharding | ||
| // With shape 128 and shardSize 64, we have 2x2 = 4 shards. | ||
| // Array.write(parallel=true) will likely process these shards concurrently. | ||
| dev.zarr.zarrjava.v3.ArrayMetadata metadata = Array.metadataBuilder() | ||
| .withShape(shape, shape) | ||
| .withDataType(DataType.INT32) | ||
| .withChunkShape(shardSize, shardSize) // This sets the shard shape (outer chunks) | ||
| .withCodecs(c -> c.withSharding(new int[]{innerChunk, innerChunk}, c2 -> c2.withBytes("LITTLE"))) | ||
| .withFillValue(0) | ||
| .build(); | ||
|
|
||
| Array array = Array.create(storeHandle, metadata); | ||
|
|
||
| int[] data = new int[shape * shape]; | ||
| for (int i = 0; i < shape * shape; i++) { | ||
| data[i] = i; | ||
| } | ||
|
|
||
| ucar.ma2.Array outputData = ucar.ma2.Array.factory(ucar.ma2.DataType.INT, new int[]{shape, shape}, data); | ||
|
|
||
| // Write in parallel | ||
| array.write(outputData, true); | ||
|
|
||
| ucar.ma2.Array readData = array.read(); | ||
| int[] readArr = (int[]) readData.get1DJavaArray(ucar.ma2.DataType.INT); | ||
|
|
||
| Assertions.assertArrayEquals(data, readArr, "Sharded data written in parallel should match"); | ||
| } | ||
|
|
||
| @Test | ||
| public void testConcurrentWritesDifferentChunks() throws IOException, ZarrException, InterruptedException, ExecutionException { | ||
| // Test external parallelism (multiple threads calling write on same Array instance) | ||
| Path path = TESTOUTPUT.resolve("concurrent_write_safety"); | ||
| StoreHandle storeHandle = new FilesystemStore(path).resolve(); | ||
|
|
||
| int chunksX = 10; | ||
| int chunksY = 10; | ||
| int chunkSize = 50; | ||
| int shapeX = chunksX * chunkSize; | ||
| int shapeY = chunksY * chunkSize; | ||
|
|
||
| Array array = Array.create(storeHandle, Array.metadataBuilder() | ||
| .withShape(shapeX, shapeY) | ||
| .withDataType(DataType.INT32) | ||
| .withChunkShape(chunkSize, chunkSize) | ||
| .withFillValue(-1) | ||
| .build()); | ||
|
|
||
| ExecutorService executor = Executors.newFixedThreadPool(8); | ||
| List<Callable<Void>> tasks = new ArrayList<>(); | ||
|
|
||
| for (int i = 0; i < chunksX; i++) { | ||
| for (int j = 0; j < chunksY; j++) { | ||
| final int cx = i; | ||
| final int cy = j; | ||
| tasks.add(() -> { | ||
| int[] chunkData = new int[chunkSize * chunkSize]; | ||
| int val = cx * chunksY + cy; // Unique value per chunk | ||
| java.util.Arrays.fill(chunkData, val); | ||
|
|
||
| ucar.ma2.Array ucarArray = ucar.ma2.Array.factory(ucar.ma2.DataType.INT, new int[]{chunkSize, chunkSize}, chunkData); | ||
|
|
||
| // Write to specific chunk offset | ||
| long[] offset = new long[]{cx * chunkSize, cy * chunkSize}; | ||
| // Use internal parallelism false to isolate external concurrency test mechanism | ||
| array.write(offset, ucarArray, false); | ||
| return null; | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| List<Future<Void>> futures = executor.invokeAll(tasks); | ||
|
|
||
| for (Future<Void> f : futures) { | ||
| f.get(); // Check for exceptions | ||
| } | ||
| executor.shutdown(); | ||
|
|
||
| // Verification | ||
| ucar.ma2.Array readData = array.read(); | ||
| for (int i = 0; i < chunksX; i++) { | ||
| for (int j = 0; j < chunksY; j++) { | ||
| int expectedVal = i * chunksY + j; | ||
| int originX = i * chunkSize; | ||
| int originY = j * chunkSize; | ||
|
|
||
| // Verify a pixel in the chunk | ||
| int val = readData.getInt(readData.getIndex().set(originX, originY)); | ||
| Assertions.assertEquals(expectedVal, val, "Value at chunk " + i + "," + j + " mismatch"); | ||
| } | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.