@Test public void testClientErrorMetrics() throws Exception { String directoryName = "metricsTestDirectory_ClientError"; Path directoryPath = new Path("/" + directoryName); assertTrue(fs.mkdirs(directoryPath)); String leaseID = testAccount.acquireShortLease(directoryName); try { try { fs.delete(directoryPath, true); 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 { testAccount.releaseLease(leaseID, directoryName); } }
/** * Read "size" bytes of data and verify that what was read and what was written * are the same. */ private void readRandomDataAndVerify(int size) throws AzureException, IOException { byte[] b = new byte[size]; FSDataInputStream stream = fs.open(PATH); int bytesRead = stream.read(b); stream.close(); assertEquals(bytesRead, size); // compare the data read to the data written assertTrue(comparePrefix(randomData, b, size)); }
@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); } }
/** * Get a self-renewing lease on the specified file. */ public SelfRenewingLease acquireLease(Path path) throws AzureException { String fullKey = pathToKey(makeAbsolute(path)); return getStore().acquireLease(fullKey); }
/** * Get a self-renewing Azure blob lease on the source folder zero-byte file. */ private SelfRenewingLease leaseSourceFolder(String srcKey) throws AzureException { return store.acquireLease(srcKey); }