2424import java .util .ArrayList ;
2525import java .util .Arrays ;
2626import java .util .Collections ;
27+ import java .util .List ;
28+ import java .util .stream .Collectors ;
2729import java .util .stream .Stream ;
2830import java .util .zip .ZipEntry ;
2931
@@ -79,11 +81,12 @@ static Stream<StoreHandle> inputStreamStores() throws IOException {
7981 );
8082 }
8183
82- static Stream <Store > localStores () {
84+ static Stream <Store . ListableStore > localStores () {
8385 return Stream .of (
8486 new MemoryStore (),
8587 new FilesystemStore (TESTOUTPUT .resolve ("testLocalStoresFS" )),
86- new BufferedZipStore (TESTOUTPUT .resolve ("testLocalStoresZIP.zip" ), true )
88+ new BufferedZipStore (TESTOUTPUT .resolve ("testLocalStoresZIP.zip" ), true ),
89+ new ReadOnlyZipStore (TESTOUTPUT .resolve ("testLocalStoresReadOnlyZIP.zip" ))
8790 );
8891 }
8992
@@ -113,8 +116,7 @@ public void testFileSystemStores() throws IOException, ZarrException {
113116 Assertions .assertInstanceOf (Array .class , Array .open (fsStore .resolve ("l4_sample" , "color" , "1" )));
114117
115118 Node [] subNodes = Group .open (fsStore .resolve ("l4_sample" )).list ().toArray (Node []::new );
116- Assertions .assertEquals (2 , subNodes .length );
117- Assertions .assertInstanceOf (Group .class , subNodes [0 ]);
119+ Assertions .assertEquals (12 , subNodes .length );
118120
119121 Array [] colorSubNodes = ((Group ) Group .open (fsStore .resolve ("l4_sample" )).get ("color" )).list ().toArray (Array []::new );
120122
@@ -366,9 +368,34 @@ public void testReadOnlyZipStore() throws ZarrException, IOException {
366368
367369 @ ParameterizedTest
368370 @ MethodSource ("localStores" )
369- public void testLocalStores (Store store ) throws IOException , ZarrException {
371+ public void testLocalStores (Store . ListableStore store ) throws IOException , ZarrException {
370372 boolean useParallel = true ;
371- Group group = writeTestGroupV3 (store , useParallel );
373+ Store writeStore = store ;
374+ if (store instanceof ReadOnlyZipStore ) {
375+ StoreHandle underlyingStore = ((ReadOnlyZipStore )store ).underlyingStore ;
376+ writeStore = new BufferedZipStore (underlyingStore , true );
377+ }
378+ Group group = writeTestGroupV3 (writeStore , useParallel );
379+
380+ java .util .Set <String > expectedSubgroupKeys = new java .util .HashSet <>(Arrays .asList (
381+ "array/c/1/1" ,
382+ "array/c/0/0" ,
383+ "array/c/0/1" ,
384+ "zarr.json" ,
385+ "array" ,
386+ "array/c/1/0" ,
387+ "array/c/1" ,
388+ "array/c/0" ,
389+ "array/zarr.json" ,
390+ "array/c"
391+ ));
392+
393+ java .util .Set <String > actualKeys = store .resolve ("subgroup" ).list ()
394+ .map (node -> String .join ("/" , node ))
395+ .collect (Collectors .toSet ());
396+
397+ Assertions .assertEquals (expectedSubgroupKeys , actualKeys );
398+
372399 assertIsTestGroupV3 (group , useParallel );
373400 }
374401
@@ -389,18 +416,30 @@ Group writeTestGroupV3(Store store, boolean useParallel) throws ZarrException, I
389416 .withChunkShape (512 , 512 )
390417 );
391418 array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ()), useParallel );
392- group .createGroup ("subgroup" );
419+ dev .zarr .zarrjava .v3 .Group subgroup = group .createGroup ("subgroup" );
420+ dev .zarr .zarrjava .v3 .Array subgrouparray = subgroup .createArray ("array" , b -> b
421+ .withShape (1024 , 1024 )
422+ .withDataType (dev .zarr .zarrjava .v3 .DataType .UINT32 )
423+ .withChunkShape (512 , 512 )
424+ );
425+ subgrouparray .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ()), useParallel );
426+
393427 group .setAttributes (new Attributes (b -> b .set ("some" , "value" )));
394428 return group ;
395429 }
396430
397431 void assertIsTestGroupV3 (Group group , boolean useParallel ) throws ZarrException , IOException {
398432 Stream <Node > nodes = group .list ();
399- Assertions .assertEquals (2 , nodes .count ());
433+ List <Node > nodeList = nodes .collect (Collectors .toList ());
434+ Assertions .assertEquals (3 , nodeList .size ());
400435 Array array = (Array ) group .get ("array" );
401436 Assertions .assertNotNull (array );
402437 ucar .ma2 .Array result = array .read (useParallel );
403438 Assertions .assertArrayEquals (testData (), (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
439+ Group subgroup = (Group ) group .get ("subgroup" );
440+ Array subgrouparray = (Array ) subgroup .get ("array" );
441+ result = subgrouparray .read (useParallel );
442+ Assertions .assertArrayEquals (testData (), (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
404443 Attributes attrs = group .metadata ().attributes ();
405444 Assertions .assertNotNull (attrs );
406445 Assertions .assertEquals ("value" , attrs .getString ("some" ));
0 commit comments