@Override public void run() { try { while (true) { Thread.sleep(windowSizeMs); if (!suppressAutoUpdate) { triggerUpdate(true); triggerUpdate(false); } } } catch (InterruptedException e) { } } }
@Override public void run() { try { while (true) { Thread.sleep(windowSizeMs); if (!suppressAutoUpdate) { triggerUpdate(true); triggerUpdate(false); } } } catch (InterruptedException e) { } } }
@Test public void testSingleThreaded() throws Exception { AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); updater.triggerUpdate(true); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(), new Date(), 150); updater.triggerUpdate(true); assertEquals(150, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(new Date().getTime() - 10000), new Date(), 200); updater.triggerUpdate(true); long currentBytes = AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation); assertTrue( "We expect around (200/10 = 20) bytes written as the gauge value." + "Got " + currentBytes, currentBytes > 18 && currentBytes < 22); updater.close(); }
@Test public void testSingleThreaded() throws Exception { AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); updater.triggerUpdate(true); assertEquals(0, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(), new Date(), 150); updater.triggerUpdate(true); assertEquals(150, AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation)); updater.blockUploaded(new Date(new Date().getTime() - 10000), new Date(), 200); updater.triggerUpdate(true); long currentBytes = AzureMetricsTestUtil.getCurrentBytesWritten(instrumentation); assertTrue( "We expect around (200/10 = 20) bytes written as the gauge value." + "Got " + currentBytes, currentBytes > 18 && currentBytes < 22); updater.close(); }
@Test public void testMultiThreaded() throws Exception { final AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); final BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Runnable() { @Override public void run() { updater.blockDownloaded(new Date(), new Date(), 10); updater.blockDownloaded(new Date(0), new Date(0), 10); } }); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } updater.triggerUpdate(false); assertEquals(10 * threads.length, AzureMetricsTestUtil.getCurrentBytesRead(instrumentation)); updater.close(); } }
@Test public void testMultiThreaded() throws Exception { final AzureFileSystemInstrumentation instrumentation = new AzureFileSystemInstrumentation(new Configuration()); final BandwidthGaugeUpdater updater = new BandwidthGaugeUpdater(instrumentation, 1000, true); Thread[] threads = new Thread[10]; for (int i = 0; i < threads.length; i++) { threads[i] = new Thread(new Runnable() { @Override public void run() { updater.blockDownloaded(new Date(), new Date(), 10); updater.blockDownloaded(new Date(0), new Date(0), 10); } }); } for (Thread t : threads) { t.start(); } for (Thread t : threads) { t.join(); } updater.triggerUpdate(false); assertEquals(10 * threads.length, AzureMetricsTestUtil.getCurrentBytesRead(instrumentation)); updater.close(); } }
getBandwidthGaugeUpdater().triggerUpdate(true); long totalBytesWritten = AzureMetricsTestUtil.getCurrentTotalBytesWritten(getInstrumentation()); assertTrue("The total bytes written " + totalBytesWritten + getBandwidthGaugeUpdater().triggerUpdate(false); long totalBytesRead = AzureMetricsTestUtil.getCurrentTotalBytesRead(getInstrumentation()); assertEquals(FILE_SIZE, totalBytesRead);
getBandwidthGaugeUpdater().triggerUpdate(true); long bytesWritten = AzureMetricsTestUtil.getCurrentBytesWritten(getInstrumentation()); assertTrue("The bytes written in the last second " + bytesWritten + getBandwidthGaugeUpdater().triggerUpdate(false); long totalBytesRead = AzureMetricsTestUtil.getCurrentTotalBytesRead(getInstrumentation()); assertEquals(FILE_SIZE, totalBytesRead);
getBandwidthGaugeUpdater().triggerUpdate(true); long totalBytesWritten = AzureMetricsTestUtil.getCurrentTotalBytesWritten(getInstrumentation()); assertTrue("The total bytes written " + totalBytesWritten + getBandwidthGaugeUpdater().triggerUpdate(false); long totalBytesRead = AzureMetricsTestUtil.getCurrentTotalBytesRead(getInstrumentation()); assertEquals(FILE_SIZE, totalBytesRead);
getBandwidthGaugeUpdater().triggerUpdate(true); long bytesWritten = AzureMetricsTestUtil.getCurrentBytesWritten(getInstrumentation()); assertTrue("The bytes written in the last second " + bytesWritten + getBandwidthGaugeUpdater().triggerUpdate(false); long totalBytesRead = AzureMetricsTestUtil.getCurrentTotalBytesRead(getInstrumentation()); assertEquals(FILE_SIZE, totalBytesRead);