Skip to content

Commit 14ace3c

Browse files
committed
Added support for resultAvailableAfter
1 parent ff8d06e commit 14ace3c

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed

driver/src/main/java/org/neo4j/driver/internal/InternalStatementResult.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,19 @@ public void done()
8282
keys = new ArrayList<>();
8383
}
8484
}
85+
86+
@Override
87+
public void resultAvailableAfter( long l )
88+
{
89+
pullAllResponseCollector.resultAvailableAfter( l );
90+
}
8591
};
8692
}
8793

8894
private StreamCollector newPullAllResponseCollector( Statement statement )
8995
{
9096
final SummaryBuilder summaryBuilder = new SummaryBuilder( statement );
97+
9198
return new StreamCollector.NoOperationStreamCollector()
9299
{
93100
@Override
@@ -131,6 +138,12 @@ public void done() {
131138
summary = summaryBuilder.build();
132139
done = true;
133140
}
141+
142+
@Override
143+
public void resultAvailableAfter(long l)
144+
{
145+
summaryBuilder.resultAvailableAfter( l );
146+
}
134147
};
135148
}
136149

driver/src/main/java/org/neo4j/driver/internal/net/SocketResponseHandler.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,18 @@ public void handleSuccessMessage( Map<String,Value> meta )
9090
collectPlan( collector, meta.get( "plan" ) );
9191
collectProfile( collector, meta.get( "profile" ) );
9292
collectNotifications( collector, meta.get( "notifications" ) );
93+
collectResultAvailableAfter( collector, meta.get("result_available_after"));
9394
collector.doneSuccess();
9495
}
9596

97+
private void collectResultAvailableAfter( StreamCollector collector, Value resultAvailableAfter )
98+
{
99+
if (resultAvailableAfter != null)
100+
{
101+
collector.resultAvailableAfter(resultAvailableAfter.asLong());
102+
}
103+
}
104+
96105
private void collectNotifications( StreamCollector collector, Value notifications )
97106
{
98107
if ( notifications != null )

driver/src/main/java/org/neo4j/driver/internal/spi/StreamCollector.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ public void doneIgnored()
144144
{
145145
done();
146146
}
147+
148+
@Override
149+
public void resultAvailableAfter( long l )
150+
{
151+
152+
}
147153
}
148154

149155
// TODO: This should be modified to simply have head/record/tail methods
@@ -169,5 +175,7 @@ public void doneIgnored()
169175
void doneFailure( Neo4jException error );
170176

171177
void doneIgnored();
178+
179+
void resultAvailableAfter( long l );
172180
}
173181

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

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,19 @@
2020

2121
import java.util.ArrayList;
2222
import java.util.List;
23+
import java.util.concurrent.TimeUnit;
2324

2425
import org.neo4j.driver.internal.spi.StreamCollector;
26+
import org.neo4j.driver.v1.Statement;
27+
import org.neo4j.driver.v1.Value;
28+
import org.neo4j.driver.v1.exceptions.ClientException;
2529
import org.neo4j.driver.v1.exceptions.Neo4jException;
2630
import org.neo4j.driver.v1.summary.Notification;
2731
import org.neo4j.driver.v1.summary.Plan;
2832
import org.neo4j.driver.v1.summary.ProfiledPlan;
2933
import org.neo4j.driver.v1.summary.ResultSummary;
30-
import org.neo4j.driver.v1.Statement;
3134
import org.neo4j.driver.v1.summary.StatementType;
3235
import org.neo4j.driver.v1.summary.SummaryCounters;
33-
import org.neo4j.driver.v1.Value;
34-
import org.neo4j.driver.v1.exceptions.ClientException;
3536

3637
public class SummaryBuilder implements StreamCollector
3738
{
@@ -42,6 +43,7 @@ public class SummaryBuilder implements StreamCollector
4243
private Plan plan = null;
4344
private ProfiledPlan profile;
4445
private List<Notification> notifications = null;
46+
private long resultAvailableAfter;
4547

4648
public SummaryBuilder( Statement statement )
4749
{
@@ -148,6 +150,12 @@ public void doneIgnored()
148150
// intentionally empty
149151
}
150152

153+
@Override
154+
public void resultAvailableAfter( long l )
155+
{
156+
this.resultAvailableAfter = l;
157+
}
158+
151159
public ResultSummary build()
152160
{
153161
return new ResultSummary()
@@ -199,6 +207,12 @@ public List<Notification> notifications()
199207
{
200208
return notifications == null ? new ArrayList<Notification>() : notifications;
201209
}
210+
211+
@Override
212+
public long resultAvailableAfter( TimeUnit timeUnit )
213+
{
214+
return timeUnit.convert( resultAvailableAfter, TimeUnit.MILLISECONDS );
215+
}
202216
};
203217
}
204218
}

driver/src/main/java/org/neo4j/driver/v1/summary/ResultSummary.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
package org.neo4j.driver.v1.summary;
2020

2121
import java.util.List;
22+
import java.util.concurrent.TimeUnit;
2223

23-
import org.neo4j.driver.v1.util.Immutable;
2424
import org.neo4j.driver.v1.Statement;
25+
import org.neo4j.driver.v1.util.Immutable;
2526

2627
/**
2728
* The result summary of running a statement. The result summary interface can be used to investigate
@@ -90,4 +91,12 @@ public interface ResultSummary
9091
* notifications produced while executing the statement.
9192
*/
9293
List<Notification> notifications();
94+
95+
/**
96+
* The time it took the server to make the result available for consumption.
97+
*
98+
* @param unit The unit of the duration.
99+
* @return The time it took for the server to have the result available in the provided time unit.
100+
*/
101+
long resultAvailableAfter( TimeUnit unit );
93102
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
import org.junit.Test;
2323

2424
import java.util.List;
25+
import java.util.concurrent.TimeUnit;
26+
2527
import org.neo4j.driver.v1.StatementResult;
2628
import org.neo4j.driver.v1.Value;
2729
import org.neo4j.driver.v1.Values;
@@ -71,6 +73,7 @@ public void shouldContainBasicMetadata() throws Throwable
7173
assertFalse( summary.hasPlan() );
7274
assertFalse( summary.hasProfile() );
7375
assertThat( summary, equalTo( result.consume() ) );
76+
assertThat( summary.resultAvailableAfter( TimeUnit.MILLISECONDS ), greaterThan( 0L ) );
7477
}
7578

7679
@Test

0 commit comments

Comments
 (0)