blob: c799ee5eacafde49d44a0eff3dd8d3a21a887471 (
plain) (
blame)
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
|
package com.yahoo.vespa.hosted.node.admin.task.util.network;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author smorgrav
*/
public class IPAddressesMock implements IPAddresses {
Map<String, List<InetAddress>> otherAddresses = new HashMap<>();
IPAddressesMock addAddress(String hostname, String ip) {
List<InetAddress> addresses = otherAddresses.getOrDefault(hostname, new ArrayList<>());
try {
addresses.add(InetAddress.getByName(ip));
} catch (UnknownHostException e) {
e.printStackTrace();
}
otherAddresses.put(hostname, addresses);
return this;
}
@Override
public InetAddress[] getAddresses(String hostname) {
List<InetAddress> addresses = otherAddresses.get(hostname);
return addresses.toArray(new InetAddress[addresses.size()]);
}
}
|