diff options
author | Edwin Kempin <ekempin@google.com> | 2019-07-25 07:14:18 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2019-07-25 07:14:18 +0000 |
commit | 21df2c07ce959b4bf3e3f83c89bf67761a082dd4 (patch) | |
tree | 22a35471999ba739bf7752a0b6dc33885f5bf51f | |
parent | 1b5d47a978b77431050fb47a9f342dccd82bf3f3 (diff) | |
parent | cfa98404cb71ac61a72aff613a9ae21e28d05f5c (diff) |
Merge "Merge branch 'stable-2.15' into stable-2.16" into stable-2.16
-rw-r--r-- | Documentation/config-gerrit.txt | 3 | ||||
-rw-r--r-- | java/com/google/gerrit/server/config/ThreadSettingsConfig.java | 2 | ||||
-rw-r--r-- | java/com/google/gerrit/server/git/receive/ReceiveCommits.java | 3 | ||||
-rw-r--r-- | java/com/google/gerrit/testing/GerritJUnit.java | 67 | ||||
-rw-r--r-- | java/com/google/gerrit/testing/GerritJUnitTest.java | 90 | ||||
-rw-r--r-- | javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java | 28 | ||||
m--------- | plugins/replication | 0 |
7 files changed, 191 insertions, 2 deletions
diff --git a/Documentation/config-gerrit.txt b/Documentation/config-gerrit.txt index 78100ae5cd..f13aed1f6b 100644 --- a/Documentation/config-gerrit.txt +++ b/Documentation/config-gerrit.txt @@ -4441,7 +4441,8 @@ Number of threads to use when executing SSH command requests. If additional requests are received while all threads are busy they are queued and serviced in a first-come-first-served order. + -By default, 2x the number of CPUs available to the JVM. +By default, 2x the number of CPUs available to the JVM (but at least 4 +threads). + [NOTE] When SSH daemon is enabled then this setting also defines the max number of diff --git a/java/com/google/gerrit/server/config/ThreadSettingsConfig.java b/java/com/google/gerrit/server/config/ThreadSettingsConfig.java index 6cb32cc0e5..c20e0a4ea4 100644 --- a/java/com/google/gerrit/server/config/ThreadSettingsConfig.java +++ b/java/com/google/gerrit/server/config/ThreadSettingsConfig.java @@ -28,7 +28,7 @@ public class ThreadSettingsConfig { @Inject ThreadSettingsConfig(@GerritServerConfig Config cfg) { int cores = Runtime.getRuntime().availableProcessors(); - sshdThreads = cfg.getInt("sshd", "threads", 2 * cores); + sshdThreads = cfg.getInt("sshd", "threads", Math.max(4, 2 * cores)); httpdMaxThreads = cfg.getInt("httpd", "maxThreads", 25); int defaultDatabasePoolLimit = sshdThreads + httpdMaxThreads + 2; databasePoolLimit = cfg.getInt("database", "poolLimit", defaultDatabasePoolLimit); diff --git a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java index 8cc7674a69..91c9f0b626 100644 --- a/java/com/google/gerrit/server/git/receive/ReceiveCommits.java +++ b/java/com/google/gerrit/server/git/receive/ReceiveCommits.java @@ -3048,6 +3048,9 @@ class ReceiveCommits { int limit = receiveConfig.maxBatchCommits; int n = 0; for (RevCommit c; (c = walk.next()) != null; ) { + // Even if skipValidation is set, we still get here when at least one plugin + // commit validator requires to validate all commits. In this case, however, + // we don't need to check the commit limit. if (++n > limit && !skipValidation) { logger.atFine().log("Number of new commits exceeds limit of %d", limit); reject( diff --git a/java/com/google/gerrit/testing/GerritJUnit.java b/java/com/google/gerrit/testing/GerritJUnit.java new file mode 100644 index 0000000000..0771c39454 --- /dev/null +++ b/java/com/google/gerrit/testing/GerritJUnit.java @@ -0,0 +1,67 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed 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 com.google.gerrit.testing; + +/** Static JUnit utility methods. */ +public class GerritJUnit { + /** + * Assert that an exception is thrown by a block of code. + * + * <p>This method is source-compatible with <a + * href="https://junit.org/junit4/javadoc/latest/org/junit/Assert.html#assertThrows(java.lang.Class,%20org.junit.function.ThrowingRunnable)">JUnit + * 4.13 beta</a>. + * + * <p>This construction is recommended by the Truth team for use in conjunction with asserting + * over a {@code ThrowableSubject} on the return type: + * + * <pre> + * MyException e = assertThrows(MyException.class, () -> doSomething(foo)); + * assertThat(e).isInstanceOf(MySubException.class); + * assertThat(e).hasMessageThat().contains("sub-exception occurred"); + * </pre> + * + * @param throwableClass expected exception type. + * @param runnable runnable containing arbitrary code. + * @return exception that was thrown. + */ + public static <T extends Throwable> T assertThrows( + Class<T> throwableClass, ThrowingRunnable runnable) { + try { + runnable.run(); + } catch (Throwable t) { + if (!throwableClass.isInstance(t)) { + throw new AssertionError( + "expected " + + throwableClass.getName() + + " but " + + t.getClass().getName() + + " was thrown", + t); + } + @SuppressWarnings("unchecked") + T toReturn = (T) t; + return toReturn; + } + throw new AssertionError( + "expected " + throwableClass.getName() + " but no exception was thrown"); + } + + @FunctionalInterface + public interface ThrowingRunnable { + void run() throws Throwable; + } + + private GerritJUnit() {} +} diff --git a/java/com/google/gerrit/testing/GerritJUnitTest.java b/java/com/google/gerrit/testing/GerritJUnitTest.java new file mode 100644 index 0000000000..430f48f832 --- /dev/null +++ b/java/com/google/gerrit/testing/GerritJUnitTest.java @@ -0,0 +1,90 @@ +// Copyright (C) 2019 The Android Open Source Project +// +// Licensed 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 com.google.gerrit.testing; + +import static com.google.common.truth.Truth.assertThat; +import static com.google.common.truth.Truth.assert_; +import static com.google.gerrit.testing.GerritJUnit.assertThrows; + +import org.junit.Test; + +public class GerritJUnitTest { + private static class MyException extends Exception { + private static final long serialVersionUID = 1L; + + MyException(String msg) { + super(msg); + } + } + + private static class MySubException extends MyException { + private static final long serialVersionUID = 1L; + + MySubException(String msg) { + super(msg); + } + } + + @Test + public void assertThrowsCatchesSpecifiedExceptionType() { + MyException e = + assertThrows( + MyException.class, + () -> { + throw new MyException("foo"); + }); + assertThat(e).hasMessageThat().isEqualTo("foo"); + } + + @Test + public void assertThrowsCatchesSubclassOfSpecifiedExceptionType() { + MyException e = + assertThrows( + MyException.class, + () -> { + throw new MySubException("foo"); + }); + assertThat(e).isInstanceOf(MySubException.class); + assertThat(e).hasMessageThat().isEqualTo("foo"); + } + + @Test + public void assertThrowsConvertsUnexpectedExceptionTypeToAssertionError() { + try { + assertThrows( + IllegalStateException.class, + () -> { + throw new MyException("foo"); + }); + assert_().fail("expected AssertionError"); + } catch (AssertionError e) { + assertThat(e).hasMessageThat().contains(IllegalStateException.class.getSimpleName()); + assertThat(e).hasMessageThat().contains(MyException.class.getSimpleName()); + assertThat(e).hasCauseThat().isInstanceOf(MyException.class); + assertThat(e).hasCauseThat().hasMessageThat().isEqualTo("foo"); + } + } + + @Test + public void assertThrowsThrowsAssertionErrorWhenNothingThrown() { + try { + assertThrows(MyException.class, () -> {}); + assert_().fail("expected AssertionError"); + } catch (AssertionError e) { + assertThat(e).hasMessageThat().contains(MyException.class.getSimpleName()); + assertThat(e).hasCauseThat().isNull(); + } + } +} diff --git a/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java b/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java index dc1c53384e..8e14330670 100644 --- a/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java +++ b/javatests/com/google/gerrit/acceptance/git/AbstractPushForReview.java @@ -2252,6 +2252,34 @@ public abstract class AbstractPushForReview extends AbstractDaemonTest { @GerritConfig(name = "receive.maxBatchCommits", value = "2") @Test public void maxBatchCommits() throws Exception { + testMaxBatchCommits(); + } + + @GerritConfig(name = "receive.maxBatchCommits", value = "2") + @Test + public void maxBatchCommitsWithDefaultValidator() throws Exception { + TestValidator validator = new TestValidator(); + RegistrationHandle handle = commitValidators.add("test-validator", validator); + try { + testMaxBatchCommits(); + } finally { + handle.remove(); + } + } + + @GerritConfig(name = "receive.maxBatchCommits", value = "2") + @Test + public void maxBatchCommitsWithValidateAllCommitsValidator() throws Exception { + TestValidator validator = new TestValidator(true); + RegistrationHandle handle = commitValidators.add("test-validator", validator); + try { + testMaxBatchCommits(); + } finally { + handle.remove(); + } + } + + private void testMaxBatchCommits() throws Exception { List<RevCommit> commits = new ArrayList<>(); commits.addAll(initChanges(2)); String master = "refs/heads/master"; diff --git a/plugins/replication b/plugins/replication -Subproject a3cf8a61980a84ae710b15cb93d9a2a7423d93c +Subproject 423547441a96b5397e620e23010561838c784c5 |