-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathReadOnlyZipStoreTest.java
More file actions
126 lines (101 loc) · 4.5 KB
/
Copy pathReadOnlyZipStoreTest.java
File metadata and controls
126 lines (101 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package dev.zarr.zarrjava.store;
import dev.zarr.zarrjava.Utils;
import dev.zarr.zarrjava.ZarrException;
import dev.zarr.zarrjava.core.Group;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import java.util.stream.Collectors;
public class ReadOnlyZipStoreTest extends StoreTest {
Path storePath = TESTOUTPUT.resolve("readOnlyZipStoreTest.zip");
StoreHandle storeHandleWithData;
@BeforeAll
void writeStoreHandleWithData() throws ZarrException, IOException {
Path source = TESTDATA.resolve("v2_sample").resolve("subgroup");
Utils.zipFile(source, storePath);
storeHandleWithData = new ReadOnlyZipStore(storePath).resolve("array", "0.0.0");
}
@Override
StoreHandle storeHandleWithData() {
return storeHandleWithData;
}
@Override
StoreHandle storeHandleWithoutData() {
return new ReadOnlyZipStore(storePath).resolve("nonexistent_key");
}
@Override
Store storeWithArrays() {
return new ReadOnlyZipStore(storePath);
}
@Test
public void testUnreadableArchiveThrows() {
ReadOnlyZipStore zipStore = new ReadOnlyZipStore(TESTOUTPUT.resolve("does_not_exist.zip"));
Assertions.assertThrows(StoreException.class, () -> zipStore.resolve().listChildren().count());
Assertions.assertThrows(StoreException.class, () -> zipStore.resolve("array", "0.0.0").exists());
}
@Override
@Test
public void testListChildren() {
ReadOnlyZipStore zipStore = new ReadOnlyZipStore(storePath);
BufferedZipStore bufferedZipStore = new BufferedZipStore(storePath);
Set<String> expectedKeys = bufferedZipStore.resolve().listChildren()
.map(node -> String.join("/", node))
.collect(Collectors.toSet());
Set<String> actualKeys = zipStore.resolve().listChildren()
.map(node -> String.join("/", node))
.collect(Collectors.toSet());
Assertions.assertFalse(actualKeys.isEmpty());
Assertions.assertEquals(expectedKeys, actualKeys);
}
@Override
@Test
public void testList() {
ReadOnlyZipStore zipStore = new ReadOnlyZipStore(storePath);
BufferedZipStore bufferedZipStore = new BufferedZipStore(storePath);
Set<String> expectedKeys = bufferedZipStore.resolve().list()
.map(node -> String.join("/", node))
.collect(Collectors.toSet());
Set<String> actualKeys = zipStore.resolve().list()
.map(node -> String.join("/", node))
.collect(Collectors.toSet());
Assertions.assertEquals(expectedKeys, actualKeys);
}
@Test
public void testOpen() throws ZarrException, IOException {
Path sourceDir = TESTOUTPUT.resolve("testZipStore");
Path targetDir = TESTOUTPUT.resolve("testZipStore.zip");
FilesystemStore fsStore = new FilesystemStore(sourceDir);
writeTestGroupV3(fsStore.resolve(), true);
Utils.zipFile(sourceDir, targetDir);
ReadOnlyZipStore readOnlyZipStore = new ReadOnlyZipStore(targetDir);
assertIsTestGroupV3(Group.open(readOnlyZipStore.resolve()), true);
}
@Test
public void testReadFromBufferedZipStore() throws ZarrException, IOException {
Path path = TESTOUTPUT.resolve("testReadOnlyZipStore.zip");
String archiveComment = "This is a test ZIP archive comment.";
BufferedZipStore zipStore = new BufferedZipStore(path, archiveComment);
writeTestGroupV3(zipStore.resolve(), true);
zipStore.flush();
ReadOnlyZipStore readOnlyZipStore = new ReadOnlyZipStore(path);
Assertions.assertEquals(archiveComment, readOnlyZipStore.getArchiveComment(), "ZIP archive comment from ReadOnlyZipStore does not match expected value.");
Set<String> expectedSubgroupKeys = new HashSet<>(Arrays.asList(
"array/c/1/1",
"array/c/0/0",
"array/c/0/1",
"zarr.json",
"array/c/1/0",
"array/zarr.json"
));
Set<String> actualKeys = readOnlyZipStore.resolve("subgroup").list()
.map(node -> String.join("/", node))
.collect(Collectors.toSet());
Assertions.assertEquals(expectedSubgroupKeys, actualKeys);
assertIsTestGroupV3(Group.open(readOnlyZipStore.resolve()), true);
}
}