@Override public void close() { if (bandwidthGaugeUpdater != null) { bandwidthGaugeUpdater.close(); bandwidthGaugeUpdater = null; } }
@Override public void close() { if(bandwidthGaugeUpdater != null) { bandwidthGaugeUpdater.close(); bandwidthGaugeUpdater = null; } }
@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(); } }
@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(); }