Skip to content

Commit c5775cd

Browse files
committed
Fixed a test
1 parent cf36969 commit c5775cd

File tree

10 files changed

+49
-18
lines changed

10 files changed

+49
-18
lines changed

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

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@
3838
import org.neo4j.driver.v1.ResultSummary;
3939
import org.neo4j.driver.v1.Statement;
4040
import org.neo4j.driver.v1.StatementType;
41+
import org.neo4j.driver.v1.Transaction;
4142
import org.neo4j.driver.v1.UpdateStatistics;
4243
import org.neo4j.driver.v1.Value;
4344
import org.neo4j.driver.v1.exceptions.ClientException;
45+
import org.neo4j.driver.v1.exceptions.Neo4jException;
4446
import org.neo4j.driver.v1.exceptions.NoSuchRecordException;
4547

4648
import static java.lang.String.format;
@@ -51,6 +53,7 @@
5153
public class InternalResultCursor extends InternalRecordAccessor implements ResultCursor
5254
{
5355
private final Connection connection;
56+
private final Transaction transaction;
5457
private final StreamCollector runResponseCollector;
5558
private final StreamCollector pullAllResponseCollector;
5659
private final Queue<Record> recordBuffer = new LinkedList<>();
@@ -64,9 +67,10 @@ public class InternalResultCursor extends InternalRecordAccessor implements Resu
6467
private long limit = -1;
6568
private boolean done = false;
6669

67-
public InternalResultCursor( Connection connection, String statement, Map<String, Value> parameters )
70+
public InternalResultCursor( Connection connection, Transaction tx, String statement, Map<String, Value> parameters )
6871
{
6972
this.connection = connection;
73+
this.transaction = tx;
7074
this.runResponseCollector = newRunResponseCollector();
7175
this.pullAllResponseCollector = newPullAllResponseCollector( new Statement( statement, parameters ) );
7276
}
@@ -172,6 +176,22 @@ StreamCollector pullAllResponseCollector()
172176
return pullAllResponseCollector;
173177
}
174178

