Skip to content

Commit 71303c2

Browse files
committed
Added conditional test so it runs with 3.0.X
1 parent cd787ed commit 71303c2

File tree

4 files changed

+157
-18
lines changed

4 files changed

+157
-18
lines changed

driver/src/main/java/org/neo4j/driver/internal/summary/SummaryBuilder.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class SummaryBuilder implements StreamCollector
4343
private Plan plan = null;
4444
private ProfiledPlan profile;
4545
private List<Notification> notifications = null;
46-
private long resultAvailableAfter;
47-
private long resultConsumedAfter;
46+
private long resultAvailableAfter = -1L;
47+
private long resultConsumedAfter = -1L;
4848

4949
public SummaryBuilder( Statement statement )
5050
{

driver/src/test/java/org/neo4j/driver/v1/integration/SessionIT.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import static org.hamcrest.CoreMatchers.equalTo;
3535
import static org.hamcrest.Matchers.greaterThan;
3636
import static org.junit.Assert.assertFalse;
37-
import static org.junit.Assert.assertNotNull;
3837
import static org.junit.Assert.assertThat;
3938
import static org.junit.Assert.assertTrue;
4039
import static org.junit.Assert.fail;
@@ -174,19 +173,6 @@ public void shouldKillLongStreamingResult() throws Throwable
174173
}
175174
}
176175

177-
@Test
178-
public void shouldShowServerVersion() throws Throwable
179-
{
180-
// Given
181-
try( Driver driver = GraphDatabase.driver( neo4j.uri() ) )
182-
{
183-
try ( Session session = driver.session() )
184-
{
185-
assertNotNull( session.server() );
186-
}
187-
}
188-
}
189-
190176
private void resetSessionAfterTimeout( final Session session, final int timeout )
191177
{
192178
new Thread( new Runnable()

driver/src/test/java/org/neo4j/driver/v1/integration/SummaryIT.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
import static org.junit.Assert.assertNotNull;
4444
import static org.junit.Assert.assertThat;
4545
import static org.junit.Assert.assertTrue;
46+
import static org.neo4j.driver.v1.util.ServerVersion.v3_1_0;
47+
import static org.neo4j.driver.v1.util.ServerVersion.version;
4648

4749
public class SummaryIT
4850
{
@@ -73,8 +75,27 @@ public void shouldContainBasicMetadata() throws Throwable
7375
assertFalse( summary.hasPlan() );
7476
assertFalse( summary.hasProfile() );
7577
assertThat( summary, equalTo( result.consume() ) );
76-
assertThat( summary.resultAvailableAfter( TimeUnit.MILLISECONDS ), greaterThan( 0L ) );
77-
assertThat( summary.resultConsumedAfter( TimeUnit.MILLISECONDS ), greaterThan( 0L ) );
78+
79+
}
80+
81+
@Test
82+
public void shouldContainTimeInformation()
83+
{
84+
// Given
85+
ResultSummary summary = session.run( "UNWIND range(1,1000) AS n RETURN n AS number" ).consume();
86+
87+
// Then
88+
if ( version( session.server() ).greaterThanOrEqual( v3_1_0 ) )
89+
{
90+
assertThat( summary.resultAvailableAfter( TimeUnit.MILLISECONDS ), greaterThan( 0L ) );
91+
assertThat( summary.resultConsumedAfter( TimeUnit.MILLISECONDS ), greaterThan( 0L ) );
92+
}
93+
else
94+
{
95+
//Not passed through by older versions of the server
96+
assertThat( summary.resultAvailableAfter( TimeUnit.MILLISECONDS ), equalTo( -1L ) );
97+
assertThat( summary.resultConsumedAfter( TimeUnit.MILLISECONDS ), equalTo( -1L ) );
98+
}
7899
}
79100

80101
@Test
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
/**
2+
* Copyright (c) 2002-2016 "Neo Technology,"
3+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
4+
*
5+
* This file is part of Neo4j.
6+
*
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
*/
19+
package org.neo4j.driver.v1.util;
20+
21+
import java.util.regex.Matcher;
22+
import java.util.regex.Pattern;
23+
24+
import static java.lang.Integer.compare;
25+
26+
public class ServerVersion
27+
{
28+
private final int major;
29+
private final int minor;
30+
private final int patch;
31+
32+
private static final Pattern PATTERN =
33+
Pattern.compile("Neo4j/(\\d+)\\.(\\d+)(?:\\.)?(\\d*)(\\.|-|\\+)?([0-9A-Za-z-.]*)?");
34+
35+
private ServerVersion( int major, int minor, int patch )
36+
{
37+
this.major = major;
38+
this.minor = minor;
39+
this.patch = patch;
40+
}
41+
public static final ServerVersion v3_1_0 = new ServerVersion(3, 1, 0);
42+
public static final ServerVersion v3_0_0 = new ServerVersion(3, 1, 0);
43+
44+
public static ServerVersion version( String server )
45+
{
46+
if ( server == null )
47+
{
48+
return new ServerVersion( 3, 0, 0 );
49+
}
50+
else
51+
{
52+
Matcher matcher = PATTERN.matcher( server );
53+
if ( matcher.matches() )
54+
{
55+
int major = Integer.valueOf( matcher.group( 1 ) );
56+
int minor = Integer.valueOf( matcher.group( 2 ) );
57+
String patchString = matcher.group( 3 );
58+
int patch = 0;
59+
if ( patchString != null && !patchString.isEmpty() )
60+
{
61+
patch = Integer.valueOf( patchString );
62+
}
63+
return new ServerVersion( major, minor, patch );
64+
}
65+
else
66+
{
67+
throw new IllegalArgumentException( "Cannot parse " + server );
68+
}
69+
}
70+
}
71+
72+
@Override
73+
public boolean equals( Object o )
74+
{
75+
if ( this == o )
76+
{ return true; }
77+
if ( o == null || getClass() != o.getClass() )
78+
{ return false; }
79+
80+
ServerVersion that = (ServerVersion) o;
81+
82+
if ( major != that.major )
83+
{ return false; }
84+
if ( minor != that.minor )
85+
{ return false; }
86+
return patch == that.patch;
87+
}
88+
89+
@Override
90+
public int hashCode()
91+
{
92+
int result = major;
93+
result = 31 * result + minor;
94+
result = 31 * result + patch;
95+
return result;
96+
}
97+
98+
public boolean greaterThan(ServerVersion other)
99+
{
100+
return compareTo( other ) > 0;
101+
}
102+
103+
public boolean greaterThanOrEqual(ServerVersion other)
104+
{
105+
return compareTo( other ) >= 0;
106+
}
107+
108+
public boolean lessThan(ServerVersion other)
109+
{
110+
return compareTo( other ) < 0;
111+
}
112+
113+
public boolean lessThanOrEqual(ServerVersion other)
114+
{
115+
return compareTo( other ) <= 0;
116+
}
117+
118+
private int compareTo( ServerVersion o )
119+
{
120+
int c = compare( major, o.major );
121+
if (c == 0)
122+
{
123+
c = compare( minor, o.minor );
124+
if (c == 0)
125+
{
126+
c = compare( patch, o.patch );
127+
}
128+
}
129+
130+
return c;
131+
}
132+
}

0 commit comments

Comments
 (0)