11package dev .zarr .zarrjava .store ;
22
33import dev .zarr .zarrjava .ZarrException ;
4+ import dev .zarr .zarrjava .core .Array ;
5+ import dev .zarr .zarrjava .core .Attributes ;
46import dev .zarr .zarrjava .core .Group ;
7+ import dev .zarr .zarrjava .core .Node ;
58import org .junit .jupiter .api .Assertions ;
69import org .junit .jupiter .api .Test ;
710import org .junit .jupiter .api .TestInstance ;
11+ import org .junit .jupiter .params .ParameterizedTest ;
12+ import org .junit .jupiter .params .provider .CsvSource ;
813
914import java .io .IOException ;
1015import java .util .Arrays ;
16+ import java .util .List ;
1117import java .util .stream .Collectors ;
18+ import java .util .stream .Stream ;
1219
1320@ TestInstance (TestInstance .Lifecycle .PER_CLASS )
1421public abstract class WritableStoreTest extends StoreTest {
1522 abstract Store writableStore ();
1623
1724 @ Test
18- public void testList () throws ZarrException , IOException {
25+ public void testList () throws IOException , ZarrException {
1926 StoreHandle storeHandle = writableStore ().resolve ("testList" );
2027 boolean useParallel = true ;
2128 writeTestGroupV3 (storeHandle , useParallel );
@@ -36,6 +43,11 @@ public void testList() throws ZarrException, IOException {
3643 .map (node -> String .join ("/" , node ))
3744 .collect (Collectors .toSet ());
3845 Assertions .assertEquals (expectedSubgroupKeys , actualKeys );
46+
47+ List <String > allKeys = storeHandle .list ()
48+ .map (node -> String .join ("/" , node ))
49+ .collect (Collectors .toList ());
50+ Assertions .assertEquals (21 , allKeys .size (), "Total number of keys in store should be 21 but was: " + allKeys );
3951 }
4052
4153 @ Test
@@ -46,4 +58,56 @@ public void testWriteRead() throws IOException, ZarrException {
4658 assertIsTestGroupV3 (group , useParallel );
4759 }
4860
61+ @ ParameterizedTest
62+ @ CsvSource ({"false" , "true" ,})
63+ public void testWriteReadV3 (boolean useParallel ) throws ZarrException , IOException {
64+ int [] testData = testDataInt ();
65+ Store store = writableStore ();
66+ StoreHandle storeHandle = store .resolve ("testWriteReadV3" ).resolve (store .getClass ().getSimpleName ());
67+
68+ dev .zarr .zarrjava .v3 .Group group = dev .zarr .zarrjava .v3 .Group .create (storeHandle );
69+ Array array = group .createArray ("array" , b -> b
70+ .withShape (1024 , 1024 )
71+ .withDataType (dev .zarr .zarrjava .v3 .DataType .UINT32 )
72+ .withChunkShape (64 , 64 )
73+ );
74+ array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ), useParallel );
75+ group .createGroup ("subgroup" );
76+ group .setAttributes (new Attributes (b -> b .set ("some" , "value" )));
77+ Stream <Node > nodes = group .list ();
78+ Assertions .assertEquals (2 , nodes .count ());
79+
80+ ucar .ma2 .Array result = array .read (useParallel );
81+ Assertions .assertArrayEquals (testData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
82+ Attributes attrs = group .metadata ().attributes ;
83+ Assertions .assertNotNull (attrs );
84+ Assertions .assertEquals ("value" , attrs .getString ("some" ));
85+ }
86+
87+ @ ParameterizedTest
88+ @ CsvSource ({"false" , "true" ,})
89+ public void testMemoryStoreV2 (boolean useParallel ) throws ZarrException , IOException {
90+ int [] testData = testDataInt ();
91+ Store store = writableStore ();
92+ StoreHandle storeHandle = store .resolve ("testMemoryStoreV2" ).resolve (store .getClass ().getSimpleName ());
93+
94+ dev .zarr .zarrjava .v2 .Group group = dev .zarr .zarrjava .v2 .Group .create (storeHandle );
95+ dev .zarr .zarrjava .v2 .Array array = group .createArray ("array" , b -> b
96+ .withShape (1024 , 1024 )
97+ .withDataType (dev .zarr .zarrjava .v2 .DataType .UINT32 )
98+ .withChunks (512 , 512 )
99+ );
100+ array .write (ucar .ma2 .Array .factory (ucar .ma2 .DataType .UINT , new int []{1024 , 1024 }, testData ), useParallel );
101+ group .createGroup ("subgroup" );
102+ Stream <dev .zarr .zarrjava .core .Node > nodes = group .list ();
103+ group .setAttributes (new Attributes ().set ("description" , "test group" ));
104+ Assertions .assertEquals (2 , nodes .count ());
105+
106+ ucar .ma2 .Array result = array .read (useParallel );
107+ Assertions .assertArrayEquals (testData , (int []) result .get1DJavaArray (ucar .ma2 .DataType .UINT ));
108+ Attributes attrs = group .metadata ().attributes ;
109+ Assertions .assertNotNull (attrs );
110+ Assertions .assertEquals ("test group" , attrs .getString ("description" ));
111+ }
112+
49113}
0 commit comments