179+
private void receiveOne()
180+
{
181+
try
182+
{
183+
connection.receiveOne();
184+
}
185+
catch ( Neo4jException ex )
186+
{
187+
if (transaction != null)
188+
{
189+
transaction.failure();
190+
}
191+
throw ex;
192+
}
193+
}
194+
175195
@Override
176196
public boolean isOpen()
177197
{
@@ -203,7 +223,7 @@ public int index( String key )
203223
public List<String> keys()
204224
{
205225
while (keys == null && !done) {
206-
connection.receiveOne();
226+
receiveOne();
207227
}
208228
return keys;
209229
}
@@ -253,7 +273,7 @@ else if (done)
253273
{
254274
while ( recordBuffer.isEmpty() && !done )
255275
{
256-
connection.receiveOne();
276+
receiveOne();
257277
}
258278
return recordBuffer.isEmpty() && done;
259279
}
@@ -282,7 +302,7 @@ else if ( done )
282302
{
283303
while ( recordBuffer.isEmpty() && !done )
284304
{
285-
connection.receiveOne();
305+
receiveOne();
286306
}
287307
return next();
288308
}
@@ -399,7 +419,7 @@ else if ( done )
399419
{
400420
while ( recordBuffer.isEmpty() && !done )
401421
{
402-
connection.receiveOne();
422+
receiveOne();
403423
}
404424
return peek();
405425
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public InternalSession( Connection connection, Logger logger )
6060
public ResultCursor run( String statementText, Map<String,Value> statementParameters )
6161
{
6262
ensureConnectionIsValid();
63-
InternalResultCursor cursor = new InternalResultCursor( connection, statementText, statementParameters );
63+
InternalResultCursor cursor = new InternalResultCursor( connection, null, statementText, statementParameters );
6464
connection.run( statementText, statementParameters, cursor.runResponseCollector() );
6565
connection.pullAll( cursor.pullAllResponseCollector() );
6666
connection.sendAll();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ public ResultCursor run( String statementText, Map<String,Value> statementParame
125125

126126
try
127127
{
128-
InternalResultCursor cursor = new InternalResultCursor( conn, statementText, statementParameters );
128+
InternalResultCursor cursor = new InternalResultCursor( conn, this, statementText, statementParameters );
129129
conn.run( statementText, statementParameters, cursor.runResponseCollector() );
130130
conn.pullAll( cursor.pullAllResponseCollector() );
131131
conn.sendAll();
@@ -158,7 +158,7 @@ public boolean isOpen()
158158

159159
private void ensureNotFailed()
160160
{
161-
if ( state == State.FAILED )
161+
if ( state == State.FAILED || state == State.MARKED_FAILED )
162162
{
163163
throw new ClientException(
164164
"Cannot run more statements in this transaction, because previous statements in the " +

driver/src/main/java/org/neo4j/driver/internal/connector/socket/SocketConnection.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public int receiveAll()
129129
{
130130
reset( StreamCollector.NO_OP );
131131
Neo4jException exception = responseHandler.serverFailure();
132-
responseHandler.reset();
132+
responseHandler.clearError();
133133
throw exception;
134134
}
135135
return messageCount;
@@ -162,7 +162,7 @@ public void receiveOne()
162162
{
163163
reset( StreamCollector.NO_OP );
164164
Neo4jException exception = responseHandler.serverFailure();
165-
responseHandler.reset();
165+
responseHandler.clearError();
166166
throw exception;
167167
}
168168
}

driver/src/main/java/org/neo4j/driver/internal/connector/socket/SocketResponseHandler.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,10 @@ public void handleFailureMessage( String code, String message )
7272
error = new DatabaseException( code, message );
7373
break;
7474
}
75-
collector.done();
75+
if ( collector != null )
76+
{
77+
collector.done();
78+
}
7679
}
7780

7881
@Override
@@ -226,7 +229,7 @@ public Neo4jException serverFailure()
226229
return error;
227230
}
228231

229-
public void reset()
232+
public void clearError()
230233
{
231234
error = null;
232235
}

driver/src/main/java/org/neo4j/driver/internal/pool/PooledConnection.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,16 @@ public void close()
165165
{
166166
// In case this session has an open result or transaction or something,
167167
// make sure it's reset to a nice state before we reuse it.
168-
reset( StreamCollector.NO_OP );
169-
release.accept( this );
168+
try
169+
{
170+
reset( StreamCollector.NO_OP );
171+
sync();
172+
release.accept( this );
173+
}
174+
catch (Exception ex)
175+
{
176+
dispose();
177+
}
170178
}
171179

172180
@Override

driver/src/test/java/org/neo4j/driver/internal/ExtractTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public void testFields() throws Exception
150150
Connection connection = mock( Connection.class );
151151
String statement = "<unknown>";
152152

153-
InternalResultCursor cursor = new InternalResultCursor( connection, statement, ParameterSupport.NO_PARAMETERS );
153+
InternalResultCursor cursor = new InternalResultCursor( connection, null, statement, ParameterSupport.NO_PARAMETERS );
154154
cursor.runResponseCollector().keys( new String[]{"k1"} );
155155
cursor.runResponseCollector().done();
156156
cursor.pullAllResponseCollector().record( new Value[]{value( 42 )} );

driver/src/test/java/org/neo4j/driver/internal/InternalResultCursorTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ private ResultCursor createResult( int numberOfRecords )
503503
Connection connection = mock( Connection.class );
504504
String statement = "<unknown>";
505505

506-
InternalResultCursor cursor = new InternalResultCursor( connection, statement, ParameterSupport.NO_PARAMETERS );
506+
InternalResultCursor cursor = new InternalResultCursor( connection, null, statement, ParameterSupport.NO_PARAMETERS );
507507
cursor.runResponseCollector().keys( new String[]{"k1", "k2"} );
508508
cursor.runResponseCollector().done();
509509
for ( int i = 1; i <= numberOfRecords; i++ )

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ public void shouldThrowHelpfulSyntaxError() throws Throwable
5050
" ^" );
5151

5252
// When
53-
session.run( "invalid statement" ).close();
53+
ResultCursor result = session.run( "invalid statement" );
54+
result.close();
5455
}
5556

5657
@Test

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,5 @@ public void shouldCloseConnectionWhenReceivingProtocolViolationError() throws Ex
9999

100100
assertThat( client.isOpen(), equalTo( false ) );
101101
verify( handler, times(1) ).protocolViolationErrorOccurred();
102-
verify( handler, times(1) ).collectorsWaiting();
103102
}
104103
}

0 commit comments

Comments
 (0)