HDFS-10463. TestRollingFileSystemSinkWithHdfs needs some cleanup. (Daniel Templeton via kasha)
This commit is contained in:
parent
f4b9bcd87c
commit
55c3e2de3d
|
@ -221,8 +221,12 @@ public class RollingFileSystemSinkTestBase {
|
|||
mm1.testMetric2.incr(2);
|
||||
|
||||
ms.publishMetricsNow(); // publish the metrics
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
|
||||
return readLogFile(path, then, count);
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.hadoop.fs.FileStatus;
|
|||
import org.apache.hadoop.fs.FileSystem;
|
||||
import org.apache.hadoop.fs.Path;
|
||||
import org.apache.hadoop.hdfs.MiniDFSCluster;
|
||||
import org.apache.hadoop.metrics2.MetricsException;
|
||||
import org.apache.hadoop.metrics2.MetricsSystem;
|
||||
import org.apache.hadoop.metrics2.sink.RollingFileSystemSinkTestBase.MyMetrics1;
|
||||
import org.junit.After;
|
||||
|
@ -108,7 +109,7 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
public void testSilentAppend() throws Exception {
|
||||
String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp";
|
||||
|
||||
assertExtraContents(doAppendTest(path, false, true, 1));
|
||||
assertExtraContents(doAppendTest(path, true, true, 1));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -158,9 +159,12 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
assertTrue("No exception was generated while writing metrics "
|
||||
+ "even though HDFS was unavailable", MockSink.errored);
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that closing a file in HDFS fails when HDFS is unavailable.
|
||||
|
@ -180,13 +184,17 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
shutdownHdfs();
|
||||
MockSink.errored = false;
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
|
||||
assertTrue("No exception was generated while stopping sink "
|
||||
+ "even though HDFS was unavailable", MockSink.errored);
|
||||
|
||||
} catch (MetricsException ex) {
|
||||
// Expected
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that writing to HDFS fails silently when HDFS is unavailable.
|
||||
|
@ -211,9 +219,12 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
+ "while HDFS was unavailable, even though the sink is set to "
|
||||
+ "ignore errors", MockSink.errored);
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that closing a file in HDFS silently fails when HDFS is unavailable.
|
||||
|
@ -233,14 +244,16 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
shutdownHdfs();
|
||||
MockSink.errored = false;
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
|
||||
assertFalse("An exception was generated stopping sink "
|
||||
+ "while HDFS was unavailable, even though the sink is set to "
|
||||
+ "ignore errors", MockSink.errored);
|
||||
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This test specifically checks whether the flusher thread is automatically
|
||||
|
@ -268,6 +281,7 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
|
||||
int count = 0;
|
||||
|
||||
try {
|
||||
// Sleep until the flusher has run. This should never actually need to
|
||||
// sleep, but the sleep is here to make sure this test isn't flakey.
|
||||
while (!RollingFileSystemSink.hasFlushed) {
|
||||
|
@ -289,8 +303,15 @@ public class TestRollingFileSystemSinkWithHdfs
|
|||
assertTrue("The flusher thread didn't flush the log contents. Expected "
|
||||
+ "at least 236 bytes in the log file, but got " + status.getLen(),
|
||||
status.getLen() >= 236);
|
||||
} finally {
|
||||
RollingFileSystemSink.forceFlush = false;
|
||||
|
||||
try {
|
||||
ms.stop();
|
||||
} finally {
|
||||
ms.shutdown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue