Repository: cassandra Updated Branches: refs/heads/trunk 958e13d16 -> 6da5fb56c
Make AsyncOneResponse use the correct timeout Patch by Dinesh Joshi; reviewed by marcuse for CASSANDRA-14509 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6da5fb56 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6da5fb56 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6da5fb56 Branch: refs/heads/trunk Commit: 6da5fb56c8e0777843e88359a45a461a9f9eb639 Parents: 958e13d Author: Dinesh A. Joshi <dinesh.jo...@apple.com> Authored: Fri Jun 8 16:38:00 2018 -0700 Committer: Marcus Eriksson <marc...@apache.org> Committed: Mon Jun 11 08:55:55 2018 -0700 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../apache/cassandra/net/AsyncOneResponse.java | 2 +- .../cassandra/net/AsyncOneResponseTest.java | 63 ++++++++++++++++++++ 3 files changed, 65 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/6da5fb56/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index 27c9561..6819711 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 4.0 + * Make AsyncOneResponse use the correct timeout (CASSANDRA-14509) * Add option to sanity check tombstones on reads/compactions (CASSANDRA-14467) * Add a virtual table to expose all running sstable tasks (CASSANDRA-14457) * Let nodetool import take a list of directories (CASSANDRA-14442) http://git-wip-us.apache.org/repos/asf/cassandra/blob/6da5fb56/src/java/org/apache/cassandra/net/AsyncOneResponse.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/net/AsyncOneResponse.java b/src/java/org/apache/cassandra/net/AsyncOneResponse.java index 4e004d2..3fe0a2a 100644 --- a/src/java/org/apache/cassandra/net/AsyncOneResponse.java +++ b/src/java/org/apache/cassandra/net/AsyncOneResponse.java @@ -52,7 +52,7 @@ public class AsyncOneResponse<T> extends AbstractFuture<T> implements IAsyncCall } try { - return super.get(timeout, TimeUnit.NANOSECONDS); + return super.get(adjustedTimeout, TimeUnit.NANOSECONDS); } catch (InterruptedException | ExecutionException e) { http://git-wip-us.apache.org/repos/asf/cassandra/blob/6da5fb56/test/unit/org/apache/cassandra/net/AsyncOneResponseTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/net/AsyncOneResponseTest.java b/test/unit/org/apache/cassandra/net/AsyncOneResponseTest.java new file mode 100644 index 0000000..15b3327 --- /dev/null +++ b/test/unit/org/apache/cassandra/net/AsyncOneResponseTest.java @@ -0,0 +1,63 @@ +/* + * 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.cassandra.net; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.junit.Test; + +import static org.junit.Assert.assertTrue; + +public class AsyncOneResponseTest +{ + @Test(expected = TimeoutException.class) + public void getThrowsExceptionAfterTimeout() throws InterruptedException, TimeoutException + { + AsyncOneResponse<Object> response = new AsyncOneResponse<>(); + Thread.sleep(2000); + response.get(1, TimeUnit.SECONDS); + } + + @Test + public void getThrowsExceptionAfterCorrectTimeout() + { + AsyncOneResponse<Object> response = new AsyncOneResponse<>(); + + final long expectedTimeoutMillis = 1000; // Should time out after roughly this time + final long schedulingError = 10; // Scheduling is imperfect + boolean hitException = false; // Ensure we actually hit the TimeoutException + + long startTime = System.currentTimeMillis(); + + try + { + response.get(expectedTimeoutMillis, TimeUnit.MILLISECONDS); + } + catch(TimeoutException e) + { + hitException = true; + } + + long endTime = System.currentTimeMillis(); + + assertTrue(hitException); + assertTrue(endTime - startTime > (expectedTimeoutMillis - schedulingError)); + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@cassandra.apache.org For additional commands, e-mail: commits-h...@cassandra.apache.org