29
29
import java .util .HashSet ;
30
30
import java .util .List ;
31
31
import java .util .Set ;
32
+ import java .util .concurrent .CopyOnWriteArrayList ;
32
33
34
+ import org .apache .commons .io .Charsets ;
33
35
import org .apache .commons .logging .Log ;
34
36
import org .apache .commons .logging .LogFactory ;
35
37
import org .apache .hadoop .metrics2 .AbstractMetric ;
@@ -145,7 +147,7 @@ public void testTagsForPrefix() throws Exception {
145
147
private void checkMetrics (List <byte []> bytearrlist , int expectedCount ) {
146
148
boolean [] foundMetrics = new boolean [expectedMetrics .length ];
147
149
for (byte [] bytes : bytearrlist ) {
148
- String binaryStr = new String (bytes );
150
+ String binaryStr = new String (bytes , Charsets . UTF_8 );
149
151
for (int index = 0 ; index < expectedMetrics .length ; index ++) {
150
152
if (binaryStr .indexOf (expectedMetrics [index ]) >= 0 ) {
151
153
foundMetrics [index ] = true ;
@@ -188,13 +190,13 @@ private static class TestSource {
188
190
* hence all the captured byte arrays were pointing to one instance.
189
191
*/
190
192
private class MockDatagramSocket extends DatagramSocket {
191
- private ArrayList <byte []> capture ;
193
+ private List <byte []> capture ;
192
194
193
195
/**
194
196
* @throws SocketException
195
197
*/
196
198
public MockDatagramSocket () throws SocketException {
197
- capture = new ArrayList <byte []>();
199
+ capture = new CopyOnWriteArrayList <byte []>();
198
200
}
199
201
200
202
/* (non-Javadoc)
@@ -211,7 +213,7 @@ public void send(DatagramPacket p) throws IOException {
211
213
/**
212
214
* @return the captured byte arrays
213
215
*/
214
- ArrayList <byte []> getCapturedSend () {
216
+ List <byte []> getCapturedSend () {
215
217
return capture ;
216
218
}
217
219
}
0 commit comments