diff --git hadoop-project/pom.xml hadoop-project/pom.xml
index ef0d1cdedb6..71b70c79e01 100644
--- hadoop-project/pom.xml
+++ hadoop-project/pom.xml
@@ -985,7 +985,7 @@
org.mockito
mockito-all
- 1.8.5
+ 1.10.19
org.mock-server
diff --git hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java
index 140483a265f..25620f9ad08 100644
--- hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java
+++ hadoop-yarn-project/hadoop-yarn/hadoop-yarn-server/hadoop-yarn-server-resourcemanager/src/test/java/org/apache/hadoop/yarn/server/resourcemanager/TestRMEmbeddedElector.java
@@ -22,18 +22,22 @@
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ha.ClientBaseWithFixes;
import org.apache.hadoop.ha.ServiceFailedException;
+import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.yarn.conf.YarnConfiguration;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.invocation.Invocation;
import java.io.IOException;
+import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
+
import static org.junit.Assert.fail;
import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.atLeast;
-import static org.mockito.Mockito.atMost;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.mockingDetails;
import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -103,7 +107,7 @@ public void testDeadlockShutdownBecomeActive() throws InterruptedException {
*/
@Test
public void testCallbackSynchronization()
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
testCallbackSynchronization(SyncTestType.ACTIVE);
testCallbackSynchronization(SyncTestType.STANDBY);
testCallbackSynchronization(SyncTestType.NEUTRAL);
@@ -117,9 +121,10 @@ public void testCallbackSynchronization()
* @param type the type of test to run
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronization(SyncTestType type)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
AdminService as = mock(AdminService.class);
RMContext rc = mock(RMContext.class);
ResourceManager rm = mock(ResourceManager.class);
@@ -165,15 +170,23 @@ private void testCallbackSynchronization(SyncTestType type)
* @param ees the embedded elector service
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronizationActive(AdminService as,
ActiveStandbyElectorBasedElectorService ees)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
ees.becomeActive();
- Thread.sleep(100);
-
- verify(as).transitionToActive(any());
+ GenericTestUtils.waitFor(() -> {
+ int count = 0;
+ for (Invocation invocation : mockingDetails(as).getInvocations()) {
+ if (invocation.getMethod().getName().equals("transitionToActive")) {
+ count++;
+ }
+ }
+ return count >= 1;
+ }, 500, 10 * 1000);
+ verify(as, times(1)).transitionToActive(any());
verify(as, never()).transitionToStandby(any());
}
@@ -185,16 +198,23 @@ private void testCallbackSynchronizationActive(AdminService as,
* @param ees the embedded elector service
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronizationStandby(AdminService as,
ActiveStandbyElectorBasedElectorService ees)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
ees.becomeStandby();
- Thread.sleep(100);
-
- verify(as, atLeast(1)).transitionToStandby(any());
- verify(as, atMost(1)).transitionToStandby(any());
+ GenericTestUtils.waitFor(() -> {
+ int count = 0;
+ for (Invocation invocation : mockingDetails(as).getInvocations()) {
+ if (invocation.getMethod().getName().equals("transitionToStandby")) {
+ count++;
+ }
+ }
+ return count >= 1;
+ }, 500, 10 * 1000);
+ verify(as, times(1)).transitionToStandby(any());
}
/**
@@ -204,16 +224,23 @@ private void testCallbackSynchronizationStandby(AdminService as,
* @param ees the embedded elector service
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronizationNeutral(AdminService as,
ActiveStandbyElectorBasedElectorService ees)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
ees.enterNeutralMode();
- Thread.sleep(100);
-
- verify(as, atLeast(1)).transitionToStandby(any());
- verify(as, atMost(1)).transitionToStandby(any());
+ GenericTestUtils.waitFor(() -> {
+ int count = 0;
+ for (Invocation invocation : mockingDetails(as).getInvocations()) {
+ if (invocation.getMethod().getName().equals("transitionToStandby")) {
+ count++;
+ }
+ }
+ return count >= 1;
+ }, 500, 10 * 1000);
+ verify(as, times(1)).transitionToStandby(any());
}
/**
@@ -224,10 +251,11 @@ private void testCallbackSynchronizationNeutral(AdminService as,
* @param ees the embedded elector service
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronizationTimingActive(AdminService as,
ActiveStandbyElectorBasedElectorService ees)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
synchronized (ees.zkDisconnectLock) {
// Sleep while holding the lock so that the timer thread can't do
// anything when it runs. Sleep until we're pretty sure the timer thread
@@ -243,7 +271,16 @@ private void testCallbackSynchronizationTimingActive(AdminService as,
// going to do, hopefully nothing.
Thread.sleep(50);
- verify(as).transitionToActive(any());
+ GenericTestUtils.waitFor(() -> {
+ int count = 0;
+ for (Invocation invocation : mockingDetails(as).getInvocations()) {
+ if (invocation.getMethod().getName().equals("transitionToActive")) {
+ count++;
+ }
+ }
+ return count >= 1;
+ }, 500, 10 * 1000);
+ verify(as, times(1)).transitionToActive(any());
verify(as, never()).transitionToStandby(any());
}
@@ -255,10 +292,11 @@ private void testCallbackSynchronizationTimingActive(AdminService as,
* @param ees the embedded elector service
* @throws IOException if there's an issue transitioning
* @throws InterruptedException if interrupted
+ * @throws TimeoutException if waitFor timeout reached
*/
private void testCallbackSynchronizationTimingStandby(AdminService as,
ActiveStandbyElectorBasedElectorService ees)
- throws IOException, InterruptedException {
+ throws IOException, InterruptedException, TimeoutException {
synchronized (ees.zkDisconnectLock) {
// Sleep while holding the lock so that the timer thread can't do
// anything when it runs. Sleep until we're pretty sure the timer thread
@@ -274,8 +312,16 @@ private void testCallbackSynchronizationTimingStandby(AdminService as,
// going to do, hopefully nothing.
Thread.sleep(50);
- verify(as, atLeast(1)).transitionToStandby(any());
- verify(as, atMost(1)).transitionToStandby(any());
+ GenericTestUtils.waitFor(() -> {
+ int count = 0;
+ for (Invocation invocation : mockingDetails(as).getInvocations()) {
+ if (invocation.getMethod().getName().equals("transitionToStandby")) {
+ count++;
+ }
+ }
+ return count >= 1;
+ }, 500, 10 * 1000);
+ verify(as, times(1)).transitionToStandby(any());
}
private class MockRMWithElector extends MockRM {