File tree Expand file tree Collapse file tree 4 files changed +14
-33
lines changed
main/java/org/neo4j/driver
test/java/org/neo4j/driver/internal Expand file tree Collapse file tree 4 files changed +14
-33
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,6 @@ public long idleTimeBeforeConnectionTest()
51
51
52
52
public boolean idleTimeBeforeConnectionTestConfigured ()
53
53
{
54
- return idleTimeBeforeConnectionTest > 0 ;
54
+ return idleTimeBeforeConnectionTest >= 0 ;
55
55
}
56
56
}
Original file line number Diff line number Diff line change @@ -292,22 +292,16 @@ public ConfigBuilder withSessionLivenessCheckTimeout( long timeout )
292
292
* application seeing connection problems, and performance.
293
293
* <p>
294
294
* You normally should not need to tune this parameter.
295
- * This feature is turned off by default.
295
+ * This feature is turned off by default. Value {@code 0} means connections will always be tested for
296
+ * validity and negative values mean connections will never be tested.
296
297
*
297
298
* @param value the minimum idle time in milliseconds
298
299
* @param unit the unit in which the duration is given
299
300
* @return this builder
300
301
*/
301
302
public ConfigBuilder withConnectionLivenessCheckTimeout ( long value , TimeUnit unit )
302
303
{
303
- long idleTimeBeforeConnectionTestMillis = unit .toMillis ( value );
304
- if ( idleTimeBeforeConnectionTestMillis <= 0 )
305
- {
306
- throw new IllegalArgumentException ( String .format (
307
- "The timeout value must be positive when converted to ms, but was %d. Given %d %s" ,
308
- idleTimeBeforeConnectionTestMillis , value , unit ) );
309
- }
310
- this .idleTimeBeforeConnectionTest = idleTimeBeforeConnectionTestMillis ;
304
+ this .idleTimeBeforeConnectionTest = unit .toMillis ( value );
311
305
return this ;
312
306
}
313
307
Original file line number Diff line number Diff line change @@ -91,35 +91,19 @@ public void shouldSupportLivenessCheckTimeoutSetting() throws Throwable
91
91
}
92
92
93
93
@ Test
94
- public void shouldThrowForZeroTimeoutInLivenessCheckTimeoutSetting () throws Throwable
94
+ public void shouldAllowZeroConnectionLivenessCheckTimeout () throws Throwable
95
95
{
96
- Config . ConfigBuilder builder = Config .build ();
96
+ Config config = Config .build (). withConnectionLivenessCheckTimeout ( 0 , TimeUnit . SECONDS ). toConfig ();
97
97
98
- try
99
- {
100
- builder .withConnectionLivenessCheckTimeout ( 0 , TimeUnit .SECONDS );
101
- fail ( "Exception expected" );
102
- }
103
- catch ( Exception e )
104
- {
105
- assertThat ( e , instanceOf ( IllegalArgumentException .class ) );
106
- }
98
+ assertEquals ( 0 , config .idleTimeBeforeConnectionTest () );
107
99
}
108
100
109
101
@ Test
110
- public void shouldThrowForNegativeTimeoutInLivenessCheckTimeoutSetting () throws Throwable
102
+ public void shouldAllowNegativeConnectionLivenessCheckTimeout () throws Throwable
111
103
{
112
- Config . ConfigBuilder builder = Config .build ();
104
+ Config config = Config .build (). withConnectionLivenessCheckTimeout ( - 42 , TimeUnit . SECONDS ). toConfig ();
113
105
114
- try
115
- {
116
- builder .withConnectionLivenessCheckTimeout ( -42 , TimeUnit .SECONDS );
117
- fail ( "Exception expected" );
118
- }
119
- catch ( Exception e )
120
- {
121
- assertThat ( e , instanceOf ( IllegalArgumentException .class ) );
122
- }
106
+ assertEquals ( TimeUnit .SECONDS .toMillis ( -42 ), config .idleTimeBeforeConnectionTest () );
123
107
}
124
108
125
109
@ Test
Original file line number Diff line number Diff line change @@ -39,14 +39,17 @@ public void idleTimeBeforeConnectionTestWhenConfigured()
39
39
@ Test
40
40
public void idleTimeBeforeConnectionTestWhenSetToZero ()
41
41
{
42
- testWithIllegalValue ( 0 );
42
+ PoolSettings settings = new PoolSettings ( 10 , 0 );
43
+ assertTrue ( settings .idleTimeBeforeConnectionTestConfigured () );
44
+ assertEquals ( 0 , settings .idleTimeBeforeConnectionTest () );
43
45
}
44
46
45
47
@ Test
46
48
public void idleTimeBeforeConnectionTestWhenSetToNegativeValue ()
47
49
{
48
50
testWithIllegalValue ( -1 );
49
51
testWithIllegalValue ( -42 );
52
+ testWithIllegalValue ( Integer .MIN_VALUE );
50
53
}
51
54
52
55
private static void testWithIllegalValue ( int value )
You can’t perform that action at this time.
0 commit comments