Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
b16a727
Refactor ConcurrentPool so that it becomes agnostic of the item initi…
stIncMale Mar 4, 2021
f21d299
Implement maxConnecting in DefaultConnectionPool.get
stIncMale Mar 10, 2021
9371a8b
Add specification tests
stIncMale Mar 10, 2021
388a7a7
Implement integration style CMAP specification tests
stIncMale Mar 10, 2021
1e75fe0
Implement maxConnecting in DefaultConnectionPool.getAsync
stIncMale Mar 16, 2021
8360c76
Fix static validation issues
stIncMale Mar 16, 2021
045fe13
Implement runOn in AbstractConnectionPoolTest
stIncMale Mar 16, 2021
5e5c7c0
Send ConnectionCheckOutFailedEvent with Reason.CONNECTION_ERROR if fa…
stIncMale Mar 17, 2021
459466a
Address the first set of review concerns
stIncMale Mar 17, 2021
4dae245
Add an test for DefaultConnectionPool.getAsync that checks for Reason…
stIncMale Mar 18, 2021
5d203f7
Simplify DefaultConnectionPoolSpecification.selectConnectionAsync
stIncMale Mar 18, 2021
3d54d9d
Simplify ConcurrentPool.ensureMinSize
stIncMale Mar 23, 2021
26a4a7b
Replace Java assert statements with our assert methods
stIncMale Mar 24, 2021
e2bd080
Merge branch 'master' into JAVA-3927
stIncMale Mar 24, 2021
45d1891
Address naming and try-finally review concerns
stIncMale Mar 24, 2021
49a3e3c
Fix ensureMinSize call in ConcurrentPoolTest
stIncMale Mar 24, 2021
fbd5a97
Add tests for Timeout
stIncMale Mar 25, 2021
6eaf542
Introduce sync and async methods by duplicating the logic of openOrSi…
stIncMale Mar 25, 2021
f5967d1
Make it clearer that releasePermit and tryHandOver methods acquire th…
stIncMale Mar 26, 2021
1e29f20
Replace Timeout.remainingNanos with remaining(TimeUnit)
stIncMale Mar 26, 2021
d3a9195
Address review concerns
stIncMale Mar 31, 2021
fa3c23c
Undo changes in the ConnectionPoolListener specification
stIncMale Apr 1, 2021
0fedc2d
Improve docs
stIncMale Apr 3, 2021
22d3afc
Add concurrency tests for DefaultConnectionPool
stIncMale Apr 3, 2021
fbdd763
Assert all checked in connections are handed over in DefaultConnectio…
stIncMale Apr 5, 2021
ba98f3d
Address review concerns
stIncMale Apr 5, 2021
b04ff8f
Do not confuse a user with timeout exceptions caused by timeout excep…
stIncMale Apr 6, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix static validation issues
  • Loading branch information
stIncMale committed Mar 16, 2021
commit 8360c76bfb1552462b1ddf9fb640af1b7edd39ba
6 changes: 6 additions & 0 deletions config/findbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,10 @@
<Bug pattern="VA_FORMAT_STRING_USES_NEWLINE"/>
</Match>

<!-- The return value of Condition.awaitNanos is ignored on purpose for infinite timeouts. -->
<Match>
<Class name="com.mongodb.internal.connection.DefaultConnectionPool$OpenConcurrencyLimiter"/>
<Method name="awaitNanos"/>
<Bug pattern="RV_RETURN_VALUE_IGNORED_BAD_PRACTICE"/>
</Match>
</FindBugsFilter>
30 changes: 23 additions & 7 deletions driver-core/src/main/com/mongodb/internal/Timeout.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
/*
* Copyright 2008-present MongoDB, Inc.
*
* 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.mongodb.internal;

import com.mongodb.annotations.Immutable;

import java.util.Objects;
import java.util.concurrent.TimeUnit;

import static com.mongodb.assertions.Assertions.notNull;
import static java.util.concurrent.TimeUnit.NANOSECONDS;

/**
Expand All @@ -28,7 +44,7 @@ private Timeout(final long durationNanos, final long startNanos) {
* @see #startNow(long)
*/
public static Timeout startNow(final long duration, final TimeUnit unit) {
return startNow(unit.toNanos(duration));
return startNow(notNull("unit", unit).toNanos(duration));
}

