|
23 | 23 | import org.elasticsearch.client.Node.Roles;
|
24 | 24 |
|
25 | 25 | import java.util.Arrays;
|
| 26 | +import java.util.HashMap; |
26 | 27 | import java.util.HashSet;
|
| 28 | +import java.util.List; |
| 29 | +import java.util.Map; |
27 | 30 |
|
28 | 31 | import static java.util.Collections.singleton;
|
| 32 | +import static java.util.Collections.singletonList; |
| 33 | +import static java.util.Collections.singletonMap; |
29 | 34 | import static org.junit.Assert.assertEquals;
|
30 | 35 | import static org.junit.Assert.assertFalse;
|
31 | 36 | import static org.junit.Assert.assertTrue;
|
32 | 37 |
|
33 | 38 | public class NodeTests extends RestClientTestCase {
|
34 | 39 | public void testToString() {
|
| 40 | + Map<String, List<String>> attributes = new HashMap<>(); |
| 41 | + attributes.put("foo", singletonList("bar")); |
| 42 | + attributes.put("baz", Arrays.asList("bort", "zoom")); |
35 | 43 | assertEquals("[host=http://1]", new Node(new HttpHost("1")).toString());
|
| 44 | + assertEquals("[host=http://1, attributes={foo=[bar], baz=[bort, zoom]}]", |
| 45 | + new Node(new HttpHost("1"), null, null, null, null, attributes).toString()); |
36 | 46 | assertEquals("[host=http://1, roles=mdi]", new Node(new HttpHost("1"),
|
37 |
| - null, null, null, new Roles(true, true, true)).toString()); |
| 47 | + null, null, null, new Roles(true, true, true), null).toString()); |
38 | 48 | assertEquals("[host=http://1, version=ver]", new Node(new HttpHost("1"),
|
39 |
| - null, null, "ver", null).toString()); |
| 49 | + null, null, "ver", null, null).toString()); |
40 | 50 | assertEquals("[host=http://1, name=nam]", new Node(new HttpHost("1"),
|
41 |
| - null, "nam", null, null).toString()); |
| 51 | + null, "nam", null, null, null).toString()); |
42 | 52 | assertEquals("[host=http://1, bound=[http://1, http://2]]", new Node(new HttpHost("1"),
|
43 |
| - new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))), null, null, null).toString()); |
44 |
| - assertEquals("[host=http://1, bound=[http://1, http://2], name=nam, version=ver, roles=m]", |
| 53 | + new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))), null, null, null, null).toString()); |
| 54 | + assertEquals( |
| 55 | + "[host=http://1, bound=[http://1, http://2], name=nam, version=ver, roles=m, attributes={foo=[bar], baz=[bort, zoom]}]", |
45 | 56 | new Node(new HttpHost("1"), new HashSet<>(Arrays.asList(new HttpHost("1"), new HttpHost("2"))),
|
46 |
| - "nam", "ver", new Roles(true, false, false)).toString()); |
| 57 | + "nam", "ver", new Roles(true, false, false), attributes).toString()); |
47 | 58 |
|
48 | 59 | }
|
49 | 60 |
|
50 | 61 | public void testEqualsAndHashCode() {
|
51 | 62 | HttpHost host = new HttpHost(randomAsciiAlphanumOfLength(5));
|
52 | 63 | Node node = new Node(host,
|
53 |
| - randomBoolean() ? null : singleton(host), |
54 |
| - randomBoolean() ? null : randomAsciiAlphanumOfLength(5), |
55 |
| - randomBoolean() ? null : randomAsciiAlphanumOfLength(5), |
56 |
| - randomBoolean() ? null : new Roles(true, true, true)); |
| 64 | + randomBoolean() ? null : singleton(host), |
| 65 | + randomBoolean() ? null : randomAsciiAlphanumOfLength(5), |
| 66 | + randomBoolean() ? null : randomAsciiAlphanumOfLength(5), |
| 67 | + randomBoolean() ? null : new Roles(true, true, true), |
| 68 | + randomBoolean() ? null : singletonMap("foo", singletonList("bar"))); |
57 | 69 | assertFalse(node.equals(null));
|
58 | 70 | assertTrue(node.equals(node));
|
59 | 71 | assertEquals(node.hashCode(), node.hashCode());
|
60 |
| - Node copy = new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(), node.getRoles()); |
| 72 | + Node copy = new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(), |
| 73 | + node.getRoles(), node.getAttributes()); |
61 | 74 | assertTrue(node.equals(copy));
|
62 | 75 | assertEquals(node.hashCode(), copy.hashCode());
|
63 | 76 | assertFalse(node.equals(new Node(new HttpHost(host.toHostString() + "changed"), node.getBoundHosts(),
|
64 |
| - node.getName(), node.getVersion(), node.getRoles()))); |
| 77 | + node.getName(), node.getVersion(), node.getRoles(), node.getAttributes()))); |
65 | 78 | assertFalse(node.equals(new Node(host, new HashSet<>(Arrays.asList(host, new HttpHost(host.toHostString() + "changed"))),
|
66 |
| - node.getName(), node.getVersion(), node.getRoles()))); |
67 |
| - assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName() + "changed", node.getVersion(), node.getRoles()))); |
68 |
| - assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), node.getVersion() + "changed", node.getRoles()))); |
69 |
| - assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), node.getVersion(), new Roles(false, false, false)))); |
| 79 | + node.getName(), node.getVersion(), node.getRoles(), node.getAttributes()))); |
| 80 | + assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName() + "changed", |
| 81 | + node.getVersion(), node.getRoles(), node.getAttributes()))); |
| 82 | + assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), |
| 83 | + node.getVersion() + "changed", node.getRoles(), node.getAttributes()))); |
| 84 | + assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), |
| 85 | + node.getVersion(), new Roles(false, false, false), node.getAttributes()))); |
| 86 | + assertFalse(node.equals(new Node(host, node.getBoundHosts(), node.getName(), |
| 87 | + node.getVersion(), node.getRoles(), singletonMap("bort", singletonList("bing"))))); |
70 | 88 | }
|
71 | 89 | }
|
0 commit comments