Skip to content

Commit e9299f0

Browse files
authored
Fixing Red Builds Against 4.1 (#715)
1 parent 286693e commit e9299f0

File tree

3 files changed

+45
-30
lines changed

3 files changed

+45
-30
lines changed

driver/src/test/java/org/neo4j/driver/integration/BookmarkIT.java

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.neo4j.driver.Transaction;
3232
import org.neo4j.driver.exceptions.ClientException;
3333
import org.neo4j.driver.Bookmark;
34+
import org.neo4j.driver.internal.InternalBookmark;
3435
import org.neo4j.driver.internal.util.DisabledOnNeo4jWith;
3536
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
3637
import org.neo4j.driver.internal.util.Neo4jFeature;
@@ -39,6 +40,7 @@
3940

4041
import static org.hamcrest.Matchers.startsWith;
4142
import static org.junit.jupiter.api.Assertions.assertEquals;
43+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
4244
import static org.junit.jupiter.api.Assertions.assertThrows;
4345
import static org.neo4j.driver.SessionConfig.builder;
4446
import static org.neo4j.driver.internal.InternalBookmark.parse;
@@ -81,32 +83,15 @@ void shouldReceiveBookmarkOnSuccessfulCommit() throws Throwable
8183
void shouldReceiveNewBookmarkOnSuccessfulCommit() throws Throwable
8284
{
8385
// Given
84-
assertBookmarkIsEmpty( session.lastBookmark() );
86+
Bookmark initialBookmark = session.lastBookmark();
87+
assertBookmarkIsEmpty( initialBookmark );
8588

8689
// When
8790
createNodeInTx( session );
8891

8992
// Then
90-
assertBookmarkContainsSingleValue( session.lastBookmark(), new BaseMatcher<String>()
91-
{
92-
@Override
93-
public boolean matches( Object item )
94-
{
95-
if ( item instanceof String )
96-
{
97-
String bookmark = (String) item;
98-
String[] split = bookmark.split( ":" );
99-
return split.length == 2 && isUuid( split[0] ) && isNumeric( split[1] );
100-
}
101-
return false;
102-
}
103-
104-
@Override
105-
public void describeTo( Description description )
106-
{
107-
description.appendText( "Expecting a bookmark with format 'database_uuid:tx_id'" );
108-
}
109-
} );
93+
assertBookmarkContainsSingleValue( session.lastBookmark() );
94+
assertNotEquals( initialBookmark, session.lastBookmark() );
11095
}
11196

11297
@Test

driver/src/test/java/org/neo4j/driver/integration/SessionBoltV3IT.java

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import org.neo4j.driver.TransactionConfig;
4040
import org.neo4j.driver.async.AsyncSession;
4141
import org.neo4j.driver.async.ResultCursor;
42+
import org.neo4j.driver.exceptions.ClientException;
4243
import org.neo4j.driver.exceptions.TransientException;
4344
import org.neo4j.driver.internal.cluster.RoutingSettings;
4445
import org.neo4j.driver.internal.messaging.Message;
@@ -63,6 +64,7 @@
6364
import static org.junit.jupiter.api.Assertions.assertNotNull;
6465
import static org.junit.jupiter.api.Assertions.assertThrows;
6566
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
67+
import static org.junit.jupiter.api.Assertions.fail;
6668
import static org.neo4j.driver.Config.defaultConfig;
6769
import static org.neo4j.driver.internal.util.Neo4jFeature.BOLT_V3;
6870
import static org.neo4j.driver.util.TestUtil.TX_TIMEOUT_TEST_TIMEOUT;
@@ -132,9 +134,9 @@ void shouldSetTransactionTimeout()
132134
TransactionConfig config = TransactionConfig.builder().withTimeout( ofMillis( 1 ) ).build();
133135

134136
// run a query in an auto-commit transaction with timeout and try to update the locked dummy node
135-
TransientException error = assertThrows( TransientException.class,
137+
Exception error = assertThrows( Exception.class,
136138
() -> session.run( "MATCH (n:Node) SET n.prop = 2", config ).consume() );
137-
assertThat( error.getMessage(), containsString( "terminated" ) );
139+
verifyValidException( error );
138140
} );
139141
}
140142
}
@@ -163,9 +165,8 @@ void shouldSetTransactionTimeoutAsync()
163165
CompletionStage<ResultSummary> resultFuture = asyncSession.runAsync( "MATCH (n:Node) SET n.prop = 2", config )
164166
.thenCompose( ResultCursor::consumeAsync );
165167

