/** * Gets the current value of the wasb_raw_bytes_downloaded counter. */ public static long getCurrentTotalBytesRead( AzureFileSystemInstrumentation instrumentation) { return getLongCounterValue(instrumentation, WASB_RAW_BYTES_DOWNLOADED); }
/** * Gets the current value of the wasb_raw_bytes_downloaded counter. */ public static long getCurrentTotalBytesRead( AzureFileSystemInstrumentation instrumentation) { return getLongCounterValue(instrumentation, WASB_RAW_BYTES_DOWNLOADED); }
/** * Gets the current value of the wasb_raw_bytes_uploaded counter. */ public static long getCurrentTotalBytesWritten( AzureFileSystemInstrumentation instrumentation) { return getLongCounterValue(instrumentation, WASB_RAW_BYTES_UPLOADED); }
/** * Gets the current value of the wasb_raw_bytes_uploaded counter. */ public static long getCurrentTotalBytesWritten( AzureFileSystemInstrumentation instrumentation) { return getLongCounterValue(instrumentation, WASB_RAW_BYTES_UPLOADED); }
private void assertNoErrors() { assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS)); assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS)); }
private void assertNoErrors() { assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_CLIENT_ERRORS)); assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_SERVER_ERRORS)); }
@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); } }
@Test public void testMetricsOnMkdirList() throws Exception { long base = getBaseWebResponses(); // Create a directory assertTrue(fs.mkdirs(new Path("a"))); // At the time of writing, it takes 1 request to create the actual directory, // plus 2 requests per level to check that there's no blob with that name and // 1 request per level above to create it if it doesn't exist. // So for the path above (/user/<name>/a), it takes 2 requests each to check // there's no blob called /user, no blob called /user/<name> and no blob // called /user/<name>/a, and then 3 request for the creation of the three // levels, and then 2 requests for checking/stamping the version of AS, // totaling 11. // Also, there's the initial 1 request for container check so total is 12. base = assertWebResponsesInRange(base, 1, 12); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_DIRECTORIES_CREATED)); // List the root contents assertEquals(1, fs.listStatus(new Path("/")).length); base = assertWebResponsesEquals(base, 1); assertNoErrors(); }
@Test public void testMetricsOnFileRename() throws Exception { long base = getBaseWebResponses(); Path originalPath = new Path("/metricsTest_RenameStart"); Path destinationPath = new Path("/metricsTest_RenameFinal"); // Create an empty file assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED)); assertTrue(fs.createNewFile(originalPath)); logOpResponseCount("Creating an empty file", base); base = assertWebResponsesInRange(base, 2, 20); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED)); // Rename the file assertTrue(fs.rename(originalPath, destinationPath)); // Varies: at the time of writing this code it takes 7 requests/responses. logOpResponseCount("Renaming a file", base); base = assertWebResponsesInRange(base, 2, 15); assertNoErrors(); }
@Test public void testMetricsOnFileRename() throws Exception { long base = getBaseWebResponses(); Path originalPath = new Path("/metricsTest_RenameStart"); Path destinationPath = new Path("/metricsTest_RenameFinal"); // Create an empty file assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED)); assertTrue(getFileSystem().createNewFile(originalPath)); logOpResponseCount("Creating an empty file", base); base = assertWebResponsesInRange(base, 2, 20); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_CREATED)); // Rename the file assertTrue( ((FileSystem) getFileSystem()).rename(originalPath, destinationPath)); // Varies: at the time of writing this code it takes 7 requests/responses. logOpResponseCount("Renaming a file", base); base = assertWebResponsesInRange(base, 2, 15); assertNoErrors(); }
@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 = getFileSystem().create(filePath); leaseID = getTestAccount().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){ getTestAccount().releaseLease(leaseID, fileName); } IOUtils.closeStream(outputStream); } }
@Test public void testMetricsOnFileExistsDelete() throws Exception { long base = getBaseWebResponses(); Path filePath = new Path("/metricsTest_delete"); // Check existence assertFalse(fs.exists(filePath)); // At the time of writing this code it takes 2 requests/responses to // check existence, which seems excessive, plus initial request for // container check. logOpResponseCount("Checking file existence for non-existent file", base); base = assertWebResponsesInRange(base, 1, 3); // Create an empty file assertTrue(fs.createNewFile(filePath)); base = getCurrentWebResponses(); // Check existence again assertTrue(fs.exists(filePath)); logOpResponseCount("Checking file existence for existent file", base); base = assertWebResponsesInRange(base, 1, 2); // Delete the file assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_DELETED)); assertTrue(fs.delete(filePath, false)); // At the time of writing this code it takes 4 requests/responses to // delete, which seems excessive. Check for range 1-4 for now. logOpResponseCount("Deleting a file", base); base = assertWebResponsesInRange(base, 1, 4); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_DELETED)); assertNoErrors(); }
@Test public void testMetricsOnMkdirList() throws Exception { long base = getBaseWebResponses(); // Create a directory assertTrue(fs.mkdirs(new Path("a"))); // At the time of writing // getAncestor uses 2 calls for each folder level /user/<name>/a // plus 1 call made by checkContainer // mkdir checks the hierarchy with 2 calls per level // mkdirs calls storeEmptyDir to create the empty folder, which makes 5 calls // For a total of 7 + 6 + 5 = 18 web responses base = assertWebResponsesInRange(base, 1, 18); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_DIRECTORIES_CREATED)); // List the root contents assertEquals(1, getFileSystem().listStatus(new Path("/")).length); base = assertWebResponsesEquals(base, 1); assertNoErrors(); }
@Test public void testMetricsOnFileExistsDelete() throws Exception { long base = getBaseWebResponses(); Path filePath = new Path("/metricsTest_delete"); // Check existence assertFalse(getFileSystem().exists(filePath)); // At the time of writing this code it takes 2 requests/responses to // check existence, which seems excessive, plus initial request for // container check, plus 2 ancestor checks only in the secure case. logOpResponseCount("Checking file existence for non-existent file", base); base = assertWebResponsesInRange(base, 1, 5); // Create an empty file assertTrue(getFileSystem().createNewFile(filePath)); base = getCurrentWebResponses(); // Check existence again assertTrue(getFileSystem().exists(filePath)); logOpResponseCount("Checking file existence for existent file", base); base = assertWebResponsesInRange(base, 1, 4); // Delete the file assertEquals(0, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_DELETED)); assertTrue(getFileSystem().delete(filePath, false)); // At the time of writing this code it takes 4 requests/responses to // delete, which seems excessive. Check for range 1-4 for now. logOpResponseCount("Deleting a file", base); base = assertWebResponsesInRange(base, 1, 4); assertEquals(1, AzureMetricsTestUtil.getLongCounterValue(getInstrumentation(), WASB_FILES_DELETED)); assertNoErrors(); }