HADOOP-12540. TestAzureFileSystemInstrumentation#testClientErrorMetrics fails intermittently due to assumption that a lease error will be thrown. Contributed by Gaurav Kanade.

This commit is contained in:
cnauroth 2015-11-04 10:19:04 -08:00
parent e2a5441b06
commit 0fb1867fd6
2 changed files with 21 additions and 8 deletions

View File

@ -1320,6 +1320,10 @@ Release 2.8.0 - UNRELEASED
HADOOP-12542. TestDNS fails on Windows after HADOOP-12437. (cnauroth) 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 OPTIMIZATIONS
HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString() HADOOP-12051. ProtobufRpcEngine.invoke() should use Exception.toString()

View File

@ -48,6 +48,7 @@ import org.apache.hadoop.fs.azure.AzureBlobStorageTestAccount;
import org.apache.hadoop.fs.azure.AzureException; import org.apache.hadoop.fs.azure.AzureException;
import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore; import org.apache.hadoop.fs.azure.AzureNativeFileSystemStore;
import org.apache.hadoop.fs.azure.NativeAzureFileSystem; import org.apache.hadoop.fs.azure.NativeAzureFileSystem;
import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.metrics2.MetricsRecordBuilder; import org.apache.hadoop.metrics2.MetricsRecordBuilder;
import org.apache.hadoop.metrics2.MetricsTag; import org.apache.hadoop.metrics2.MetricsTag;
import org.hamcrest.BaseMatcher; import org.hamcrest.BaseMatcher;
@ -405,22 +406,30 @@ public class TestAzureFileSystemInstrumentation {
@Test @Test
public void testClientErrorMetrics() throws Exception { public void testClientErrorMetrics() throws Exception {
String directoryName = "metricsTestDirectory_ClientError"; String fileName = "metricsTestFile_ClientError";
Path directoryPath = new Path("/" + directoryName); Path filePath = new Path("/"+fileName);
assertTrue(fs.mkdirs(directoryPath)); final int FILE_SIZE = 100;
String leaseID = testAccount.acquireShortLease(directoryName); OutputStream outputStream = null;
String leaseID = null;
try { try {
// Create a file
outputStream = fs.create(filePath);
leaseID = testAccount.acquireShortLease(fileName);
try { try {
fs.delete(directoryPath, true); outputStream.write(new byte[FILE_SIZE]);
assertTrue("Should've thrown.", false); outputStream.close();
assertTrue("Should've thrown", false);
} catch (AzureException ex) { } catch (AzureException ex) {
assertTrue("Unexpected exception: " + ex, assertTrue("Unexpected exception: " + ex,
ex.getMessage().contains("lease")); ex.getMessage().contains("lease"));
} }
assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS)); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS));
assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS)); assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS));
} finally { } finally {
testAccount.releaseLease(leaseID, directoryName); if(leaseID != null){
testAccount.releaseLease(leaseID, fileName);
}
IOUtils.closeStream(outputStream);
} }
} }