HDFS-10463. TestRollingFileSystemSinkWithHdfs needs some cleanup. (Daniel Templeton via kasha)

This commit is contained in:
Karthik Kambatla 2016-05-26 14:39:07 -07:00
parent 72773f8ea8
commit b4c8729cf9
2 changed files with 56 additions and 35 deletions

View File

@ -221,8 +221,12 @@ public class RollingFileSystemSinkTestBase {
mm1.testMetric2.incr(2); mm1.testMetric2.incr(2);
ms.publishMetricsNow(); // publish the metrics ms.publishMetricsNow(); // publish the metrics
try {
ms.stop(); ms.stop();
} finally {
ms.shutdown(); ms.shutdown();
}
return readLogFile(path, then, count); return readLogFile(path, then, count);
} }

View File

@ -109,7 +109,7 @@ public class TestRollingFileSystemSinkWithHdfs
public void testSilentAppend() throws Exception { public void testSilentAppend() throws Exception {
String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp"; String path = "hdfs://" + cluster.getNameNode().getHostAndPort() + "/tmp";
assertExtraContents(doAppendTest(path, false, true, 1)); assertExtraContents(doAppendTest(path, true, true, 1));
} }
/** /**
@ -159,9 +159,12 @@ public class TestRollingFileSystemSinkWithHdfs
assertTrue("No exception was generated while writing metrics " assertTrue("No exception was generated while writing metrics "
+ "even though HDFS was unavailable", MockSink.errored); + "even though HDFS was unavailable", MockSink.errored);
try {
ms.stop(); ms.stop();
} finally {
ms.shutdown(); ms.shutdown();
} }
}
/** /**
* Test that closing a file in HDFS fails when HDFS is unavailable. * Test that closing a file in HDFS fails when HDFS is unavailable.
@ -183,14 +186,15 @@ public class TestRollingFileSystemSinkWithHdfs
try { try {
ms.stop(); ms.stop();
fail("No exception was generated while stopping sink " fail("No exception was generated while stopping sink "
+ "even though HDFS was unavailable"); + "even though HDFS was unavailable");
} catch (MetricsException ex) { } catch (MetricsException ex) {
// Expected // Expected
} } finally {
ms.shutdown(); ms.shutdown();
} }
}
/** /**
* Test that writing to HDFS fails silently when HDFS is unavailable. * Test that writing to HDFS fails silently when HDFS is unavailable.
@ -215,9 +219,12 @@ public class TestRollingFileSystemSinkWithHdfs
+ "while HDFS was unavailable, even though the sink is set to " + "while HDFS was unavailable, even though the sink is set to "
+ "ignore errors", MockSink.errored); + "ignore errors", MockSink.errored);
try {
ms.stop(); ms.stop();
} finally {
ms.shutdown(); ms.shutdown();
} }
}
/** /**
* Test that closing a file in HDFS silently fails when HDFS is unavailable. * Test that closing a file in HDFS silently fails when HDFS is unavailable.
@ -237,14 +244,16 @@ public class TestRollingFileSystemSinkWithHdfs
shutdownHdfs(); shutdownHdfs();
MockSink.errored = false; MockSink.errored = false;
try {
ms.stop(); ms.stop();
assertFalse("An exception was generated stopping sink " assertFalse("An exception was generated stopping sink "
+ "while HDFS was unavailable, even though the sink is set to " + "while HDFS was unavailable, even though the sink is set to "
+ "ignore errors", MockSink.errored); + "ignore errors", MockSink.errored);
} finally {
ms.shutdown(); ms.shutdown();
} }
}
/** /**
* This test specifically checks whether the flusher thread is automatically * This test specifically checks whether the flusher thread is automatically
@ -272,6 +281,7 @@ public class TestRollingFileSystemSinkWithHdfs
int count = 0; int count = 0;
try {
// Sleep until the flusher has run. This should never actually need to // 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. // sleep, but the sleep is here to make sure this test isn't flakey.
while (!RollingFileSystemSink.hasFlushed) { while (!RollingFileSystemSink.hasFlushed) {
@ -293,8 +303,15 @@ public class TestRollingFileSystemSinkWithHdfs
assertTrue("The flusher thread didn't flush the log contents. Expected " assertTrue("The flusher thread didn't flush the log contents. Expected "
+ "at least 236 bytes in the log file, but got " + status.getLen(), + "at least 236 bytes in the log file, but got " + status.getLen(),
status.getLen() >= 236); status.getLen() >= 236);
} finally {
RollingFileSystemSink.forceFlush = false;
try {
ms.stop(); ms.stop();
} finally {
ms.shutdown();
}
}
} }
/** /**