-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updating stress tests to improve stability when testing clustered setup
- Loading branch information
1 parent
d44eadc
commit 57eb7ea
Showing
13 changed files
with
611 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
driver/src/test/java/org/neo4j/driver/stress/AsyncFailingQueryWithRetries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver.stress; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.neo4j.driver.AccessMode; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.async.AsyncSession; | ||
import org.neo4j.driver.async.ResultCursor; | ||
import org.neo4j.driver.internal.util.Futures; | ||
|
||
import static org.hamcrest.Matchers.is; | ||
import static org.hamcrest.junit.MatcherAssert.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.neo4j.driver.internal.util.Matchers.arithmeticError; | ||
|
||
public class AsyncFailingQueryWithRetries<C extends AbstractContext> extends AbstractAsyncQuery<C> | ||
{ | ||
public AsyncFailingQueryWithRetries( Driver driver ) | ||
{ | ||
super( driver, false ); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> execute( C context ) | ||
{ | ||
AsyncSession session = newSession( AccessMode.READ, context ); | ||
|
||
return session.readTransactionAsync( tx -> tx.runAsync( "UNWIND [10, 5, 0] AS x RETURN 10 / x" ) | ||
.thenCompose( ResultCursor::listAsync ) | ||
.handle( ( records, error ) -> | ||
{ | ||
session.closeAsync(); | ||
|
||
assertNull( records ); | ||
Throwable cause = Futures.completionExceptionCause( error ); | ||
assertThat( cause, is( arithmeticError() ) ); | ||
|
||
return null; | ||
} )); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
driver/src/test/java/org/neo4j/driver/stress/AsyncReadQueryWithRetries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver.stress; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.neo4j.driver.AccessMode; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.Record; | ||
import org.neo4j.driver.async.AsyncSession; | ||
import org.neo4j.driver.async.ResultCursor; | ||
import org.neo4j.driver.summary.ResultSummary; | ||
import org.neo4j.driver.types.Node; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class AsyncReadQueryWithRetries<C extends AbstractContext> extends AbstractAsyncQuery<C> | ||
{ | ||
public AsyncReadQueryWithRetries( Driver driver, boolean useBookmark ) | ||
{ | ||
super( driver, useBookmark ); | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> execute( C context ) | ||
{ | ||
AsyncSession session = newSession( AccessMode.READ, context ); | ||
|
||
CompletionStage<ResultSummary> queryFinished = session.readTransactionAsync( | ||
tx -> tx.runAsync( "MATCH (n) RETURN n LIMIT 1" ) | ||
.thenCompose( | ||
cursor -> cursor.nextAsync() | ||
.thenCompose( record -> processAndGetSummary( record, cursor ) ) ) ); | ||
|
||
queryFinished.whenComplete( ( summary, error ) -> | ||
{ | ||
if ( summary != null ) | ||
{ | ||
context.readCompleted( summary ); | ||
} | ||
session.closeAsync(); | ||
} ); | ||
|
||
return queryFinished.thenApply( summary -> null ); | ||
} | ||
|
||
private CompletionStage<ResultSummary> processAndGetSummary( Record record, ResultCursor cursor ) | ||
{ | ||
if ( record != null ) | ||
{ | ||
Node node = record.get( 0 ).asNode(); | ||
assertNotNull( node ); | ||
} | ||
return cursor.consumeAsync(); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
driver/src/test/java/org/neo4j/driver/stress/AsyncWriteQueryWithRetries.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (c) 2002-2020 "Neo4j," | ||
* Neo4j Sweden AB [http://neo4j.com] | ||
* | ||
* This file is part of Neo4j. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.neo4j.driver.stress; | ||
|
||
import java.util.concurrent.CompletionStage; | ||
|
||
import org.neo4j.driver.AccessMode; | ||
import org.neo4j.driver.Driver; | ||
import org.neo4j.driver.async.AsyncSession; | ||
import org.neo4j.driver.async.ResultCursor; | ||
import org.neo4j.driver.internal.util.Futures; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
public class AsyncWriteQueryWithRetries<C extends AbstractContext> extends AbstractAsyncQuery<C> | ||
{ | ||
private final AbstractStressTestBase<C> stressTest; | ||
|
||
public AsyncWriteQueryWithRetries( AbstractStressTestBase<C> stressTest, Driver driver, boolean useBookmark ) | ||
{ | ||
super( driver, useBookmark ); | ||
this.stressTest = stressTest; | ||
} | ||
|
||
@Override | ||
public CompletionStage<Void> execute( C context ) | ||
{ | ||
AsyncSession session = newSession( AccessMode.WRITE, context ); | ||
|
||
return session.writeTransactionAsync( | ||
tx -> tx.runAsync( "CREATE ()" ) | ||
.thenCompose( ResultCursor::consumeAsync ) ) | ||
.handle( ( summary, error ) -> | ||
{ | ||
session.closeAsync(); | ||
|
||
if ( error != null ) | ||
{ | ||
handleError( Futures.completionExceptionCause( error ), context ); | ||
} | ||
else | ||
{ | ||
context.setBookmark( session.lastBookmark() ); | ||
assertEquals( 1, summary.counters().nodesCreated() ); | ||
context.nodeCreated(); | ||
} | ||
|
||
return null; | ||
} ); | ||
} | ||
|
||
private void handleError( Throwable error, C context ) | ||
{ | ||
if ( !stressTest.handleWriteFailure( error, context ) ) | ||
{ | ||
throw new RuntimeException( error ); | ||
} | ||
} | ||
} |
Oops, something went wrong.