From 67089875f0ea2a47cca0c237fccf239bf6fe2d53 Mon Sep 17 00:00:00 2001 From: Masatake Iwasaki Date: Wed, 22 Jun 2016 23:38:20 +0900 Subject: [PATCH] HADOOP-12588. addendum patch to fix intermittent failure of TestGangliaMetrics. (iwasakims) --- .../hadoop/metrics2/impl/TestGangliaMetrics.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java index c386e36261..c19d238d48 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/metrics2/impl/TestGangliaMetrics.java @@ -29,7 +29,6 @@ import java.util.HashSet; import java.util.List; import java.util.Set; -import java.util.concurrent.CopyOnWriteArrayList; import org.apache.commons.io.Charsets; import org.apache.commons.logging.Log; @@ -99,7 +98,9 @@ public void testTagsForPrefix() throws Exception { } @Test public void testGangliaMetrics2() throws Exception { - ConfigBuilder cb = new ConfigBuilder().add("default.period", 10) + // Setting long interval to avoid periodic publishing. + // We manually publish metrics by MeticsSystem#publishMetricsNow here. + ConfigBuilder cb = new ConfigBuilder().add("*.period", 120) .add("test.sink.gsink30.context", "test") // filter out only "test" .add("test.sink.gsink31.context", "test") // filter out only "test" .save(TestMetricsConfig.getTestFilename("hadoop-metrics2-test")); @@ -196,14 +197,14 @@ private class MockDatagramSocket extends DatagramSocket { * @throws SocketException */ public MockDatagramSocket() throws SocketException { - capture = new CopyOnWriteArrayList(); + capture = new ArrayList(); } /* (non-Javadoc) * @see java.net.DatagramSocket#send(java.net.DatagramPacket) */ @Override - public void send(DatagramPacket p) throws IOException { + public synchronized void send(DatagramPacket p) throws IOException { // capture the byte arrays byte[] bytes = new byte[p.getLength()]; System.arraycopy(p.getData(), p.getOffset(), bytes, 0, p.getLength()); @@ -213,7 +214,7 @@ public void send(DatagramPacket p) throws IOException { /** * @return the captured byte arrays */ - List getCapturedSend() { + synchronized List getCapturedSend() { return capture; } }