@@ -93,7 +93,8 @@ public void ensureRoutingShouldUpdateRoutingTableAndPurgeConnectionPoolWhenStale
93
93
when ( routingTable .update ( any ( ClusterComposition .class ) ) ).thenReturn ( set );
94
94
95
95
// when
96
- LoadBalancer balancer = new LoadBalancer ( conns , routingTable , rediscovery , DEV_NULL_LOGGER );
96
+ LoadBalancer balancer = new LoadBalancer ( conns , routingTable , rediscovery , DEV_NULL_LOGGER ,
97
+ new LeastConnectedLoadBalancingStrategy ( conns ) );
97
98
98
99
// then
99
100
assertNotNull ( balancer );
@@ -109,7 +110,8 @@ public void shouldRefreshRoutingTableOnInitialization() throws Exception
109
110
// given & when
110
111
final AtomicInteger refreshRoutingTableCounter = new AtomicInteger ( 0 );
111
112
LoadBalancer balancer = new LoadBalancer ( mock ( ConnectionPool .class ), mock ( RoutingTable .class ),
112
- mock ( Rediscovery .class ), DEV_NULL_LOGGER )
113
+ mock ( Rediscovery .class ), DEV_NULL_LOGGER ,
114
+ new LeastConnectedLoadBalancingStrategy ( mock ( ConnectionPool .class ) ) )
113
115
{
114
116
@ Override
115
117
synchronized void refreshRoutingTable ()
@@ -163,7 +165,8 @@ public void shouldForgetAddressAndItsConnectionsOnServiceUnavailableWhileClosing
163
165
RoutingTable routingTable = mock ( RoutingTable .class );
164
166
ConnectionPool connectionPool = mock ( ConnectionPool .class );
165
167
Rediscovery rediscovery = mock ( Rediscovery .class );
166
- LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER );
168
+ LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER ,
169
+ new LeastConnectedLoadBalancingStrategy ( connectionPool ) );
167
170
BoltServerAddress address = new BoltServerAddress ( "host" , 42 );
168
171
169
172
PooledConnection connection = newConnectionWithFailingSync ( address );
@@ -197,7 +200,8 @@ public void shouldForgetAddressAndItsConnectionsOnServiceUnavailableWhileClosing
197
200
PooledConnection connectionWithFailingSync = newConnectionWithFailingSync ( address );
198
201
when ( connectionPool .acquire ( any ( BoltServerAddress .class ) ) ).thenReturn ( connectionWithFailingSync );
199
202
Rediscovery rediscovery = mock ( Rediscovery .class );
200
- LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER );
203
+ LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER ,
204
+ new LeastConnectedLoadBalancingStrategy ( connectionPool ) );
201
205
202
206
Session session = newSession ( loadBalancer );
203
207
// begin transaction to make session obtain a connection
@@ -243,7 +247,8 @@ public void shouldThrowWhenRediscoveryReturnsNoSuitableServers()
243
247
when ( routingTable .readers () ).thenReturn ( new AddressSet () );
244
248
when ( routingTable .writers () ).thenReturn ( new AddressSet () );
245
249
246
- LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER );
250
+ LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER ,
251
+ new LeastConnectedLoadBalancingStrategy ( connections ) );
247
252
248
253
try
249
254
{
@@ -283,7 +288,8 @@ public void shouldSelectLeastConnectedAddress()
283
288
284
289
Rediscovery rediscovery = mock ( Rediscovery .class );
285
290
286
- LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER );
291
+ LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER ,
292
+ new LeastConnectedLoadBalancingStrategy ( connectionPool ) );
287
293
288
294
Set <BoltServerAddress > seenAddresses = new HashSet <>();
289
295
for ( int i = 0 ; i < 10 ; i ++ )
@@ -309,7 +315,8 @@ public void shouldRoundRobinWhenNoActiveConnections()
309
315
310
316
Rediscovery rediscovery = mock ( Rediscovery .class );
311
317
312
- LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER );
318
+ LoadBalancer loadBalancer = new LoadBalancer ( connectionPool , routingTable , rediscovery , DEV_NULL_LOGGER ,
319
+ new LeastConnectedLoadBalancingStrategy ( connectionPool ) );
313
320
314
321
Set <BoltServerAddress > seenAddresses = new HashSet <>();
315
322
for ( int i = 0 ; i < 10 ; i ++ )
@@ -330,7 +337,8 @@ private void testRediscoveryWhenStale( AccessMode mode )
330
337
RoutingTable routingTable = newStaleRoutingTableMock ( mode );
331
338
Rediscovery rediscovery = newRediscoveryMock ();
332
339
333
- LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER );
340
+ LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER ,
341
+ new LeastConnectedLoadBalancingStrategy ( connections ) );
334
342
verify ( rediscovery ).lookupClusterComposition ( routingTable , connections );
335
343
336
344
assertNotNull ( loadBalancer .acquireConnection ( mode ) );
@@ -346,7 +354,8 @@ private void testNoRediscoveryWhenNotStale( AccessMode staleMode, AccessMode not
346
354
RoutingTable routingTable = newStaleRoutingTableMock ( staleMode );
347
355
Rediscovery rediscovery = newRediscoveryMock ();
348
356
349
- LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER );
357
+ LoadBalancer loadBalancer = new LoadBalancer ( connections , routingTable , rediscovery , DEV_NULL_LOGGER ,
358
+ new LeastConnectedLoadBalancingStrategy ( connections ) );
350
359
verify ( rediscovery ).lookupClusterComposition ( routingTable , connections );
351
360
352
361
assertNotNull ( loadBalancer .acquireConnection ( notStaleMode ) );
@@ -379,7 +388,8 @@ private LoadBalancer setupLoadBalancer( PooledConnection writerConn, PooledConne
379
388
when ( routingTable .readers () ).thenReturn ( readerAddrs );
380
389
when ( routingTable .writers () ).thenReturn ( writerAddrs );
381
390
382
- return new LoadBalancer ( connPool , routingTable , rediscovery , DEV_NULL_LOGGER );
391
+ return new LoadBalancer ( connPool , routingTable , rediscovery , DEV_NULL_LOGGER ,
392
+ new LeastConnectedLoadBalancingStrategy ( connPool ) );
383
393
}
384
394
385
395
private static Session newSession ( LoadBalancer loadBalancer )
0 commit comments