Merge branch 'stable-2.15' into stable-2.16

* stable-2.15:
  ReceiveCommits: Fix comparison to ensure correct log message
  Set sshd.threads to at least 4.
  Add assertThrows method compatible with future JUnit 4.13
  ReceiveCommits: Bypass commit count when skip-validation is used
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules
  Update git submodules

Change-Id: Iea0dc2d5f28c0c8e0489e7ce2bb429064ce7aca3
This commit is contained in:
David Pursehouse
2019-07-25 10:30:59 +09:00
7 changed files with 192 additions and 3 deletions

View File

@@ -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

View File

@@ -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);

View File

@@ -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(

View File

@@ -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() {}
}

View File

@@ -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();
}
}
}

View File

@@ -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";