forked from docker-java/docker-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInfoTest.java
More file actions
330 lines (288 loc) · 14.4 KB
/
Copy pathInfoTest.java
File metadata and controls
330 lines (288 loc) · 14.4 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
package com.github.dockerjava.api.model;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.dockerjava.api.model.InfoRegistryConfig.IndexConfig;
import org.hamcrest.CoreMatchers;
import org.testng.annotations.Test;
import java.io.IOException;
import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import static com.github.dockerjava.core.RemoteApiVersion.VERSION_1_22;
import static com.github.dockerjava.test.serdes.JSONSamples.testRoundTrip;
import static java.util.Arrays.asList;
import static java.util.Collections.singletonList;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.isEmptyString;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
/**
* @author Kanstantsin Shautsou
*/
public class InfoTest {
@Test
public void serder1Json() throws IOException {
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(Info.class);
final Info info = testRoundTrip(VERSION_1_22,
"info/1.json",
type
);
final List<List<String>> driverStatus = asList(
asList("Root Dir", "/mnt/sda1/var/lib/docker/aufs"),
asList("Backing Filesystem", "extfs"),
asList("Dirs", "31"),
asList("Dirperm1 Supported", "true")
);
final Map<String, List<String>> plugins = new LinkedHashMap<>();
plugins.put("Volume", singletonList("local"));
plugins.put("Network", asList("bridge", "null", "host"));
plugins.put("Authorization", null);
assertThat(info, notNullValue());
assertThat(info.getArchitecture(), equalTo("x86_64"));
assertThat(info.getContainersStopped(), is(3));
assertThat(info.getContainersPaused(), is(10));
assertThat(info.getContainersRunning(), is(2));
assertThat(info.getCpuCfsPeriod(), is(true));
// not available in this dump
assertThat(info.getCpuCfsQuota(), is(true));
assertThat(info.getDiscoveryBackend(), nullValue());
assertThat(info.getOomScoreAdj(), nullValue());
assertThat(info.getDriverStatuses(), notNullValue());
assertThat(info.getDriverStatuses(), hasSize(4));
assertThat(info.getDriverStatuses(), equalTo(driverStatus));
assertThat(info.getNGoroutines(), is(40));
assertThat(info.getSystemStatus(), CoreMatchers.nullValue());
assertThat(info.getPlugins(), equalTo(plugins));
assertThat(info.getPlugins(), hasEntry("Volume", singletonList("local")));
assertThat(info.getPlugins(), hasEntry("Authorization", null));
assertThat(info.getExperimentalBuild(), is(false));
assertThat(info.getHttpProxy(), isEmptyString());
assertThat(info.getHttpsProxy(), isEmptyString());
assertThat(info.getNoProxy(), isEmptyString());
assertThat(info.getOomKillDisable(), is(true));
assertThat(info.getOsType(), equalTo("linux"));
final InfoRegistryConfig registryConfig = info.getRegistryConfig();
assertThat(registryConfig, notNullValue());
final List<String> cidRs = registryConfig.getInsecureRegistryCIDRs();
assertThat(cidRs, notNullValue());
assertThat(cidRs, contains("127.0.0.0/8"));
final Map<String, IndexConfig> indexConfigs = registryConfig.getIndexConfigs();
assertThat(indexConfigs, notNullValue());
final IndexConfig indexConfig = new IndexConfig().withMirrors(null).withName("docker.io")
.withSecure(true).withOfficial(true);
assertThat(indexConfigs, hasEntry("docker.io", indexConfig));
assertThat(registryConfig.getMirrors(), nullValue());
assertThat(info.getSystemTime(), is("2016-02-17T14:56:35.212841831Z"));
assertThat(info.getServerVersion(), is("1.10.1"));
assertThat(info.getCpuSet(), is(true));
assertThat(info.getCpuShares(), is(true));
assertThat(info.getIPv4Forwarding(), is(true));
assertThat(info.getBridgeNfIptables(), is(true));
assertThat(info.getBridgeNfIp6tables(), is(true));
assertThat(info.getDebug(), is(true));
assertThat(info.getNFd(), is(24));
assertThat(info.getOomKillDisable(), is(true));
assertThat(info.getLoggingDriver(), is("json-file"));
assertThat(info.getOperatingSystem(),
is("Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016"));
assertThat(info.getClusterStore(), is(""));
final Info withInfo = new Info().withArchitecture("x86_64")
.withContainers(2)
.withContainersRunning(2)
.withContainersPaused(10)
.withContainersStopped(3)
.withImages(13)
.withId("HLN2:5SBU:SRQR:CQI6:AB52:LZZ2:DED5:REDM:BU73:JFHE:R37A:5HMX")
.withDriver("aufs")
.withDriverStatuses(driverStatus)
.withSystemStatus(null)
.withPlugins(plugins)
.withMemoryLimit(true)
.withSwapLimit(true)
.withCpuCfsPeriod(true)
.withCpuCfsQuota(true)
.withCpuShares(true)
.withCpuSet(true)
.withIPv4Forwarding(true)
.withBridgeNfIptables(true)
.withBridgeNfIp6tables(true)
.withDebug(true)
.withNFd(24)
.withOomKillDisable(true)
.withNGoroutines(40)
.withSystemTime("2016-02-17T14:56:35.212841831Z")
.withExecutionDriver("native-0.2")
.withLoggingDriver("json-file")
.withNEventsListener(0)
.withKernelVersion("4.1.17-boot2docker")
.withOperatingSystem("Boot2Docker 1.10.1 (TCL 6.4.1); master : b03e158 - Thu Feb 11 22:34:01 UTC 2016")
.withOsType("linux")
.withIndexServerAddress("https://index.docker.io/v1/")
.withRegistryConfig(registryConfig)
.withInitSha1("")
.withInitPath("/usr/local/bin/docker")
.withNCPU(1)
.withMemTotal(1044574208L)
.withDockerRootDir("/mnt/sda1/var/lib/docker")
.withHttpProxy("")
.withHttpsProxy("")
.withNoProxy("")
.withName("docker-java")
.withLabels(new String[]{"provider=virtualbox"})
.withExperimentalBuild(false)
.withServerVersion("1.10.1")
.withClusterStore("")
.withClusterAdvertise("")
//shredinger-fields
.withDiscoveryBackend(null)
.withOomScoreAdj(null)
.withSockets(null)
;
assertThat(info, is(withInfo));
}
@Test
public void serder2Json() throws IOException {
final ObjectMapper mapper = new ObjectMapper();
final JavaType type = mapper.getTypeFactory().constructType(Info.class);
final Info info = testRoundTrip(VERSION_1_22,
"info/2.json",
type
);
final List<List<String>> driverStatus = asList(
asList("Pool Name", "docker-253:2-17567992-pool"),
asList("Pool Blocksize", "65.54 kB"),
asList("Base Device Size", "107.4 GB"),
asList("Backing Filesystem", "ext4"),
asList("Data file", "/dev/loop0"),
asList("Metadata file", "/dev/loop1"),
asList("Data Space Used", "3.89 GB"),
asList("Data Space Total", "107.4 GB"),
asList("Data Space Available", "103.5 GB"),
asList("Metadata Space Used", "5.46 MB"),
asList("Metadata Space Total", "2.147 GB"),
asList("Metadata Space Available", "2.142 GB"),
asList("Udev Sync Supported", "true"),
asList("Deferred Removal Enabled", "false"),
asList("Deferred Deletion Enabled", "false"),
asList("Deferred Deleted Device Count", "0"),
asList("Data loop file", "/var/lib/docker/devicemapper/devicemapper/data"),
asList("Metadata loop file", "/var/lib/docker/devicemapper/devicemapper/metadata"),
asList("Library Version", "1.02.107-RHEL7 (2015-12-01)")
);
final Map<String, List<String>> plugins = new LinkedHashMap<>();
plugins.put("Volume", singletonList("local"));
plugins.put("Network", asList("null", "host", "bridge"));
plugins.put("Authorization", null);
assertThat(info, notNullValue());
assertThat(info.getArchitecture(), equalTo("x86_64"));
assertThat(info.getContainersStopped(), is(2));
assertThat(info.getContainersPaused(), is(0));
assertThat(info.getContainersRunning(), is(0));
assertThat(info.getCpuCfsPeriod(), is(true));
// not available in this dump
assertThat(info.getCpuCfsQuota(), is(true));
assertThat(info.getDiscoveryBackend(), nullValue());
assertThat(info.getOomScoreAdj(), nullValue());
assertThat(info.getDriverStatuses(), notNullValue());
assertThat(info.getDriverStatuses(), hasSize(19));
assertThat(info.getDriverStatuses(), equalTo(driverStatus));
assertThat(info.getNGoroutines(), is(30));
assertThat(info.getSystemStatus(), CoreMatchers.nullValue());
assertThat(info.getPlugins(), equalTo(plugins));
assertThat(info.getPlugins(), hasEntry("Volume", singletonList("local")));
assertThat(info.getPlugins(), hasEntry("Authorization", null));
assertThat(info.getExperimentalBuild(), is(false));
assertThat(info.getHttpProxy(), isEmptyString());
assertThat(info.getHttpsProxy(), isEmptyString());
assertThat(info.getNoProxy(), isEmptyString());
assertThat(info.getOomKillDisable(), is(true));
assertThat(info.getOsType(), equalTo("linux"));
final InfoRegistryConfig registryConfig = info.getRegistryConfig();
assertThat(registryConfig, notNullValue());
final List<String> cidRs = registryConfig.getInsecureRegistryCIDRs();
assertThat(cidRs, notNullValue());
assertThat(cidRs, contains("127.0.0.0/8"));
final Map<String, IndexConfig> indexConfigs = registryConfig.getIndexConfigs();
assertThat(indexConfigs, notNullValue());
final IndexConfig indexConfig = new IndexConfig().withMirrors(null).withName("docker.io")
.withSecure(true).withOfficial(true);
assertThat(indexConfigs, hasEntry("docker.io", indexConfig));
final IndexConfig indexConfig2 = new IndexConfig().withMirrors(Collections.<String>emptyList()).withName("somehost:80")
.withSecure(false).withOfficial(false);
assertThat(indexConfigs, hasEntry("somehost:80", indexConfig2));
assertThat(registryConfig.getMirrors(), nullValue());
assertThat(info.getSystemTime(), is("2016-03-20T17:32:06.598846244+01:00"));
assertThat(info.getServerVersion(), is("1.10.2"));
assertThat(info.getCpuSet(), is(true));
assertThat(info.getCpuShares(), is(true));
assertThat(info.getIPv4Forwarding(), is(true));
assertThat(info.getBridgeNfIptables(), is(false));
assertThat(info.getBridgeNfIp6tables(), is(false));
assertThat(info.getDebug(), is(false));
assertThat(info.getNFd(), is(13));
assertThat(info.getOomKillDisable(), is(true));
assertThat(info.getLoggingDriver(), is("json-file"));
assertThat(info.getOperatingSystem(), is("Red Hat Enterprise Linux Workstation 7.2 (Maipo)"));
assertThat(info.getClusterStore(), is(""));
final Info withInfo = new Info().withArchitecture("x86_64")
.withContainers(2)
.withContainersRunning(0)
.withContainersPaused(0)
.withContainersStopped(2)
.withImages(55)
.withId("H52J:52LG:YP4W:EHKY:SRK5:RYG6:ETWR:7AR3:MTFJ:PC6C:4YF2:NTN2")
.withDriver("devicemapper")
.withDriverStatuses(driverStatus)
.withSystemStatus(null)
.withPlugins(plugins)
.withMemoryLimit(true)
.withSwapLimit(true)
.withCpuCfsPeriod(true)
.withCpuCfsQuota(true)
.withCpuShares(true)
.withCpuSet(true)
.withIPv4Forwarding(true)
.withBridgeNfIptables(false)
.withBridgeNfIp6tables(false)
.withDebug(false)
.withNFd(13)
.withOomKillDisable(true)
.withNGoroutines(30)
.withSystemTime("2016-03-20T17:32:06.598846244+01:00")
.withExecutionDriver("native-0.2")
.withLoggingDriver("json-file")
.withNEventsListener(0)
.withKernelVersion("3.10.0-327.10.1.el7.x86_64")
.withOperatingSystem("Red Hat Enterprise Linux Workstation 7.2 (Maipo)")
.withOsType("linux")
.withIndexServerAddress("https://index.docker.io/v1/")
.withRegistryConfig(registryConfig)
.withInitSha1("672d65f3cf8816fbda421afeed7e52c0ca17d5e7")
.withInitPath("/usr/libexec/docker/dockerinit")
.withNCPU(8)
.withMemTotal(33350918144L)
.withDockerRootDir("/var/lib/docker")
.withHttpProxy("")
.withHttpsProxy("")
.withNoProxy("")
.withName("somename")
.withLabels(null)
.withExperimentalBuild(false)
.withServerVersion("1.10.2")
.withClusterStore("")
.withClusterAdvertise("")
//shredinger-fields
.withDiscoveryBackend(null)
.withOomScoreAdj(null)
.withSockets(null)
;
assertThat(info, is(withInfo));
}
}