Search in sources :

Example 1 with AzureException

use of org.apache.hadoop.fs.azure.AzureException in project hadoop by apache.

the class TestAzureFileSystemInstrumentation method testClientErrorMetrics.

@Test
public void testClientErrorMetrics() throws Exception {
    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 {
            outputStream.write(new byte[FILE_SIZE]);
            outputStream.close();
            assertTrue("Should've thrown", false);
        } catch (AzureException ex) {
            assertTrue("Unexpected exception: " + ex, ex.getMessage().contains("lease"));
        }
        assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS));
        assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS));
    } finally {
        if (leaseID != null) {
            testAccount.releaseLease(leaseID, fileName);
        }
        IOUtils.closeStream(outputStream);
    }
}
Also used : Path(org.apache.hadoop.fs.Path) AzureException(org.apache.hadoop.fs.azure.AzureException) OutputStream(java.io.OutputStream) Test(org.junit.Test)

Aggregations

OutputStream (java.io.OutputStream)1 Path (org.apache.hadoop.fs.Path)1 AzureException (org.apache.hadoop.fs.azure.AzureException)1 Test (org.junit.Test)1