|
6 | 6 | * to you under the Apache License, Version 2.0 (the |
7 | 7 | * "License"); you may not use this file except in compliance |
8 | 8 | * with the License. You may obtain a copy of the License at |
9 | | - * |
10 | | - * http://www.apache.org/licenses/LICENSE-2.0 |
11 | | - * |
| 9 | + * <p> |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * <p> |
12 | 12 | * Unless required by applicable law or agreed to in writing, software |
13 | 13 | * distributed under the License is distributed on an "AS IS" BASIS, |
14 | 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|
20 | 20 |
|
21 | 21 | import org.apache.commons.configuration2.SubsetConfiguration; |
22 | 22 | import org.apache.hadoop.metrics2.impl.ConfigBuilder; |
| 23 | + |
23 | 24 | import org.junit.Test; |
24 | 25 |
|
25 | 26 | import java.net.DatagramSocket; |
|
30 | 31 | import static org.junit.Assert.assertTrue; |
31 | 32 |
|
32 | 33 | public class TestGangliaSink { |
33 | | - @Test |
34 | | - public void testShouldCreateDatagramSocketByDefault() throws Exception { |
35 | | - SubsetConfiguration conf = new ConfigBuilder() |
36 | | - .subset("test.sink.ganglia"); |
| 34 | + @Test |
| 35 | + public void testShouldCreateDatagramSocketByDefault() throws Exception { |
| 36 | + SubsetConfiguration conf = new ConfigBuilder().subset("test.sink.ganglia"); |
| 37 | + |
| 38 | + GangliaSink30 gangliaSink = new GangliaSink30(); |
| 39 | + gangliaSink.init(conf); |
| 40 | + DatagramSocket socket = gangliaSink.getDatagramSocket(); |
| 41 | + assertFalse("Did not create DatagramSocket", |
| 42 | + socket == null || socket instanceof MulticastSocket); |
| 43 | + } |
37 | 44 |
|
38 | | - GangliaSink30 gangliaSink = new GangliaSink30(); |
39 | | - gangliaSink.init(conf); |
40 | | - DatagramSocket socket = gangliaSink.getDatagramSocket(); |
41 | | - assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); |
42 | | - } |
| 45 | + @Test |
| 46 | + public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { |
| 47 | + SubsetConfiguration conf = |
| 48 | + new ConfigBuilder().add("test.sink.ganglia.multicast", false).subset("test.sink.ganglia"); |
| 49 | + GangliaSink30 gangliaSink = new GangliaSink30(); |
| 50 | + gangliaSink.init(conf); |
| 51 | + DatagramSocket socket = gangliaSink.getDatagramSocket(); |
| 52 | + assertFalse("Did not create DatagramSocket", |
| 53 | + socket == null || socket instanceof MulticastSocket); |
| 54 | + } |
43 | 55 |
|
44 | | - @Test |
45 | | - public void testShouldCreateDatagramSocketIfMulticastIsDisabled() throws Exception { |
46 | | - SubsetConfiguration conf = new ConfigBuilder() |
47 | | - .add("test.sink.ganglia.multicast", false) |
48 | | - .subset("test.sink.ganglia"); |
49 | | - GangliaSink30 gangliaSink = new GangliaSink30(); |
50 | | - gangliaSink.init(conf); |
51 | | - DatagramSocket socket = gangliaSink.getDatagramSocket(); |
52 | | - assertFalse("Did not create DatagramSocket", socket == null || socket instanceof MulticastSocket); |
53 | | - } |
| 56 | + @Test |
| 57 | + public void testShouldCreateMulticastSocket() throws Exception { |
| 58 | + SubsetConfiguration conf = |
| 59 | + new ConfigBuilder().add("test.sink.ganglia.multicast", true).subset("test.sink.ganglia"); |
| 60 | + GangliaSink30 gangliaSink = new GangliaSink30(); |
| 61 | + gangliaSink.init(conf); |
| 62 | + DatagramSocket socket = gangliaSink.getDatagramSocket(); |
| 63 | + assertTrue("Did not create MulticastSocket", |
| 64 | + socket != null && socket instanceof MulticastSocket); |
| 65 | + int ttl = ((MulticastSocket) socket).getTimeToLive(); |
| 66 | + assertEquals("Did not set default TTL", 1, ttl); |
| 67 | + } |
54 | 68 |
|
55 | | - @Test |
56 | | - public void testShouldCreateMulticastSocket() throws Exception { |
57 | | - SubsetConfiguration conf = new ConfigBuilder() |
58 | | - .add("test.sink.ganglia.multicast", true) |
59 | | - .subset("test.sink.ganglia"); |
60 | | - GangliaSink30 gangliaSink = new GangliaSink30(); |
61 | | - gangliaSink.init(conf); |
62 | | - DatagramSocket socket = gangliaSink.getDatagramSocket(); |
63 | | - assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket); |
64 | | - int ttl = ((MulticastSocket) socket).getTimeToLive(); |
65 | | - assertEquals("Did not set default TTL", 1, ttl); |
66 | | - } |
| 69 | + @Test |
| 70 | + public void testShouldSetMulticastSocketTtl() throws Exception { |
| 71 | + SubsetConfiguration conf = new ConfigBuilder().add("test.sink.ganglia.multicast", true) |
| 72 | + .add("test.sink.ganglia.multicast.ttl", 3).subset("test.sink.ganglia"); |
| 73 | + GangliaSink30 gangliaSink = new GangliaSink30(); |
| 74 | + gangliaSink.init(conf); |
| 75 | + DatagramSocket socket = gangliaSink.getDatagramSocket(); |
| 76 | + assertTrue("Did not create MulticastSocket", |
| 77 | + socket != null && socket instanceof MulticastSocket); |
| 78 | + int ttl = ((MulticastSocket) socket).getTimeToLive(); |
| 79 | + assertEquals("Did not set TTL", 3, ttl); |
| 80 | + } |
67 | 81 |
|
68 | | - @Test |
69 | | - public void testShouldSetMulticastSocketTtl() throws Exception { |
70 | | - SubsetConfiguration conf = new ConfigBuilder() |
71 | | - .add("test.sink.ganglia.multicast", true) |
72 | | - .add("test.sink.ganglia.multicast.ttl", 3) |
73 | | - .subset("test.sink.ganglia"); |
74 | | - GangliaSink30 gangliaSink = new GangliaSink30(); |
75 | | - gangliaSink.init(conf); |
76 | | - DatagramSocket socket = gangliaSink.getDatagramSocket(); |
77 | | - assertTrue("Did not create MulticastSocket", socket != null && socket instanceof MulticastSocket); |
78 | | - int ttl = ((MulticastSocket) socket).getTimeToLive(); |
79 | | - assertEquals("Did not set TTL", 3, ttl); |
80 | | - } |
| 82 | + @Test |
| 83 | + public void testMultipleMetricsServers() { |
| 84 | + SubsetConfiguration conf = |
| 85 | + new ConfigBuilder().add("test.sink.ganglia.servers", "server1,server2") |
| 86 | + .subset("test.sink.ganglia"); |
| 87 | + GangliaSink30 gangliaSink = new GangliaSink30(); |
| 88 | + gangliaSink.init(conf); |
| 89 | + assertEquals(2, gangliaSink.getMetricsServers().size()); |
| 90 | + } |
81 | 91 | } |
0 commit comments