|
1 | 1 | package dev.zarr.zarrjava; |
2 | 2 |
|
3 | 3 | import com.fasterxml.jackson.databind.ObjectMapper; |
4 | | -import dev.zarr.zarrjava.core.chunkkeyencoding.Separator; |
| 4 | +import dev.zarr.zarrjava.core.Attributes; |
5 | 5 | import dev.zarr.zarrjava.store.*; |
6 | 6 | import dev.zarr.zarrjava.v3.*; |
7 | 7 | import org.junit.jupiter.api.Assertions; |
|
14 | 14 |
|
15 | 15 | import java.io.IOException; |
16 | 16 | import java.nio.file.Files; |
| 17 | +import java.util.Arrays; |
| 18 | +import java.util.stream.Stream; |
17 | 19 |
|
18 | 20 | import static dev.zarr.zarrjava.v3.Node.makeObjectMapper; |
19 | 21 |
|
@@ -82,19 +84,79 @@ public void testHttpStore() throws IOException, ZarrException { |
82 | 84 |
|
83 | 85 | @ParameterizedTest |
84 | 86 | @CsvSource({ |
85 | | - "DOT", "SLASH" |
| 87 | + "false,MemoryStore", |
| 88 | + "false,ConcurrentMemoryStore", |
| 89 | + "true,ConcurrentMemoryStore", |
86 | 90 | }) |
87 | | - public void testMemoryStore(Separator separator) throws ZarrException, IOException { |
88 | | - StoreHandle storeHandle = new MemoryStore(separator).resolve(); |
| 91 | + public void testMemoryStoreV3(boolean useParallel, String storeType) throws ZarrException, IOException { |
| 92 | + int[] testData = new int[1024 * 1024]; |
| 93 | + Arrays.setAll(testData, p -> p); |
| 94 | + |
| 95 | + StoreHandle storeHandle; |
| 96 | + switch (storeType) { |
| 97 | + case "ConcurrentMemoryStore": |
| 98 | + storeHandle = new ConcurrentMemoryStore().resolve(); |
| 99 | + break; |
| 100 | + case "MemoryStore": |
| 101 | + storeHandle = new MemoryStore().resolve(); |
| 102 | + break; |
| 103 | + default: |
| 104 | + throw new IllegalArgumentException("Unknown store type: " + storeType); |
| 105 | + } |
| 106 | + |
89 | 107 | Group group = Group.create(storeHandle); |
90 | 108 | Array array = group.createArray("array", b -> b |
91 | | - .withShape(10, 10) |
92 | | - .withDataType(DataType.UINT8) |
| 109 | + .withShape(1024, 1024) |
| 110 | + .withDataType(DataType.UINT32) |
93 | 111 | .withChunkShape(5, 5) |
94 | 112 | ); |
| 113 | + array.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{1024, 1024}, testData), useParallel); |
95 | 114 | group.createGroup("subgroup"); |
96 | | - Assertions.assertEquals(2, group.list().count()); |
97 | | - for(String s: storeHandle.list().toArray(String[]::new)) |
98 | | - System.out.println(s); |
| 115 | + group.setAttributes(new Attributes().set("description", "test group")); |
| 116 | + Stream<dev.zarr.zarrjava.core.Node> nodes = group.list(); |
| 117 | + Assertions.assertEquals(2, nodes.count()); |
| 118 | + |
| 119 | + ucar.ma2.Array result = array.read(useParallel); |
| 120 | + Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.UINT)); |
| 121 | + Assertions.assertNotNull(group.metadata().attributes); |
| 122 | + Assertions.assertEquals("test group", group.metadata().attributes.getString("description")); |
| 123 | + } |
| 124 | + |
| 125 | + @ParameterizedTest |
| 126 | + @CsvSource({ |
| 127 | + "false,MemoryStore", |
| 128 | + "false,ConcurrentMemoryStore", |
| 129 | + "true,ConcurrentMemoryStore", |
| 130 | + }) |
| 131 | + public void testMemoryStoreV2(boolean useParallel, String storeType) throws ZarrException, IOException { |
| 132 | + int[] testData = new int[1024 * 1024]; |
| 133 | + Arrays.setAll(testData, p -> p); |
| 134 | + |
| 135 | + StoreHandle storeHandle; |
| 136 | + switch (storeType) { |
| 137 | + case "ConcurrentMemoryStore": |
| 138 | + storeHandle = new ConcurrentMemoryStore().resolve(); |
| 139 | + break; |
| 140 | + case "MemoryStore": |
| 141 | + storeHandle = new MemoryStore().resolve(); |
| 142 | + break; |
| 143 | + default: |
| 144 | + throw new IllegalArgumentException("Unknown store type: " + storeType); |
| 145 | + } |
| 146 | + |
| 147 | + dev.zarr.zarrjava.v2.Group group = dev.zarr.zarrjava.v2.Group.create(storeHandle); |
| 148 | + dev.zarr.zarrjava.v2.Array array = group.createArray("array", b -> b |
| 149 | + .withShape(1024, 1024) |
| 150 | + .withDataType(dev.zarr.zarrjava.v2.DataType.UINT32) |
| 151 | + .withChunks(5, 5) |
| 152 | + ); |
| 153 | + array.write(ucar.ma2.Array.factory(ucar.ma2.DataType.UINT, new int[]{1024, 1024}, testData), useParallel); |
| 154 | + group.createGroup("subgroup"); |
| 155 | + Stream<dev.zarr.zarrjava.core.Node> nodes = group.list(); |
| 156 | + group.setAttributes(new Attributes().set("description", "test group")); |
| 157 | + Assertions.assertEquals(2, nodes.count()); |
| 158 | + |
| 159 | + ucar.ma2.Array result = array.read(useParallel); |
| 160 | + Assertions.assertArrayEquals(testData, (int[]) result.get1DJavaArray(ucar.ma2.DataType.UINT)); |
99 | 161 | } |
100 | 162 | } |
0 commit comments