-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathHttpStoreTest.java
More file actions
130 lines (111 loc) · 4.67 KB
/
Copy pathHttpStoreTest.java
File metadata and controls
130 lines (111 loc) · 4.67 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
127
128
129
130
package dev.zarr.zarrjava.store;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.SocketPolicy;
import dev.zarr.zarrjava.ZarrException;
import dev.zarr.zarrjava.core.Array;
import org.junit.jupiter.api.*;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
class HttpStoreTest extends StoreTest {
@BeforeEach
void setupLogging() {
Logger.getLogger(MockWebServer.class.getName()).setLevel(Level.SEVERE);
}
@Override
StoreHandle storeHandleWithData() {
return br00109990StoreHandle().resolve("c", "0", "0", "0");
}
@Override
StoreHandle storeHandleWithoutData() {
return br00109990StoreHandle().resolve("nonexistent", "path", "to", "data");
}
@Override
Store storeWithArrays() {
return br00109990StoreHandle().store;
}
StoreHandle br00109990StoreHandle() {
HttpStore httpStore = new HttpStore("https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0033A");
return httpStore.resolve("BR00109990_C2.zarr", "0", "0");
}
@Test
public void testOpen() throws IOException, ZarrException {
Array array = Array.open(br00109990StoreHandle());
Assertions.assertArrayEquals(new long[]{5, 1552, 2080}, array.metadata().shape);
}
@Test
public void testCustomParameters() {
HttpStore httpStore = new HttpStore("https://uk1s3.embassy.ebi.ac.uk/idr/zarr/v0.5/idr0033A");
Assertions.assertTrue(httpStore.resolve("BR00109990_C2.zarr", "0", "0", "c", "0", "0", "0").exists());
Assertions.assertFalse(httpStore.resolve("nonexistent").exists());
}
@Test
public void testRetryOnTimeout() throws IOException {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
server.enqueue(new MockResponse().setBody("data").setResponseCode(200));
server.start();
HttpStore httpStore = new HttpStore(server.url("/").toString(), 1, 3, 10);
Assertions.assertNotNull(httpStore.get(new String[]{"path"}));
Assertions.assertEquals(2, server.getRequestCount());
}
}
@Test
public void testRetryExhausted() throws IOException {
try (MockWebServer server = new MockWebServer()) {
for (int i = 0; i < 3; i++) {
server.enqueue(new MockResponse().setSocketPolicy(SocketPolicy.NO_RESPONSE));
}
server.start();
HttpStore httpStore = new HttpStore(server.url("/").toString(), 1, 2, 10);
Assertions.assertThrows(StoreException.class, () -> httpStore.get(new String[]{"path"}));
Assertions.assertEquals(3, server.getRequestCount());
}
}
@Test
public void testNoRetryOn404() throws IOException {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setResponseCode(404));
server.start();
HttpStore httpStore = new HttpStore(server.url("/").toString(), 1, 3, 10);
Assertions.assertNull(httpStore.get(new String[]{"path"}));
Assertions.assertEquals(1, server.getRequestCount());
}
}
@Test
public void testOpenEndedRangeHeader() throws IOException, InterruptedException {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setBody("data").setResponseCode(206));
server.start();
HttpStore httpStore = new HttpStore(server.url("/").toString(), 1, 3, 10);
Assertions.assertNotNull(httpStore.getInputStream(new String[]{"path"}, 0, -1));
Assertions.assertEquals("bytes=0-", server.takeRequest().getHeader("Range"));
}
}
@Test
public void testBoundedRangeHeader() throws IOException, InterruptedException {
try (MockWebServer server = new MockWebServer()) {
server.enqueue(new MockResponse().setBody("dat").setResponseCode(206));
server.start();
HttpStore httpStore = new HttpStore(server.url("/").toString(), 1, 3, 10);
Assertions.assertNotNull(httpStore.getInputStream(new String[]{"path"}, 1, 4));
Assertions.assertEquals("bytes=1-3", server.takeRequest().getHeader("Range"));
}
}
@Override
@Test
@Disabled("List is not supported in HttpStore")
public void testList() {
}
@Override
@Test
@Disabled("List is not supported in HttpStore")
public void testListedItemsExist() {
}
@Override
@Test
@Disabled("List is not supported in HttpStore")
public void testListChildren() {
}
}