Checkstyle clean up about 200 trivial violation
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / concurrent / ThreadPoolExecutorTest.java
index 4d280536a1c865b4896d764b235f69d442e86cd2..44f90f9884d927df4a20fb939a4ecb4e000334c1 100644 (file)
@@ -10,6 +10,7 @@ package org.opendaylight.yangtools.util.concurrent;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.fail;
 
+import com.google.common.base.Stopwatch;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
@@ -19,12 +20,9 @@ import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicLong;
 import java.util.concurrent.atomic.AtomicReference;
-
 import org.junit.After;
 import org.junit.Test;
 
-import com.google.common.base.Stopwatch;
-
 /**
  * Tests various ThreadPoolExecutor implementations.
  *
@@ -36,7 +34,7 @@ public class ThreadPoolExecutorTest {
 
     @After
     public void tearDown() {
-        if( executor != null ) {
+        if (executor != null) {
             executor.shutdownNow();
         }
     }
@@ -49,12 +47,12 @@ public class ThreadPoolExecutorTest {
                 100000, "TestPool", 0 );
     }
 
-    @Test(expected=RejectedExecutionException.class)
+    @Test(expected = RejectedExecutionException.class)
     public void testFastThreadPoolRejectingTask() throws Exception {
 
         executor = SpecialExecutors.newBoundedFastThreadPool( 1, 1, "TestPool" );
 
-        for( int i = 0; i < 5; i++ ) {
+        for (int i = 0; i < 5; i++) {
             executor.execute( new Task( null, null, null, null,
                     TimeUnit.MICROSECONDS.convert( 5, TimeUnit.SECONDS ) ) );
         }
@@ -77,12 +75,12 @@ public class ThreadPoolExecutorTest {
                 100000, "TestPool", 0 );
     }
 
-    @Test(expected=RejectedExecutionException.class)
+    @Test(expected = RejectedExecutionException.class)
     public void testCachedThreadRejectingTask() throws Exception {
 
         ExecutorService executor = SpecialExecutors.newBoundedCachedThreadPool( 1, 1, "TestPool" );
 
-        for( int i = 0; i < 5; i++ ) {
+        for (int i = 0; i < 5; i++) {
             executor.execute( new Task( null, null, null, null,
                     TimeUnit.MICROSECONDS.convert( 5, TimeUnit.SECONDS ) ) );
         }
@@ -101,21 +99,19 @@ public class ThreadPoolExecutorTest {
 
         this.executor = executor;
 
-        System.out.println( "\nTesting " + executor.getClass().getSimpleName() + " with " +
-                numTasksToRun + " tasks." );
+        System.out.println("\nTesting " + executor.getClass().getSimpleName() + " with " + numTasksToRun + " tasks.");
 
         final CountDownLatch tasksRunLatch = new CountDownLatch( numTasksToRun );
         final ConcurrentMap<Thread, AtomicLong> taskCountPerThread = new ConcurrentHashMap<>();
         final AtomicReference<AssertionError> threadError = new AtomicReference<>();
 
-        Stopwatch stopWatch = new Stopwatch();
-        stopWatch.start();
+        Stopwatch stopWatch = Stopwatch.createStarted();
 
         new Thread() {
             @Override
             public void run() {
-                for( int i = 0; i < numTasksToRun; i++ ) {
-//                    if(i%100 == 0) {
+                for (int i = 0; i < numTasksToRun; i++) {
+//                    if (i%100 == 0) {
 //                        Uninterruptibles.sleepUninterruptibly( 20, TimeUnit.MICROSECONDS );
 //                    }
 
@@ -129,17 +125,16 @@ public class ThreadPoolExecutorTest {
 
         stopWatch.stop();
 
-        if( !done ) {
-            fail( (numTasksToRun - tasksRunLatch.getCount()) + " tasks out of " +
-                   numTasksToRun + " executed" );
+        if (!done) {
+            fail((numTasksToRun - tasksRunLatch.getCount()) + " tasks out of " + numTasksToRun + " executed");
         }
 
-        if( threadError.get() != null ) {
+        if (threadError.get() != null) {
             throw threadError.get();
         }
 
         System.out.println( taskCountPerThread.size() + " threads used:" );
-        for( Map.Entry<Thread, AtomicLong> e : taskCountPerThread.entrySet() ) {
+        for (Map.Entry<Thread, AtomicLong> e : taskCountPerThread.entrySet()) {
             System.out.println( "  " + e.getKey().getName() + " - " + e.getValue() + " tasks" );
         }
 
@@ -179,24 +174,25 @@ public class ThreadPoolExecutorTest {
         public void run() {
             try {
                 try {
-                    if( delay > 0 ) {
+                    if (delay > 0) {
                         TimeUnit.MICROSECONDS.sleep( delay );
-                    } else if( blockLatch != null ) {
+                    } else if (blockLatch != null) {
                         blockLatch.await();
                     }
-                } catch( InterruptedException e ) {}
+                } catch (InterruptedException e) {
+                }
 
-                if( expThreadPrefix != null ) {
+                if (expThreadPrefix != null) {
                     assertEquals( "Thread name starts with " + expThreadPrefix, true,
                             Thread.currentThread().getName().startsWith( expThreadPrefix ) );
                 }
 
-                if( taskCountPerThread != null ) {
+                if (taskCountPerThread != null) {
                     AtomicLong count = taskCountPerThread.get( Thread.currentThread() );
-                    if( count == null ) {
+                    if (count == null) {
                         count = new AtomicLong( 0 );
                         AtomicLong prev = taskCountPerThread.putIfAbsent( Thread.currentThread(), count );
-                        if( prev != null ) {
+                        if (prev != null) {
                             count = prev;
                         }
                     }
@@ -204,12 +200,12 @@ public class ThreadPoolExecutorTest {
                     count.incrementAndGet();
                 }
 
-            } catch( AssertionError e ) {
-                if( threadError != null ) {
+            } catch (AssertionError e) {
+                if (threadError != null) {
                     threadError.set( e );
                 }
             } finally {
-                if( tasksRunLatch != null ) {
+                if (tasksRunLatch != null) {
                     tasksRunLatch.countDown();
                 }
             }