Skip to content

Commit 1749296

Browse files
add ipv6 test case
1 parent 7c7c71d commit 1749296

File tree

1 file changed

+135
-15
lines changed

1 file changed

+135
-15
lines changed

bookkeeper-common/src/test/java/org/apache/bookkeeper/common/net/ServiceURITest.java

Lines changed: 135 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ public void testMissingServiceName() {
9494
null, new String[0], null, new String[] { "localhost:2181" }, "/path/to/namespace");
9595
}
9696

97+
@Test
98+
public void testMissingServiceNameIPV6() {
99+
String serviceUri = "//[fec0:0:0:ffff::1]:2181/path/to/namespace";
100+
assertServiceUri(
101+
serviceUri,
102+
null, new String[0], null, new String[] { "[fec0:0:0:ffff::1]:2181" }, "/path/to/namespace");
103+
}
104+
97105
@Test
98106
public void testEmptyPath() {
99107
String serviceUri = "bk://localhost:2181";
@@ -102,6 +110,14 @@ public void testEmptyPath() {
102110
"bk", new String[0], null, new String[] { "localhost:2181" }, "");
103111
}
104112

113+
@Test
114+
public void testEmptyPathIPV6() {
115+
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181";
116+
assertServiceUri(
117+
serviceUri,
118+
"bk", new String[0], null, new String[] { "[fec0:0:0:ffff::1]:2181" }, "");
119+
}
120+
105121
@Test
106122
public void testRootPath() {
107123
String serviceUri = "bk://localhost:2181/";
@@ -110,6 +126,14 @@ public void testRootPath() {
110126
"bk", new String[0], null, new String[] { "localhost:2181" }, "/");
111127
}
112128

129+
@Test
130+
public void testRootPathIPV6() {
131+
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181/";
132+
assertServiceUri(
133+
serviceUri,
134+
"bk", new String[0], null, new String[] { "[fec0:0:0:ffff::1]:2181" }, "/");
135+
}
136+
113137
@Test
114138
public void testUserInfo() {
115139
String serviceUri = "bk://bookkeeper@localhost:2181/path/to/namespace";
@@ -122,6 +146,18 @@ public void testUserInfo() {
122146
"/path/to/namespace");
123147
}
124148

149+
@Test
150+
public void testUserInfoIPV6() {
151+
String serviceUri = "bk://bookkeeper@[fec0:0:0:ffff::1]:2181/path/to/namespace";
152+
assertServiceUri(
153+
serviceUri,
154+
"bk",
155+
new String[0],
156+
"bookkeeper",
157+
new String[] { "[fec0:0:0:ffff::1]:2181" },
158+
"/path/to/namespace");
159+
}
160+
125161
@Test
126162
public void testMultipleHostsSemiColon() {
127163
String serviceUri = "bk://host1:2181;host2:2181;host3:2181/path/to/namespace";
@@ -134,6 +170,18 @@ public void testMultipleHostsSemiColon() {
134170
"/path/to/namespace");
135171
}
136172

173+
@Test
174+
public void testMultipleHostsSemiColonIPV6() {
175+
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181;[fec0:0:0:ffff::2]:2181;[fec0:0:0:ffff::3]:2181/path/to/namespace";
176+
assertServiceUri(
177+
serviceUri,
178+
"bk",
179+
new String[0],
180+
null,
181+
new String[] { "[fec0:0:0:ffff::1]:2181", "[fec0:0:0:ffff::2]:2181", "[fec0:0:0:ffff::3]:2181" },
182+
"/path/to/namespace");
183+
}
184+
137185
@Test
138186
public void testMultipleHostsComma() {
139187
String serviceUri = "bk://host1:2181,host2:2181,host3:2181/path/to/namespace";
@@ -146,6 +194,18 @@ public void testMultipleHostsComma() {
146194
"/path/to/namespace");
147195
}
148196

197+
@Test
198+
public void testMultipleHostsCommaIPV6() {
199+
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181,[fec0:0:0:ffff::2]:2181,[fec0:0:0:ffff::3]:2181/path/to/namespace";
200+
assertServiceUri(
201+
serviceUri,
202+
"bk",
203+
new String[0],
204+
null,
205+
new String[] { "[fec0:0:0:ffff::1]:2181", "[fec0:0:0:ffff::2]:2181", "[fec0:0:0:ffff::3]:2181" },
206+
"/path/to/namespace");
207+
}
208+
149209
@Test
150210
public void testMultipleHostsWithoutPorts() {
151211
String serviceUri = "bk://host1,host2,host3/path/to/namespace";
@@ -158,6 +218,18 @@ public void testMultipleHostsWithoutPorts() {
158218
"/path/to/namespace");
159219
}
160220

221+
@Test
222+
public void testMultipleHostsWithoutPortsIPV6() {
223+
String serviceUri = "bk://[fec0:0:0:ffff::1],[fec0:0:0:ffff::2],[fec0:0:0:ffff::3]/path/to/namespace";
224+
assertServiceUri(
225+
serviceUri,
226+
"bk",
227+
new String[0],
228+
null,
229+
new String[] { "[fec0:0:0:ffff::1]:4181", "[fec0:0:0:ffff::2]:4181", "[fec0:0:0:ffff::3]:4181" },
230+
"/path/to/namespace");
231+
}
232+
161233
@Test
162234
public void testMultipleHostsMixedPorts() {
163235
String serviceUri = "bk://host1:3181,host2,host3:2181/path/to/namespace";
@@ -170,6 +242,18 @@ public void testMultipleHostsMixedPorts() {
170242
"/path/to/namespace");
171243
}
172244