/**
Expand Down Expand Up @@ -65,8 +81,8 @@ public static Timeout immediate() {
* Returns duration as per {@link #startNow(long)}.
* The duration is converted to the specified {@code unit} via {@link TimeUnit#convert(long, TimeUnit)}.
*/
public long duration(TimeUnit unit) {
return unit.convert(durationNanos, NANOSECONDS);
public long duration(final TimeUnit unit) {
return notNull("unit", unit).convert(durationNanos, NANOSECONDS);
}

/**
Expand Down Expand Up @@ -151,9 +167,9 @@ public int hashCode() {

@Override
public String toString() {
return "Timeout{" +
"durationNanos=" + durationNanos +
", startNanos=" + startNanos +
'}';
return "Timeout{"
+ "durationNanos=" + durationNanos
+ ", startNanos=" + startNanos
+ '}';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -818,8 +818,11 @@ private PooledConnection acquirePermitOrGetAvailableOpenConnection(final boolean
addLastDesiredConnectionSlot();
}
long remainingNanos = timeout.remainingNanosOrInfinite();
while (permits == 0
&& (availableConnection = tryGetAvailable ? tryGetAndRemoveFirstDesiredConnectionSlot() : null) == null) {
while (permits == 0) {
availableConnection = tryGetAvailable ? tryGetAndRemoveFirstDesiredConnectionSlot() : null;
if (availableConnection != null) {
break;
}
if (Timeout.expired(remainingNanos)) {
throw createTimeoutException(timeout);
}
Expand Down Expand Up @@ -929,7 +932,7 @@ private PooledConnection openAndReleasePermit(
}

@Nullable
private <T> T returnValue(T value, @Nullable SingleResultCallback<? super T> callback) {
private <T> T returnValue(final T value, @Nullable final SingleResultCallback<? super T> callback) {
if (callback == null) {
return value;
} else {
Expand All @@ -939,7 +942,8 @@ private <T> T returnValue(T value, @Nullable SingleResultCallback<? super T> cal
}

@Nullable
private <T> T throwException(RuntimeException e, @Nullable SingleResultCallback<? super T> callback) throws RuntimeException {
private <T> T throwException(final RuntimeException e, @Nullable final SingleResultCallback<? super T> callback)
throws RuntimeException {
if (callback == null) {
throw e;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public void whenEnsuringMinSizeShouldNotInitializePooledItemIfNotRequested() {
public void whenEnsuringMinSizeShouldInitializePooledItemIfRequested() {
pool = new ConcurrentPool<TestCloseable>(3, new TestItemFactory());

pool.ensureMinSize(1, TestCloseable.initializeAction);
pool.ensureMinSize(1, TestCloseable.INIT_ACTION);
assertTrue(pool.get().isInitialized());
}

Expand All @@ -181,7 +181,7 @@ public void testThatEnsuringMinSizeReleasesPermitIfCreateFails() {
pool = new ConcurrentPool<TestCloseable>(1, new TestItemFactory(true));

try {
pool.ensureMinSize(1, TestCloseable.initializeAction);
pool.ensureMinSize(1, TestCloseable.INIT_ACTION);
fail();
} catch (MongoException e) {
// expected
Expand Down Expand Up @@ -253,7 +253,7 @@ public ConcurrentPool.Prune shouldPrune(final TestCloseable testCloseable) {
}

static class TestCloseable implements Closeable {
private static final Function<TestCloseable, Optional<TestCloseable>> initializeAction = connection -> {
private static final Function<TestCloseable, Optional<TestCloseable>> INIT_ACTION = connection -> {
connection.initialized = true;
return Optional.of(connection);
};
Expand Down