File tree Expand file tree Collapse file tree 3 files changed +73
-3
lines changed
main/com/mongodb/connection
test/functional/com/mongodb/connection Expand file tree Collapse file tree 3 files changed +73
-3
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2008-2014 MongoDB, Inc.
2
+ * Copyright (c) 2008-2015 MongoDB, Inc.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -83,10 +83,10 @@ public InternalConnection get() {
83
83
@ Override
84
84
public InternalConnection get (final long timeout , final TimeUnit timeUnit ) {
85
85
try {
86
+ connectionPoolListener .waitQueueEntered (new ConnectionPoolWaitQueueEvent (serverId , currentThread ().getId ()));
86
87
if (waitQueueSize .incrementAndGet () > settings .getMaxWaitQueueSize ()) {
87
88
throw createWaitQueueFullException ();
88
89
}
89
- connectionPoolListener .waitQueueEntered (new ConnectionPoolWaitQueueEvent (serverId , currentThread ().getId ()));
90
90
PooledConnection pooledConnection = getPooledConnection (timeout , timeUnit );
91
91
if (!pooledConnection .opened ()) {
92
92
try {
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright (c) 2008-2014 MongoDB, Inc.
2
+ * Copyright (c) 2008-2015 MongoDB, Inc.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
@@ -227,4 +227,34 @@ public void shouldPruneAfterMaintenanceTaskRuns() throws InterruptedException {
227
227
// then
228
228
assertTrue (connectionFactory .getCreatedConnections ().get (0 ).isClosed ());
229
229
}
230
+
231
+ @ Test
232
+ public void shouldNotCallWaitQueueExitedIfWaitQueueEnteredWasNotCalled () throws InterruptedException {
233
+ // given
234
+ QueueEventsConnectionPoolListener listener = new QueueEventsConnectionPoolListener ();
235
+
236
+ provider = new DefaultConnectionPool (SERVER_ID , connectionFactory ,
237
+ ConnectionPoolSettings .builder ()
238
+ .maxSize (1 )
239
+ .maxWaitQueueSize (1 )
240
+ .maxWaitTime (500 , MILLISECONDS )
241
+ .build (),
242
+ listener );
243
+
244
+ // when
245
+ provider .get ();
246
+
247
+ new Thread (new TimeoutTrackingConnectionGetter (provider )).start ();
248
+ Thread .sleep (100 );
249
+
250
+ try {
251
+ provider .get ();
252
+ fail ();
253
+ } catch (MongoWaitQueueFullException e ) {
254
+ // all good
255
+ }
256
+
257
+ // then
258
+ assertEquals (1 , listener .getWaitQueueSize ());
259
+ }
230
260
}
Original file line number Diff line number Diff line change
1
+ /*
2
+ * Copyright (c) 2008-2015 MongoDB, Inc.
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ package com .mongodb .connection ;
18
+
19
+ import com .mongodb .event .ConnectionPoolListenerAdapter ;
20
+ import com .mongodb .event .ConnectionPoolWaitQueueEvent ;
21
+
22
+ import java .util .concurrent .atomic .AtomicInteger ;
23
+
24
+ class QueueEventsConnectionPoolListener extends ConnectionPoolListenerAdapter {
25
+ private final AtomicInteger waitQueueSize = new AtomicInteger ();
26
+
27
+ @ Override
28
+ public void waitQueueExited (ConnectionPoolWaitQueueEvent event ) {
29
+ waitQueueSize .decrementAndGet ();
30
+ }
31
+
32
+ @ Override
33
+ public void waitQueueEntered (ConnectionPoolWaitQueueEvent event ) {
34
+ waitQueueSize .incrementAndGet ();
35
+ }
36
+
37
+ public int getWaitQueueSize () {
38
+ return waitQueueSize .get ();
39
+ }
40
+ }
You can’t perform that action at this time.
0 commit comments