245+
@Test
246+
public void testMultipleHostsMixedPortsIPV6() {
247+
String serviceUri = "bk://[fec0:0:0:ffff::1]:3181,[fec0:0:0:ffff::2],[fec0:0:0:ffff::3]:2181/path/to/namespace";
248+
assertServiceUri(
249+
serviceUri,
250+
"bk",
251+
new String[0],
252+
null,
253+
new String[] { "[fec0:0:0:ffff::1]:3181", "[fec0:0:0:ffff::2]:4181", "[fec0:0:0:ffff::3]:2181" },
254+
"/path/to/namespace");
255+
}
256+
173257
@Test
174258
public void testMultipleHostsMixed() {
175259
String serviceUri = "bk://host1:2181,host2,host3:2181/path/to/namespace";
@@ -182,6 +266,18 @@ public void testMultipleHostsMixed() {
182266
"/path/to/namespace");
183267
}
184268

269+
@Test
270+
public void testMultipleHostsMixedIPV6() {
271+
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181,[fec0:0:0:ffff::2],[fec0:0:0:ffff::3]:2181/path/to/namespace";
272+
assertServiceUri(
273+
serviceUri,
274+
"bk",
275+
new String[0],
276+
null,
277+
new String[] { "[fec0:0:0:ffff::1]:2181", "[fec0:0:0:ffff::2]:4181", "[fec0:0:0:ffff::3]:2181" },
278+
"/path/to/namespace");
279+
}
280+
185281
@Test
186282
public void testUserInfoWithMultipleHosts() {
187283
String serviceUri = "bk://bookkeeper@host1:2181;host2:2181;host3:2181/path/to/namespace";
@@ -194,6 +290,18 @@ public void testUserInfoWithMultipleHosts() {
194290
"/path/to/namespace");
195291
}
196292

293+
@Test
294+
public void testUserInfoWithMultipleHostsIPV6() {
295+
String serviceUri = "bk://bookkeeper@[fec0:0:0:ffff::1]:2181;[fec0:0:0:ffff::2]:2181;[fec0:0:0:ffff::3]:2181/path/to/namespace";
296+
assertServiceUri(
297+
serviceUri,
298+
"bk",
299+
new String[0],
300+
"bookkeeper",
301+
new String[] { "[fec0:0:0:ffff::1]:2181", "[fec0:0:0:ffff::2]:2181", "[fec0:0:0:ffff::3]:2181" },
302+
"/path/to/namespace");
303+
}
304+
197305
@Test
198306
public void testServiceInfoPlus() {
199307
String serviceUri = "bk+ssl://host:2181/path/to/namespace";
@@ -207,29 +315,17 @@ public void testServiceInfoPlus() {
207315
}
208316

209317
@Test
210-
public void testIPv6Address() {
211-
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181/path/to/namespace";
318+
public void testServiceInfoPlusIPV6() {
319+
String serviceUri = "bk+ssl://[fec0:0:0:ffff::1]:2181/path/to/namespace";
212320
assertServiceUri(
213321
serviceUri,
214322
"bk",
215-
new String[0],
323+
new String[] { "ssl" },
216324
null,
217325
new String[] { "[fec0:0:0:ffff::1]:2181" },
218326
"/path/to/namespace");
219327
}
220328

221-
@Test
222-
public void testMultipleIPv6Address() {
223-
String serviceUri = "bk://[fec0:0:0:ffff::1]:2181;[fec0:0:0:ffff::2]:2181/path/to/namespace";
224-
assertServiceUri(
225-
serviceUri,
226-
"bk",
227-
new String[0],
228-
null,
229-
new String[] { "[fec0:0:0:ffff::1]:2181", "[fec0:0:0:ffff::2]:2181"},
230-
"/path/to/namespace");
231-
}
232-
233329
@Test
234330
public void testServiceInfoMinus() {
235331
String serviceUri = "bk-ssl://host:2181/path/to/namespace";
@@ -242,6 +338,18 @@ public void testServiceInfoMinus() {
242338
"/path/to/namespace");
243339
}
244340

341+
@Test
342+
public void testServiceInfoMinusIPV6() {
343+
String serviceUri = "bk-ssl://[fec0:0:0:ffff::1]:2181/path/to/namespace";
344+
assertServiceUri(
345+
serviceUri,
346+
"bk-ssl",
347+
new String[0],
348+
null,
349+
new String[] { "[fec0:0:0:ffff::1]:2181" },
350+
"/path/to/namespace");
351+
}
352+
245353
@Test
246354
public void testServiceInfoDlogMinus() {
247355
String serviceUri = "distributedlog-bk://host:2181/path/to/namespace";
@@ -254,4 +362,16 @@ public void testServiceInfoDlogMinus() {
254362
"/path/to/namespace");
255363
}
256364

365+
@Test
366+
public void testServiceInfoDlogMinusIPV6() {
367+
String serviceUri = "distributedlog-bk://[fec0:0:0:ffff::1]:2181/path/to/namespace";
368+
assertServiceUri(
369+
serviceUri,
370+
"distributedlog",
371+
new String[] { "bk" },
372+
null,
373+
new String[] { "[fec0:0:0:ffff::1]:2181" },
374+
"/path/to/namespace");
375+
}
376+
257377
}

0 commit comments

Comments
 (0)