svn merge -c 1586030 from trunk for HADOOP-10473. TestCallQueueManager should interrupt before counting calls.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1586031 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Tsz-wo Sze 2014-04-09 16:50:25 +00:00
parent 2c54fd41ef
commit 29f9ee01ce
2 changed files with 14 additions and 6 deletions

View File

@ -73,6 +73,9 @@ Release 2.4.1 - UNRELEASED
HADOOP-10456. Bug in Configuration.java exposed by Spark HADOOP-10456. Bug in Configuration.java exposed by Spark
(ConcurrentModificationException). (Nishkam Ravi via cnauroth) (ConcurrentModificationException). (Nishkam Ravi via cnauroth)
HADOOP-10473. TestCallQueueManager should interrupt before counting calls.
(szetszwo)
Release 2.4.0 - 2014-04-07 Release 2.4.0 - 2014-04-07
INCOMPATIBLE CHANGES INCOMPATIBLE CHANGES

View File

@ -19,7 +19,6 @@
package org.apache.hadoop.ipc; package org.apache.hadoop.ipc;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
@ -49,7 +48,7 @@ public class TestCallQueueManager {
public volatile int callsAdded = 0; // How many calls we added, accurate unless interrupted public volatile int callsAdded = 0; // How many calls we added, accurate unless interrupted
private final int maxCalls; private final int maxCalls;
private boolean isRunning = true; private volatile boolean isRunning = true;
public Putter(CallQueueManager<FakeCall> aCq, int maxCalls, int tag) { public Putter(CallQueueManager<FakeCall> aCq, int maxCalls, int tag) {
this.maxCalls = maxCalls; this.maxCalls = maxCalls;
@ -201,16 +200,22 @@ public class TestCallQueueManager {
// Ensure no calls were dropped // Ensure no calls were dropped
long totalCallsCreated = 0; long totalCallsCreated = 0;
long totalCallsConsumed = 0;
for (Putter p : producers) { for (Putter p : producers) {
totalCallsCreated += p.callsAdded;
threads.get(p).interrupt(); threads.get(p).interrupt();
} }
for (Putter p : producers) {
threads.get(p).join();
totalCallsCreated += p.callsAdded;
}
long totalCallsConsumed = 0;
for (Taker t : consumers) { for (Taker t : consumers) {
totalCallsConsumed += t.callsTaken;
threads.get(t).interrupt(); threads.get(t).interrupt();
} }
for (Taker t : consumers) {
threads.get(t).join();
totalCallsConsumed += t.callsTaken;
}
assertEquals(totalCallsConsumed, totalCallsCreated); assertEquals(totalCallsConsumed, totalCallsCreated);
} }