Skip to content

Commit a6512de

Browse files
committed
make MemoryStore allways concurrent
1 parent 250daf1 commit a6512de

File tree

3 files changed

+8
-60
lines changed

3 files changed

+8
-60
lines changed

src/main/java/dev/zarr/zarrjava/store/ConcurrentMemoryStore.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

src/main/java/dev/zarr/zarrjava/store/MemoryStore.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@
44
import javax.annotation.Nullable;
55
import java.nio.ByteBuffer;
66
import java.util.*;
7+
import java.util.concurrent.ConcurrentHashMap;
78
import java.util.stream.Stream;
89

910
public class MemoryStore implements Store, Store.ListableStore {
10-
private final Map<List<String>, byte[]> map = map();
11-
12-
protected Map<List<String>, byte[]> map(){
13-
return new HashMap<>();
14-
}
11+
private final Map<List<String>, byte[]> map = new ConcurrentHashMap<>();
1512

1613
List<String> resolveKeys(String[] keys) {
1714
ArrayList<String> resolvedKeys = new ArrayList<>();

src/test/java/dev/zarr/zarrjava/ZarrStoreTest.java

Lines changed: 6 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -83,28 +83,12 @@ public void testHttpStore() throws IOException, ZarrException {
8383
}
8484

8585
@ParameterizedTest
86-
@CsvSource({
87-
"false,MemoryStore",
88-
"false,ConcurrentMemoryStore",
89-
"true,ConcurrentMemoryStore",
90-
})
91-
public void testMemoryStoreV3(boolean useParallel, String storeType) throws ZarrException, IOException {
86+
@CsvSource({"false", "true",})
87+
public void testMemoryStoreV3(boolean useParallel) throws ZarrException, IOException {
9288
int[] testData = new int[1024 * 1024];
9389
Arrays.setAll(testData, p -> p);
9490

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-
107-
Group group = Group.create(storeHandle);
91+
Group group = Group.create(new MemoryStore().resolve());
10892
Array array = group.createArray("array", b -> b
10993
.withShape(1024, 1024)
11094
.withDataType(DataType.UINT32)
@@ -124,28 +108,12 @@ public void testMemoryStoreV3(boolean useParallel, String storeType) throws Zarr
124108
}
125109

126110
@ParameterizedTest
127-
@CsvSource({
128-
"false,MemoryStore",
129-
"false,ConcurrentMemoryStore",
130-
"true,ConcurrentMemoryStore",
131-
})
132-
public void testMemoryStoreV2(boolean useParallel, String storeType) throws ZarrException, IOException {
111+
@CsvSource({"false", "true",})
112+
public void testMemoryStoreV2(boolean useParallel) throws ZarrException, IOException {
133113
int[] testData = new int[1024 * 1024];
134114
Arrays.setAll(testData, p -> p);
135115

136-
StoreHandle storeHandle;
137-
switch (storeType) {
138-
case "ConcurrentMemoryStore":
139-
storeHandle = new ConcurrentMemoryStore().resolve();
140-
break;
141-
case "MemoryStore":
142-
storeHandle = new MemoryStore().resolve();
143-
break;
144-
default:
145-
throw new IllegalArgumentException("Unknown store type: " + storeType);
146-
}
147-
148-
dev.zarr.zarrjava.v2.Group group = dev.zarr.zarrjava.v2.Group.create(storeHandle);
116+
dev.zarr.zarrjava.v2.Group group = dev.zarr.zarrjava.v2.Group.create(new MemoryStore().resolve());
149117
dev.zarr.zarrjava.v2.Array array = group.createArray("array", b -> b
150118
.withShape(1024, 1024)
151119
.withDataType(dev.zarr.zarrjava.v2.DataType.UINT32)

0 commit comments

Comments
 (0)