8888import java .util .concurrent .Executors ;
8989import java .util .concurrent .Future ;
9090import java .util .concurrent .ThreadLocalRandom ;
91- import java .util .concurrent .ThreadPoolExecutor ;
9291import java .util .concurrent .TimeUnit ;
9392import java .util .concurrent .atomic .AtomicBoolean ;
9493import java .util .concurrent .atomic .AtomicInteger ;
@@ -951,9 +950,9 @@ public void run() {
951950 * We use a mock SocketFactory so that we can control when the input and
952951 * output streams are frozen.
953952 */
954- @ Test
953+ @ Test ( timeout = 30000 )
955954 public void testSlowConnection () throws Exception {
956- final int NUM_THREADS = 5 ;
955+ final int numThreads = 5 ;
957956 SocketFactory mockFactory = Mockito .mock (SocketFactory .class );
958957 Socket mockSocket = Mockito .mock (Socket .class );
959958 Mockito .when (mockFactory .createSocket ()).thenReturn (mockSocket );
@@ -997,17 +996,17 @@ public int read() throws IOException {
997996 // The connection isn't actually made until the first call.
998997 client .ping (null , newEmptyRequest ());
999998 mockOutputStream .waitForFlush (1 );
1000- final long header_and_first = mockOutputStream .bytesWritten ;
999+ final long headerAndFirst = mockOutputStream .bytesWritten ;
10011000 client .ping (null , newEmptyRequest ());
10021001 mockOutputStream .waitForFlush (2 );
1003- final long second = mockOutputStream .bytesWritten - header_and_first ;
1002+ final long second = mockOutputStream .bytesWritten - headerAndFirst ;
10041003 // pause the writer thread
10051004 mockOutputStream .pause ();
10061005 // create a set of threads to create calls that will back up
10071006 ExecutorService pool = Executors .newCachedThreadPool ();
1008- Future <Void >[] futures = new Future [NUM_THREADS ];
1007+ Future <Void >[] futures = new Future [numThreads ];
10091008 final AtomicInteger doneThreads = new AtomicInteger (0 );
1010- for (int thread = 0 ; thread < NUM_THREADS ; ++thread ) {
1009+ for (int thread = 0 ; thread < numThreads ; ++thread ) {
10111010 final TestRpcService finalClient = client ;
10121011 futures [thread ] = pool .submit (new Callable <Void >() {
10131012 @ Override
@@ -1021,7 +1020,7 @@ public Void call() throws Exception {
10211020 // wait until one of the threads has started writing
10221021 mockOutputStream .waitForWriters ();
10231022 // interrupt all the threads
1024- for (int thread =0 ; thread < NUM_THREADS ; ++thread ) {
1023+ for (int thread =0 ; thread < numThreads ; ++thread ) {
10251024 futures [thread ].cancel (true );
10261025 }
10271026 mockOutputStream .resume ();
@@ -1030,7 +1029,7 @@ public Void call() throws Exception {
10301029 // All the threads should have been interrupted
10311030 assertEquals (0 , doneThreads .get ());
10321031 // make sure that only one additional rpc request was sent
1033- assertEquals (header_and_first + second * 2 , mockOutputStream .bytesWritten );
1032+ assertEquals (headerAndFirst + second * 2 , mockOutputStream .bytesWritten );
10341033 } finally {
10351034 Client .setAsynchronousMode (wasAsync );
10361035 if (client != null ) {
@@ -1040,8 +1039,8 @@ public Void call() throws Exception {
10401039 }
10411040
10421041 private static final class MockOutputStream extends OutputStream {
1043- long bytesWritten = 0 ;
1044- AtomicInteger flushCount = new AtomicInteger (0 );
1042+ private long bytesWritten = 0 ;
1043+ private AtomicInteger flushCount = new AtomicInteger (0 );
10451044 private ReentrantLock lock = new ReentrantLock (true );
10461045
10471046 @ Override
0 commit comments