ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adorosz...@apache.org
Subject [ambari] 02/02: AMBARI-22805. Blueprints do not handle some failures properly - fix timeout edge case
Date Wed, 24 Jan 2018 15:37:30 GMT
This is an automated email from the ASF dual-hosted git repository.

adoroszlai pushed a commit to branch branch-2.6
in repository https://gitbox.apache.org/repos/asf/ambari.git

commit 51add1288529c2b28badf5737f50c40deb07e3a6
Author: Doroszlai, Attila <adoroszlai@apache.org>
AuthorDate: Tue Jan 23 23:00:11 2018 +0100

    AMBARI-22805. Blueprints do not handle some failures properly - fix timeout edge case
---
 .../org/apache/ambari/server/topology/AsyncCallableService.java   | 4 ++--
 .../apache/ambari/server/topology/AsyncCallableServiceTest.java   | 8 ++++++--
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/ambari-server/src/main/java/org/apache/ambari/server/topology/AsyncCallableService.java
b/ambari-server/src/main/java/org/apache/ambari/server/topology/AsyncCallableService.java
index 1d8b322..8b24c65 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/topology/AsyncCallableService.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/topology/AsyncCallableService.java
@@ -100,10 +100,10 @@ public class AsyncCallableService<T> implements Callable<T>
{
           LOG.info(String.format("Task %s exception during execution", taskName), cause);
         }
         lastError = cause;
-        timeLeft = timeout - (System.currentTimeMillis() - startTime);
+        timeLeft = timeout - (System.currentTimeMillis() - startTime) - retryDelay;
       }
 
-      if (timeLeft < retryDelay) {
+      if (timeLeft <= 0) {
         attemptToCancel(future);
         LOG.warn("Task {} timeout exceeded, no more retries", taskName);
         onError.apply(lastError);
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/topology/AsyncCallableServiceTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/topology/AsyncCallableServiceTest.java
index bc8ef2b..a4586b8 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/topology/AsyncCallableServiceTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/topology/AsyncCallableServiceTest.java
@@ -18,8 +18,9 @@
 
 package org.apache.ambari.server.topology;
 
-import static org.easymock.EasyMock.anyLong;
 import static org.easymock.EasyMock.anyObject;
+import static org.easymock.EasyMock.captureLong;
+import static org.easymock.EasyMock.eq;
 import static org.easymock.EasyMock.expect;
 
 import java.util.concurrent.Callable;
@@ -29,6 +30,7 @@ import java.util.concurrent.ScheduledFuture;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.TimeoutException;
 
+import org.easymock.Capture;
 import org.easymock.EasyMockRule;
 import org.easymock.EasyMockSupport;
 import org.easymock.Mock;
@@ -90,7 +92,8 @@ public class AsyncCallableServiceTest extends EasyMockSupport {
     Exception timeoutException = new TimeoutException("Timeout during second attempt");
     expect(futureMock.get(TIMEOUT, TimeUnit.MILLISECONDS)).andThrow(computationException);
     expect(executorServiceMock.schedule(taskMock, RETRY_DELAY, TimeUnit.MILLISECONDS)).andReturn(futureMock);
-    expect(futureMock.get(anyLong(), anyObject(TimeUnit.class))).andThrow(timeoutException);
+    Capture<Long> timeoutCapture = Capture.newInstance();
+    expect(futureMock.get(captureLong(timeoutCapture), eq(TimeUnit.MILLISECONDS))).andThrow(timeoutException);
     expect(futureMock.isDone()).andReturn(Boolean.FALSE);
     expect(futureMock.cancel(true)).andReturn(Boolean.TRUE);
     expect(executorServiceMock.submit(taskMock)).andReturn(futureMock);
@@ -104,6 +107,7 @@ public class AsyncCallableServiceTest extends EasyMockSupport {
 
     // THEN
     verifyAll();
+    Assert.assertTrue(timeoutCapture.getValue() <= TIMEOUT - RETRY_DELAY);
     Assert.assertNull("No result expected in case of timeout", serviceResult);
   }
 

-- 
To stop receiving notification emails like this one, please contact
adoroszlai@apache.org.

Mime
View raw message