@Test public void testMetricsOnDirRename() throws Exception { long base = getBaseWebResponses(); Path originalDirName = new Path("/metricsTestDirectory_RenameStart"); Path innerFileName = new Path(originalDirName, "innerFile"); Path destDirName = new Path("/metricsTestDirectory_RenameFinal"); // Create an empty directory assertTrue(fs.mkdirs(originalDirName)); base = getCurrentWebResponses(); // Create an inner file assertTrue(fs.createNewFile(innerFileName)); base = getCurrentWebResponses(); // Rename the directory assertTrue(fs.rename(originalDirName, destDirName)); // At the time of writing this code it takes 11 requests/responses // to rename the directory with one file. Check for range 1-20 for now. logOpResponseCount("Renaming a directory", base); base = assertWebResponsesInRange(base, 1, 20); assertNoErrors(); }
/** * Gets (and asserts) the value of the wasb_web_responses counter just * after the creation of the file system object. */ private long getBaseWebResponses() { // The number of requests should start at 0 return assertWebResponsesEquals(0, 0); }
/** * Gets the metrics for the file system object. * @return The metrics record. */ private MetricsRecordBuilder getMyMetrics() { return getMetrics(getInstrumentation()); }
@Test public void testMetricsOnFileCreateRead() throws Exception { long base = getBaseWebResponses(); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(getInstrumentation())); getBandwidthGaugeUpdater().suppressAutoUpdate(); outputStream.write(nonZeroByteArray(FILE_SIZE)); outputStream.close(); long uploadDurationMs = new Date().getTime() - start.getTime(); logOpResponseCount("Creating a 1K file", base); base = assertWebResponsesInRange(base, 2, 15); getBandwidthGaugeUpdater().triggerUpdate(true); long bytesWritten = AzureMetricsTestUtil.getCurrentBytesWritten(getInstrumentation()); assertTrue("The bytes written in the last second " + bytesWritten + " is pretty far from the expected range of around " + FILE_SIZE + " bytes plus a little overhead.", bytesWritten > (FILE_SIZE / 2) && bytesWritten < (FILE_SIZE * 2)); long totalBytesWritten = AzureMetricsTestUtil.getCurrentTotalBytesWritten(getInstrumentation()); assertTrue("The total bytes written " + totalBytesWritten + " is pretty far from the expected range of around " + FILE_SIZE + " bytes plus a little overhead.", totalBytesWritten >= FILE_SIZE && totalBytesWritten < (FILE_SIZE * 2)); long uploadRate = AzureMetricsTestUtil.getLongGaugeValue(getInstrumentation(), WASB_UPLOAD_RATE); System.out.println("Upload rate: " + uploadRate + " bytes/second."); long expectedRate = (FILE_SIZE * 1000L) / uploadDurationMs; " end-to-end time instead of just block upload time.",
@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 testMetricsOnBigFileCreateRead() throws Exception { long base = getBaseWebResponses(); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(getInstrumentation())); getBandwidthGaugeUpdater().suppressAutoUpdate(); logOpResponseCount("Creating a 100 MB file", base); base = assertWebResponsesInRange(base, 20, 50); getBandwidthGaugeUpdater().triggerUpdate(true); long totalBytesWritten = AzureMetricsTestUtil.getCurrentTotalBytesWritten(getInstrumentation()); assertTrue("The total bytes written " + totalBytesWritten + " is pretty far from the expected range of around " + FILE_SIZE + " bytes plus a little overhead.", totalBytesWritten >= FILE_SIZE && totalBytesWritten < (FILE_SIZE * 2)); long uploadRate = AzureMetricsTestUtil.getLongGaugeValue(getInstrumentation(), WASB_UPLOAD_RATE); System.out.println("Upload rate: " + uploadRate + " bytes/second."); long uploadLatency = AzureMetricsTestUtil.getLongGaugeValue(getInstrumentation(), WASB_UPLOAD_LATENCY); System.out.println("Upload latency: " + uploadLatency); logOpResponseCount("Reading a 100 MB file", base); base = assertWebResponsesInRange(base, 20, 40); getBandwidthGaugeUpdater().triggerUpdate(false); long totalBytesRead = AzureMetricsTestUtil.getCurrentTotalBytesRead(getInstrumentation()); assertEquals(FILE_SIZE, totalBytesRead); long downloadRate = AzureMetricsTestUtil.getLongGaugeValue(getInstrumentation(), WASB_DOWNLOAD_RATE); System.out.println("Download rate: " + downloadRate + " bytes/second."); long downloadLatency = AzureMetricsTestUtil.getLongGaugeValue(getInstrumentation(),
private void logOpResponseCount(String opName, long base) { System.out.println(opName + " took " + (getCurrentWebResponses() - base) + " web responses to complete."); }
/** * Checks that the wasb_web_responses counter is at the given value. * @param base The base value (before the operation of interest). * @param expected The expected value for the operation of interest. * @return The new base value now. */ private long assertWebResponsesEquals(long base, long expected) { assertCounter(WASB_WEB_RESPONSES, base + expected, getMyMetrics()); return base + expected; }
/** * Checks that the wasb_web_responses counter is in the given range. * @param base The base value (before the operation of interest). * @param inclusiveLowerLimit The lower limit for what it should increase by. * @param inclusiveUpperLimit The upper limit for what it should increase by. * @return The new base value now. */ private long assertWebResponsesInRange(long base, long inclusiveLowerLimit, long inclusiveUpperLimit) { long currentResponses = getCurrentWebResponses(); long justOperation = currentResponses - base; assertTrue(String.format( "Web responses expected in range [%d, %d], but was %d.", inclusiveLowerLimit, inclusiveUpperLimit, justOperation), justOperation >= inclusiveLowerLimit && justOperation <= inclusiveUpperLimit); return currentResponses; }
@Test public void testMetricTags() throws Exception { String accountName = testAccount.getRealAccount().getBlobEndpoint() .getAuthority(); String containerName = testAccount.getRealContainer().getName(); MetricsRecordBuilder myMetrics = getMyMetrics(); verify(myMetrics).add(argThat( new TagMatcher("accountName", accountName) )); verify(myMetrics).add(argThat( new TagMatcher("containerName", containerName) )); verify(myMetrics).add(argThat( new TagMatcher("Context", "azureFileSystem") )); verify(myMetrics).add(argThat( new TagExistsMatcher("wasbFileSystemId") )); }
@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(); }
/** * Gets the current value of the wasb_web_responses counter. */ private long getCurrentWebResponses() { return AzureMetricsTestUtil.getCurrentWebResponses(getInstrumentation()); }
@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(); }
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); } }