2525import static org .hamcrest .Matchers .hasItem ;
2626import static org .junit .Assert .assertEquals ;
2727
28- public class UnixDatagramSocketTest implements StatsDClientErrorHandler {
28+ public class UnixSocketTest implements StatsDClientErrorHandler {
2929 private static File tmpFolder ;
3030 private static NonBlockingStatsDClient client ;
3131 private static NonBlockingStatsDClient clientAggregate ;
@@ -55,36 +55,27 @@ public void start() throws IOException {
5555
5656 server = new UnixDatagramSocketDummyStatsDServer (socketFile .toString ());
5757
58- Callable <SocketAddress > addressLookup = new Callable <SocketAddress >() {
59- @ Override
60- public SocketAddress call () throws Exception {
61- return new UnixSocketAddressWithTransport (new UnixSocketAddress (socketFile .getPath ()), UnixSocketAddressWithTransport .TransportType .UDS_DATAGRAM );
62- }
63- };
64-
6558 client = new NonBlockingStatsDClientBuilder ().prefix ("my.prefix" )
66- .addressLookup (addressLookup )
67- .port (0 )
68- .queueSize (1 )
69- .timeout (1 ) // non-zero timeout to ensure exception triggered if socket buffer full.
70- .connectionTimeout (100 )
71- .socketBufferSize (1024 * 1024 )
72- .enableAggregation (false )
73- .errorHandler (this )
74- .originDetectionEnabled (false )
75- .build ();
59+ .hostname (socketFile .toString ())
60+ .port (0 )
61+ .queueSize (1 )
62+ .timeout (1 ) // non-zero timeout to ensure exception triggered if socket buffer full.
63+ .socketBufferSize (1024 * 1024 )
64+ .enableAggregation (false )
65+ .errorHandler (this )
66+ .originDetectionEnabled (false )
67+ .build ();
7668
7769 clientAggregate = new NonBlockingStatsDClientBuilder ().prefix ("my.prefix" )
78- .addressLookup (addressLookup )
79- .port (0 )
80- .queueSize (1 )
81- .timeout (1 ) // non-zero timeout to ensure exception triggered if socket buffer full.
82- .connectionTimeout (100 )
83- .socketBufferSize (1024 * 1024 )
84- .enableAggregation (false )
85- .errorHandler (this )
86- .originDetectionEnabled (false )
87- .build ();
70+ .hostname (socketFile .toString ())
71+ .port (0 )
72+ .queueSize (1 )
73+ .timeout (1 ) // non-zero timeout to ensure exception triggered if socket buffer full.
74+ .socketBufferSize (1024 * 1024 )
75+ .enableAggregation (false )
76+ .errorHandler (this )
77+ .originDetectionEnabled (false )
78+ .build ();
8879 }
8980
9081 @ After
@@ -127,7 +118,7 @@ public void resist_dsd_restart() throws Exception {
127118 Thread .sleep (10 );
128119 }
129120 // Depending on the state of the client at that point we might get different messages.
130- assertThat (lastException .getMessage (), anyOf ( containsString ("Connection refused" ), containsString ( "Broken pipe" ) ));
121+ assertThat (lastException .getMessage (), containsString ("Connection refused" ));
131122
132123 // Delete the socket file, client should throw an IOException
133124 lastException = new Exception ();
@@ -141,11 +132,11 @@ public void resist_dsd_restart() throws Exception {
141132 assertThat (lastException .getMessage (), containsString ("No such file or directory" ));
142133
143134 // Re-open the server, next send should work OK
144- DummyStatsDServer server2 ;
145- server2 = new UnixDatagramSocketDummyStatsDServer (socketFile .toString ());
146135 lastException = new Exception ();
136+ DummyStatsDServer server2 = new UnixDatagramSocketDummyStatsDServer (socketFile .toString ());
147137
148138 client .gauge ("mycount" , 30 );
139+
149140 server2 .waitForMessage ();
150141 assertThat (server2 .messagesReceived (), hasItem ("my.prefix.mycount:30|g" ));
151142
@@ -164,7 +155,6 @@ public void resist_dsd_timeout() throws Exception {
164155
165156 // Freeze the server to simulate dsd being overwhelmed
166157 server .freeze ();
167-
168158 while (lastException .getMessage () == null ) {
169159 client .gauge ("mycount" , 20 );
170160 Thread .sleep (10 ); // We need to fill the buffer, setting a shorter sleep
0 commit comments