You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2013/07/18 09:49:39 UTC

git commit: [SSHD-219] DefaultSshFuture.awaitUninterruptibly() uses incorrect timeout

Updated Branches:
  refs/heads/master c71b0bfd2 -> a0cb511cc


[SSHD-219] DefaultSshFuture.awaitUninterruptibly() uses incorrect timeout

Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/a0cb511c
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/a0cb511c
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/a0cb511c

Branch: refs/heads/master
Commit: a0cb511ccbffa8dd3f79f44aa3cdef984e28cb1c
Parents: c71b0bf
Author: Guillaume Nodet <gn...@apache.org>
Authored: Thu Jul 18 09:49:28 2013 +0200
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Thu Jul 18 09:49:28 2013 +0200

----------------------------------------------------------------------
 .../sshd/common/future/DefaultSshFuture.java    |  3 +-
 .../apache/sshd/common/future/FutureTest.java   | 48 ++++++++++++++++++++
 2 files changed, 50 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a0cb511c/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultSshFuture.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultSshFuture.java b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultSshFuture.java
index 41f385f..a7985c3 100644
--- a/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultSshFuture.java
+++ b/sshd-core/src/main/java/org/apache/sshd/common/future/DefaultSshFuture.java
@@ -134,7 +134,8 @@ public class DefaultSshFuture<T extends SshFuture> implements SshFuture<T> {
      * when it's not allowed.
      */
     private boolean await0(long timeoutMillis, boolean interruptable) throws InterruptedException {
-        long endTime = System.currentTimeMillis() + timeoutMillis;
+        long curTime = System.currentTimeMillis();
+        long endTime = Long.MAX_VALUE - timeoutMillis < curTime ? Long.MAX_VALUE : curTime + timeoutMillis;
 
         synchronized (lock) {
             if (ready) {

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/a0cb511c/sshd-core/src/test/java/org/apache/sshd/common/future/FutureTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/future/FutureTest.java b/sshd-core/src/test/java/org/apache/sshd/common/future/FutureTest.java
new file mode 100644
index 0000000..efbe749
--- /dev/null
+++ b/sshd-core/src/test/java/org/apache/sshd/common/future/FutureTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.sshd.common.future;
+
+import org.junit.Test;
+
+import static junit.framework.Assert.assertNotNull;
+
+/**
+ */
+public class FutureTest {
+
+    @Test
+    public void testAwaitUnint() {
+
+        final DefaultSshFuture future = new DefaultSshFuture(null);
+        new Thread() {
+            @Override
+            public void run() {
+                try {
+                    Thread.sleep(10000);
+                } catch (InterruptedException e) {
+                    throw new RuntimeException(e);
+                }
+                future.setValue(new Object());
+            }
+        }.start();
+
+        future.awaitUninterruptibly();
+        assertNotNull(future.getValue());
+    }
+}