diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index efb73f44dd0..dd709474088 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -1320,6 +1320,10 @@ Release 2.8.0 - UNRELEASED HADOOP-12542. TestDNS fails on Windows after HADOOP-12437. (cnauroth) + HADOOP-12540. TestAzureFileSystemInstrumentation#testClientErrorMetrics + fails intermittently due to assumption that a lease error will be thrown. + (Gaurav Kanade via cnauroth) + OPTIMIZATIONS HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() diff --git a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/TestAzureFileSystemInstrumentation.java b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/TestAzureFileSystemInstrumentation.java index 896ec1bbc2a..0c9126cf0a0 100644 --- a/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/TestAzureFileSystemInstrumentation.java +++ b/hadoop-tools/hadoop-azure/src/test/java/org/apache/hadoop/fs/azure/metrics/TestAzureFileSystemInstrumentation.java @@ -48,6 +48,7 @@ import org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount; import org.apache.hadoop.fs.azure.AzureException; import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore; import org.apache.hadoop.fs.azure.NativeAzureFileSystem; +import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsTag; import org.hamcrest.BaseMatcher; @@ -405,22 +406,30 @@ public class TestAzureFileSystemInstrumentation { @Test public void testClientErrorMetrics() throws Exception { - String directoryName = "metricsTestDirectory_ClientError"; - Path directoryPath = new Path("/" + directoryName); - assertTrue(fs.mkdirs(directoryPath)); - String leaseID = testAccount.acquireShortLease(directoryName); + String fileName = "metricsTestFile_ClientError"; + Path filePath = new Path("/"+fileName); + final int FILE_SIZE = 100; + OutputStream outputStream = null; + String leaseID = null; try { + // Create a file + outputStream = fs.create(filePath); + leaseID = testAccount.acquireShortLease(fileName); try { - fs.delete(directoryPath, true); - assertTrue("Should've thrown.", false); + outputStream.write(new byte[FILE_SIZE]); + outputStream.close(); + assertTrue("Should've thrown", false); } catch (AzureException ex) { assertTrue("Unexpected exception: " + ex, - ex.getMessage().contains("lease")); + ex.getMessage().contains("lease")); } assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS)); assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS)); } finally { - testAccount.releaseLease(leaseID, directoryName); + if(leaseID != null){ + testAccount.releaseLease(leaseID, fileName); + } + IOUtils.closeStream(outputStream); } }