166-
TransientException error = assertThrows( TransientException.class, () -> await( resultFuture ) );
167-
168-
MatcherAssert.assertThat( error.getMessage(), containsString( "terminated" ) );
168+
Exception error = assertThrows( Exception.class, () -> await( resultFuture ) );
169+
verifyValidException( error );
169170
} );
170171
}
171172
}
@@ -362,4 +363,16 @@ private static void testTransactionMetadataWithTransactionFunctions( boolean rea
362363
assertEquals( metadata, receivedMetadata );
363364
}
364365

366+
private static void verifyValidException( Exception error )
367+
{
368+
// Server 4.1 corrected this exception to ClientException. Testing either here for compatibility
369+
if ( error instanceof TransientException || error instanceof ClientException )
370+
{
371+
assertThat( error.getMessage(), containsString( "terminated" ) );
372+
}
373+
else
374+
{
375+
fail( "Expected either a TransientException or ClientException", error );
376+
}
377+
}
365378
}

driver/src/test/java/org/neo4j/driver/integration/TransactionBoltV3IT.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.neo4j.driver.async.AsyncSession;
3535
import org.neo4j.driver.async.AsyncTransaction;
3636
import org.neo4j.driver.async.ResultCursor;
37+
import org.neo4j.driver.exceptions.ClientException;
3738
import org.neo4j.driver.exceptions.TransientException;
3839
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
3940
import org.neo4j.driver.util.DriverExtension;
@@ -45,6 +46,7 @@
4546
import static org.junit.jupiter.api.Assertions.assertEquals;
4647
import static org.junit.jupiter.api.Assertions.assertThrows;
4748
import static org.junit.jupiter.api.Assertions.assertTimeoutPreemptively;
49+
import static org.junit.jupiter.api.Assertions.fail;
4850
import static org.neo4j.driver.internal.util.Neo4jFeature.BOLT_V3;
4951
import static org.neo4j.driver.util.TestUtil.TX_TIMEOUT_TEST_TIMEOUT;
5052
import static org.neo4j.driver.util.TestUtil.await;
@@ -123,7 +125,7 @@ void shouldSetTransactionTimeout()
123125
.build();
124126

125127
// start a new transaction with timeout and try to update the locked dummy node
126-
TransientException error = assertThrows( TransientException.class, () ->
128+
Exception error = assertThrows( Exception.class, () ->
127129
{
128130
try ( Transaction tx = session.beginTransaction( config ) )
129131
{
@@ -132,7 +134,7 @@ void shouldSetTransactionTimeout()
132134
}
133135
} );
134136

135-
assertThat( error.getMessage(), containsString( "terminated" ) );
137+
verifyValidException( error );
136138
} );
137139
}
138140
}
@@ -164,13 +166,28 @@ void shouldSetTransactionTimeoutAsync()
164166
.thenCompose( tx -> tx.runAsync( "MATCH (n:Node) SET n.prop = 2" )
165167
.thenCompose( ignore -> tx.commitAsync() ) );
166168

167-
TransientException error = assertThrows( TransientException.class, () -> await( txCommitFuture ) );
168-
assertThat( error.getMessage(), containsString( "terminated" ) );
169+
Exception error = assertThrows( Exception.class, () -> await( txCommitFuture ) );
170+
171+
verifyValidException( error );
169172
} );
170173
}
171174
}
172175
}
173176

177+
178+
private static void verifyValidException( Exception error )
179+
{
180+
// Server 4.1 corrected this exception to ClientException. Testing either here for compatibility
181+
if ( error instanceof TransientException || error instanceof ClientException )
182+
{
183+
assertThat( error.getMessage(), containsString( "terminated" ) );
184+
}
185+
else
186+
{
187+
fail( "Expected either a TransientException or ClientException", error );
188+
}
189+
}
190+
174191
private static void verifyTransactionMetadata( Map<String,Object> metadata )
175192
{
176193
try ( Session session = driver.driver().session() )

0 commit comments

Comments
 (0)