HADOOP-10715. Remove public GraphiteSink#setWriter()

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1605647 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Ravi Prakash 2014-06-26 01:53:43 +00:00
parent 8317fd5de6
commit c03c90471e
3 changed files with 26 additions and 29 deletions

View File

@ -288,6 +288,8 @@ Release 2.5.0 - UNRELEASED
HADOOP-10479. Fix new findbugs warnings in hadoop-minikdc.
(Swarnim Kulkarni via wheat9)
HADOOP-10715. Remove public GraphiteSink#setWriter (Babak Behzad via raviprak)
Release 2.4.1 - 2014-06-23
INCOMPATIBLE CHANGES

View File

@ -50,10 +50,6 @@ public class GraphiteSink implements MetricsSink, Closeable {
private String metricsPrefix = null;
private Socket socket = null;
public void setWriter(Writer writer) {
this.writer = writer;
}
@Override
public void init(SubsetConfiguration conf) {
// Get Graphite host configurations.
@ -68,7 +64,7 @@ public class GraphiteSink implements MetricsSink, Closeable {
try {
// Open an connection to Graphite server.
socket = new Socket(serverHost, serverPort);
setWriter(new OutputStreamWriter(socket.getOutputStream()));
writer = new OutputStreamWriter(socket.getOutputStream());
} catch (Exception e) {
throw new MetricsException("Error creating connection, "
+ serverHost + ":" + serverPort, e);

View File

@ -28,15 +28,16 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static org.mockito.Mockito.*;
import org.apache.hadoop.metrics2.AbstractMetric;
import org.apache.hadoop.metrics2.MetricsException;
import org.apache.hadoop.metrics2.MetricsRecord;
import org.apache.hadoop.metrics2.MetricsTag;
import org.apache.hadoop.metrics2.sink.GraphiteSink;
import org.junit.Test;
import static org.mockito.Mockito.*;
import org.mockito.ArgumentCaptor;
import org.mockito.internal.util.reflection.Whitebox;
public class TestGraphiteMetrics {
private AbstractMetric makeMetric(String name, Number value) {
@ -57,14 +58,13 @@ public class TestGraphiteMetrics {
metrics.add(makeMetric("foo2", 2.25));
MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
OutputStreamWriter writer = mock(OutputStreamWriter.class);
OutputStreamWriter mockWriter = mock(OutputStreamWriter.class);
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
sink.setWriter(writer);
Whitebox.setInternalState(sink, "writer", mockWriter);
sink.putMetrics(record);
try {
verify(writer).write(argument.capture());
verify(mockWriter).write(argument.capture());
} catch (IOException e) {
e.printStackTrace();
}
@ -89,14 +89,13 @@ public class TestGraphiteMetrics {
metrics.add(makeMetric("foo2", 2));
MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);
OutputStreamWriter writer = mock(OutputStreamWriter.class);
OutputStreamWriter mockWriter = mock(OutputStreamWriter.class);
ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
sink.setWriter(writer);
Whitebox.setInternalState(sink, "writer", mockWriter);
sink.putMetrics(record);
try {
verify(writer).write(argument.capture());
verify(mockWriter).write(argument.capture());
} catch (IOException e) {
e.printStackTrace();
}
@ -122,26 +121,26 @@ public class TestGraphiteMetrics {
OutputStreamWriter writer = mock(OutputStreamWriter.class);
sink.setWriter(writer);
Whitebox.setInternalState(sink, "writer", writer);
sink.close();
sink.putMetrics(record);
}
@Test
public void testClose(){
GraphiteSink sink = new GraphiteSink();
Writer mockWriter = mock(Writer.class);
sink.setWriter(mockWriter);
try {
sink.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
GraphiteSink sink = new GraphiteSink();
Writer mockWriter = mock(Writer.class);
Whitebox.setInternalState(sink, "writer", mockWriter);
try {
sink.close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
verify(mockWriter).close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
try {
verify(mockWriter).close();
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}