Skip to content

Commit

Permalink
Fix formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
bziobrowski committed Jan 9, 2025
1 parent 4b19737 commit 69545cb
Showing 1 changed file with 119 additions and 118 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,134 +49,135 @@ public void testHostAddressRoundRobin()
};

try (MockedStatic<InetAddress> mock = Mockito.mockStatic(InetAddress.class)) {
mock.when(() -> InetAddress.getAllByName("localhost")).thenReturn(localHostAddresses);
mock.when(() -> InetAddress.getAllByName("testweb.com")).thenReturn(testWebAddresses);
mock.when(() -> InetAddress.getAllByName("localhost")).thenReturn(localHostAddresses);
mock.when(() -> InetAddress.getAllByName("testweb.com")).thenReturn(testWebAddresses);

TestCase[] testCases = new TestCase[]{
new TestCase("http://127.0.0.1", Collections.singletonList("http://127.0.0.1")),
new TestCase("http://127.0.0.1/", Collections.singletonList("http://127.0.0.1/")),
new TestCase("http://127.0.0.1/?", Collections.singletonList("http://127.0.0.1/?")),
new TestCase("http://127.0.0.1/?it=5", Collections.singletonList("http://127.0.0.1/?it=5")),
new TestCase("http://127.0.0.1/me/out?it=5", Collections.singletonList("http://127.0.0.1/me/out?it=5")),
new TestCase("http://127.0.0.1:20000", Collections.singletonList("http://127.0.0.1:20000")),
new TestCase("http://127.0.0.1:20000/", Collections.singletonList("http://127.0.0.1:20000/")),
new TestCase("http://127.0.0.1:20000/?", Collections.singletonList("http://127.0.0.1:20000/?")),
new TestCase("http://127.0.0.1:20000/?it=5", Collections.singletonList("http://127.0.0.1:20000/?it=5")),
new TestCase("http://127.0.0.1:20000/me/out?it=5",
Collections.singletonList("http://127.0.0.1:20000/me/out?it=5")),
TestCase[] testCases = new TestCase[]{
new TestCase("http://127.0.0.1", Collections.singletonList("http://127.0.0.1")),
new TestCase("http://127.0.0.1/", Collections.singletonList("http://127.0.0.1/")),
new TestCase("http://127.0.0.1/?", Collections.singletonList("http://127.0.0.1/?")),
new TestCase("http://127.0.0.1/?it=5", Collections.singletonList("http://127.0.0.1/?it=5")),
new TestCase("http://127.0.0.1/me/out?it=5", Collections.singletonList("http://127.0.0.1/me/out?it=5")),
new TestCase("http://127.0.0.1:20000", Collections.singletonList("http://127.0.0.1:20000")),
new TestCase("http://127.0.0.1:20000/", Collections.singletonList("http://127.0.0.1:20000/")),
new TestCase("http://127.0.0.1:20000/?", Collections.singletonList("http://127.0.0.1:20000/?")),
new TestCase("http://127.0.0.1:20000/?it=5", Collections.singletonList("http://127.0.0.1:20000/?it=5")),
new TestCase("http://127.0.0.1:20000/me/out?it=5",
Collections.singletonList("http://127.0.0.1:20000/me/out?it=5")),

new TestCase("http://localhost", Arrays.asList("http://127.0.0.1", "http://[0:0:0:0:0:0:0:1]")),
new TestCase("http://localhost/", Arrays.asList("http://127.0.0.1/", "http://[0:0:0:0:0:0:0:1]/")),
new TestCase("http://localhost/?", Arrays.asList("http://127.0.0.1/?", "http://[0:0:0:0:0:0:0:1]/?")),
new TestCase("http://localhost/?it=5",
Arrays.asList("http://127.0.0.1/?it=5", "http://[0:0:0:0:0:0:0:1]/?it=5")),
new TestCase("http://localhost/me/out?it=5",
Arrays.asList("http://127.0.0.1/me/out?it=5", "http://[0:0:0:0:0:0:0:1]/me/out?it=5")),
new TestCase("http://localhost:20000",
Arrays.asList("http://127.0.0.1:20000", "http://[0:0:0:0:0:0:0:1]:20000")),
new TestCase("http://localhost:20000/",
Arrays.asList("http://127.0.0.1:20000/", "http://[0:0:0:0:0:0:0:1]:20000/")),
new TestCase("http://localhost:20000/?",
Arrays.asList("http://127.0.0.1:20000/?", "http://[0:0:0:0:0:0:0:1]:20000/?")),
new TestCase("http://localhost:20000/?it=5",
Arrays.asList("http://127.0.0.1:20000/?it=5", "http://[0:0:0:0:0:0:0:1]:20000/?it=5")),
new TestCase("http://localhost:20000/me/out?it=5",
Arrays.asList("http://127.0.0.1:20000/me/out?it=5", "http://[0:0:0:0:0:0:0:1]:20000/me/out?it=5")),
new TestCase("http://localhost", Arrays.asList("http://127.0.0.1", "http://[0:0:0:0:0:0:0:1]")),
new TestCase("http://localhost/", Arrays.asList("http://127.0.0.1/", "http://[0:0:0:0:0:0:0:1]/")),
new TestCase("http://localhost/?", Arrays.asList("http://127.0.0.1/?", "http://[0:0:0:0:0:0:0:1]/?")),
new TestCase("http://localhost/?it=5",
Arrays.asList("http://127.0.0.1/?it=5", "http://[0:0:0:0:0:0:0:1]/?it=5")),
new TestCase("http://localhost/me/out?it=5",
Arrays.asList("http://127.0.0.1/me/out?it=5", "http://[0:0:0:0:0:0:0:1]/me/out?it=5")),
new TestCase("http://localhost:20000",
Arrays.asList("http://127.0.0.1:20000", "http://[0:0:0:0:0:0:0:1]:20000")),
new TestCase("http://localhost:20000/",
Arrays.asList("http://127.0.0.1:20000/", "http://[0:0:0:0:0:0:0:1]:20000/")),
new TestCase("http://localhost:20000/?",
Arrays.asList("http://127.0.0.1:20000/?", "http://[0:0:0:0:0:0:0:1]:20000/?")),
new TestCase("http://localhost:20000/?it=5",
Arrays.asList("http://127.0.0.1:20000/?it=5", "http://[0:0:0:0:0:0:0:1]:20000/?it=5")),
new TestCase("http://localhost:20000/me/out?it=5",
Arrays.asList("http://127.0.0.1:20000/me/out?it=5", "http://[0:0:0:0:0:0:0:1]:20000/me/out?it=5")),

new TestCase("http://testweb.com",
Arrays.asList("http://192.168.3.1", "http://192.168.3.2", "http://192.168.3.3")),
new TestCase("http://testweb.com/",
Arrays.asList("http://192.168.3.1/", "http://192.168.3.2/", "http://192.168.3.3/")),
new TestCase("http://testweb.com/?",
Arrays.asList("http://192.168.3.1/?", "http://192.168.3.2/?", "http://192.168.3.3/?")),
new TestCase("http://testweb.com/?it=5",
Arrays.asList("http://192.168.3.1/?it=5", "http://192.168.3.2/?it=5", "http://192.168.3.3/?it=5")),
new TestCase("http://testweb.com/me/out?it=5",
Arrays.asList("http://192.168.3.1/me/out?it=5", "http://192.168.3.2/me/out?it=5",
"http://192.168.3.3/me/out?it=5")),
new TestCase("http://testweb.com:20000",
Arrays.asList("http://192.168.3.1:20000", "http://192.168.3.2:20000", "http://192.168.3.3:20000")),
new TestCase("http://testweb.com:20000/",
Arrays.asList("http://192.168.3.1:20000/", "http://192.168.3.2:20000/", "http://192.168.3.3:20000/")),
new TestCase("http://testweb.com:20000/?",
Arrays.asList("http://192.168.3.1:20000/?", "http://192.168.3.2:20000/?", "http://192.168.3.3:20000/?")),
new TestCase("http://testweb.com:20000/?it=5",
Arrays.asList("http://192.168.3.1:20000/?it=5", "http://192.168.3.2:20000/?it=5",
"http://192.168.3.3:20000/?it=5")),
new TestCase("http://testweb.com:20000/me/out?it=5",
Arrays.asList("http://192.168.3.1:20000/me/out?it=5", "http://192.168.3.2:20000/me/out?it=5",
"http://192.168.3.3:20000/me/out?it=5")),
new TestCase("http://testweb.com",
Arrays.asList("http://192.168.3.1", "http://192.168.3.2", "http://192.168.3.3")),
new TestCase("http://testweb.com/",
Arrays.asList("http://192.168.3.1/", "http://192.168.3.2/", "http://192.168.3.3/")),
new TestCase("http://testweb.com/?",
Arrays.asList("http://192.168.3.1/?", "http://192.168.3.2/?", "http://192.168.3.3/?")),
new TestCase("http://testweb.com/?it=5",
Arrays.asList("http://192.168.3.1/?it=5", "http://192.168.3.2/?it=5", "http://192.168.3.3/?it=5")),
new TestCase("http://testweb.com/me/out?it=5",
Arrays.asList("http://192.168.3.1/me/out?it=5", "http://192.168.3.2/me/out?it=5",
"http://192.168.3.3/me/out?it=5")),
new TestCase("http://testweb.com:20000",
Arrays.asList("http://192.168.3.1:20000", "http://192.168.3.2:20000", "http://192.168.3.3:20000")),
new TestCase("http://testweb.com:20000/",
Arrays.asList("http://192.168.3.1:20000/", "http://192.168.3.2:20000/", "http://192.168.3.3:20000/")),
new TestCase("http://testweb.com:20000/?",
Arrays.asList("http://192.168.3.1:20000/?", "http://192.168.3.2:20000/?", "http://192.168.3.3:20000/?")),
new TestCase("http://testweb.com:20000/?it=5",
Arrays.asList("http://192.168.3.1:20000/?it=5", "http://192.168.3.2:20000/?it=5",
"http://192.168.3.3:20000/?it=5")),
new TestCase("http://testweb.com:20000/me/out?it=5",
Arrays.asList("http://192.168.3.1:20000/me/out?it=5", "http://192.168.3.2:20000/me/out?it=5",
"http://192.168.3.3:20000/me/out?it=5")),

new TestCase("https://127.0.0.1", Collections.singletonList("https://127.0.0.1")),
new TestCase("https://127.0.0.1/", Collections.singletonList("https://127.0.0.1/")),
new TestCase("https://127.0.0.1/?", Collections.singletonList("https://127.0.0.1/?")),
new TestCase("https://127.0.0.1/?it=5", Collections.singletonList("https://127.0.0.1/?it=5")),
new TestCase("https://127.0.0.1/me/out?it=5", Collections.singletonList("https://127.0.0.1/me/out?it=5")),
new TestCase("https://127.0.0.1:20000", Collections.singletonList("https://127.0.0.1:20000")),
new TestCase("https://127.0.0.1:20000/", Collections.singletonList("https://127.0.0.1:20000/")),
new TestCase("https://127.0.0.1:20000/?", Collections.singletonList("https://127.0.0.1:20000/?")),
new TestCase("https://127.0.0.1:20000/?it=5", Collections.singletonList("https://127.0.0.1:20000/?it=5")),
new TestCase("https://127.0.0.1:20000/me/out?it=5",
Collections.singletonList("https://127.0.0.1:20000/me/out?it=5")),
new TestCase("https://127.0.0.1", Collections.singletonList("https://127.0.0.1")),
new TestCase("https://127.0.0.1/", Collections.singletonList("https://127.0.0.1/")),
new TestCase("https://127.0.0.1/?", Collections.singletonList("https://127.0.0.1/?")),
new TestCase("https://127.0.0.1/?it=5", Collections.singletonList("https://127.0.0.1/?it=5")),
new TestCase("https://127.0.0.1/me/out?it=5", Collections.singletonList("https://127.0.0.1/me/out?it=5")),
new TestCase("https://127.0.0.1:20000", Collections.singletonList("https://127.0.0.1:20000")),
new TestCase("https://127.0.0.1:20000/", Collections.singletonList("https://127.0.0.1:20000/")),
new TestCase("https://127.0.0.1:20000/?", Collections.singletonList("https://127.0.0.1:20000/?")),
new TestCase("https://127.0.0.1:20000/?it=5", Collections.singletonList("https://127.0.0.1:20000/?it=5")),
new TestCase("https://127.0.0.1:20000/me/out?it=5",
Collections.singletonList("https://127.0.0.1:20000/me/out?it=5")),

new TestCase("https://localhost", Arrays.asList("https://127.0.0.1", "https://[0:0:0:0:0:0:0:1]")),
new TestCase("https://localhost/", Arrays.asList("https://127.0.0.1/", "https://[0:0:0:0:0:0:0:1]/")),
new TestCase("https://localhost/?", Arrays.asList("https://127.0.0.1/?", "https://[0:0:0:0:0:0:0:1]/?")),
new TestCase("https://localhost/?it=5",
Arrays.asList("https://127.0.0.1/?it=5", "https://[0:0:0:0:0:0:0:1]/?it=5")),
new TestCase("https://localhost/me/out?it=5",
Arrays.asList("https://127.0.0.1/me/out?it=5", "https://[0:0:0:0:0:0:0:1]/me/out?it=5")),
new TestCase("https://localhost:20000",
Arrays.asList("https://127.0.0.1:20000", "https://[0:0:0:0:0:0:0:1]:20000")),
new TestCase("https://localhost:20000/",
Arrays.asList("https://127.0.0.1:20000/", "https://[0:0:0:0:0:0:0:1]:20000/")),
new TestCase("https://localhost:20000/?",
Arrays.asList("https://127.0.0.1:20000/?", "https://[0:0:0:0:0:0:0:1]:20000/?")),
new TestCase("https://localhost:20000/?it=5",
Arrays.asList("https://127.0.0.1:20000/?it=5", "https://[0:0:0:0:0:0:0:1]:20000/?it=5")),
new TestCase("https://localhost", Arrays.asList("https://127.0.0.1", "https://[0:0:0:0:0:0:0:1]")),
new TestCase("https://localhost/", Arrays.asList("https://127.0.0.1/", "https://[0:0:0:0:0:0:0:1]/")),
new TestCase("https://localhost/?", Arrays.asList("https://127.0.0.1/?", "https://[0:0:0:0:0:0:0:1]/?")),
new TestCase("https://localhost/?it=5",
Arrays.asList("https://127.0.0.1/?it=5", "https://[0:0:0:0:0:0:0:1]/?it=5")),
new TestCase("https://localhost/me/out?it=5",
Arrays.asList("https://127.0.0.1/me/out?it=5", "https://[0:0:0:0:0:0:0:1]/me/out?it=5")),
new TestCase("https://localhost:20000",
Arrays.asList("https://127.0.0.1:20000", "https://[0:0:0:0:0:0:0:1]:20000")),
new TestCase("https://localhost:20000/",
Arrays.asList("https://127.0.0.1:20000/", "https://[0:0:0:0:0:0:0:1]:20000/")),
new TestCase("https://localhost:20000/?",
Arrays.asList("https://127.0.0.1:20000/?", "https://[0:0:0:0:0:0:0:1]:20000/?")),
new TestCase("https://localhost:20000/?it=5",
Arrays.asList("https://127.0.0.1:20000/?it=5", "https://[0:0:0:0:0:0:0:1]:20000/?it=5")),

new TestCase("https://testweb.com",
Arrays.asList("https://192.168.3.1", "https://192.168.3.2", "https://192.168.3.3")),
new TestCase("https://testweb.com/",
Arrays.asList("https://192.168.3.1/", "https://192.168.3.2/", "https://192.168.3.3/")),
new TestCase("https://testweb.com/?",
Arrays.asList("https://192.168.3.1/?", "https://192.168.3.2/?", "https://192.168.3.3/?")),
new TestCase("https://testweb.com/?it=5",
Arrays.asList("https://192.168.3.1/?it=5", "https://192.168.3.2/?it=5", "https://192.168.3.3/?it=5")),
new TestCase("https://testweb.com/me/out?it=5",
Arrays.asList("https://192.168.3.1/me/out?it=5", "https://192.168.3.2/me/out?it=5",
"https://192.168.3.3/me/out?it=5")),
new TestCase("https://testweb.com:20000",
Arrays.asList("https://192.168.3.1:20000", "https://192.168.3.2:20000", "https://192.168.3.3:20000")),
new TestCase("https://testweb.com:20000/",
Arrays.asList("https://192.168.3.1:20000/", "https://192.168.3.2:20000/", "https://192.168.3.3:20000/")),
new TestCase("https://testweb.com:20000/?",
Arrays.asList("https://192.168.3.1:20000/?", "https://192.168.3.2:20000/?", "https://192.168.3.3:20000/?")),
new TestCase("https://testweb.com:20000/?it=5",
Arrays.asList("https://192.168.3.1:20000/?it=5", "https://192.168.3.2:20000/?it=5",
"https://192.168.3.3:20000/?it=5")),
new TestCase("https://testweb.com:20000/me/out?it=5",
Arrays.asList("https://192.168.3.1:20000/me/out?it=5", "https://192.168.3.2:20000/me/out?it=5",
"https://192.168.3.3:20000/me/out?it=5")),
};
new TestCase("https://testweb.com",
Arrays.asList("https://192.168.3.1", "https://192.168.3.2", "https://192.168.3.3")),
new TestCase("https://testweb.com/",
Arrays.asList("https://192.168.3.1/", "https://192.168.3.2/", "https://192.168.3.3/")),
new TestCase("https://testweb.com/?",
Arrays.asList("https://192.168.3.1/?", "https://192.168.3.2/?", "https://192.168.3.3/?")),
new TestCase("https://testweb.com/?it=5",
Arrays.asList("https://192.168.3.1/?it=5", "https://192.168.3.2/?it=5", "https://192.168.3.3/?it=5")),
new TestCase("https://testweb.com/me/out?it=5",
Arrays.asList("https://192.168.3.1/me/out?it=5", "https://192.168.3.2/me/out?it=5",
"https://192.168.3.3/me/out?it=5")),
new TestCase("https://testweb.com:20000",
Arrays.asList("https://192.168.3.1:20000", "https://192.168.3.2:20000", "https://192.168.3.3:20000")),
new TestCase("https://testweb.com:20000/",
Arrays.asList("https://192.168.3.1:20000/", "https://192.168.3.2:20000/", "https://192.168.3.3:20000/")),
new TestCase("https://testweb.com:20000/?",
Arrays.asList("https://192.168.3.1:20000/?", "https://192.168.3.2:20000/?",
"https://192.168.3.3:20000/?")),
new TestCase("https://testweb.com:20000/?it=5",
Arrays.asList("https://192.168.3.1:20000/?it=5", "https://192.168.3.2:20000/?it=5",
"https://192.168.3.3:20000/?it=5")),
new TestCase("https://testweb.com:20000/me/out?it=5",
Arrays.asList("https://192.168.3.1:20000/me/out?it=5", "https://192.168.3.2:20000/me/out?it=5",
"https://192.168.3.3:20000/me/out?it=5")),
};

for (TestCase testCase : testCases) {
String uri = testCase._originalUri;
RoundRobinURIProvider uriProvider = new RoundRobinURIProvider(List.of(new URI(uri)), true);
int n = testCase._expectedUris.size();
int previousIndex = -1;
int currentIndex;
for (int i = 0; i < 2 * n; i++) {
String actualUri = uriProvider.next().toString();
currentIndex = testCase._expectedUris.indexOf(actualUri);
Assert.assertTrue(currentIndex != -1);
if (previousIndex != -1) {
Assert.assertEquals((previousIndex + 1) % n, currentIndex);
for (TestCase testCase : testCases) {
String uri = testCase._originalUri;
RoundRobinURIProvider uriProvider = new RoundRobinURIProvider(List.of(new URI(uri)), true);
int n = testCase._expectedUris.size();
int previousIndex = -1;
int currentIndex;
for (int i = 0; i < 2 * n; i++) {
String actualUri = uriProvider.next().toString();
currentIndex = testCase._expectedUris.indexOf(actualUri);
Assert.assertTrue(currentIndex != -1);
if (previousIndex != -1) {
Assert.assertEquals((previousIndex + 1) % n, currentIndex);
}
previousIndex = currentIndex;
}
previousIndex = currentIndex;
}
}
}
}

static class TestCase {
Expand Down

0 comments on commit 69545cb

Please sign in to comment.