-
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.
- Loading branch information
Showing
15 changed files
with
457 additions
and
40 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
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
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
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
60 changes: 60 additions & 0 deletions
60
...ckend/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionLastBookmarks.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,60 @@ | ||
/* | ||
* 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 neo4j.org.testkit.backend.messages.requests; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import neo4j.org.testkit.backend.SessionState; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.Bookmarks; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitResponse; | ||
|
||
import java.util.Optional; | ||
|
||
import org.neo4j.driver.Bookmark; | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
public class SessionLastBookmarks implements TestkitRequest | ||
{ | ||
private SessionLastBookmarksBody data; | ||
|
||
@Override | ||
public TestkitResponse process( TestkitState testkitState ) | ||
{ | ||
return Optional.ofNullable( testkitState.getSessionStates().getOrDefault( data.sessionId, null ) ) | ||
.map( SessionState::getSession ) | ||
.map( session -> | ||
{ | ||
Bookmark bookmark = testkitState.getSessionStates().get( data.getSessionId() ).getSession().lastBookmark(); | ||
return Bookmarks.builder().data( Bookmarks.BookmarksBody.builder().bookmarks( bookmark ).build() ).build(); | ||
} ) | ||
.orElseThrow( () -> new RuntimeException( "Could not find session" ) ); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
public static class SessionLastBookmarksBody | ||
{ | ||
private String sessionId; | ||
} | ||
} |
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
113 changes: 113 additions & 0 deletions
113
...nd/src/main/java/neo4j/org/testkit/backend/messages/requests/SessionWriteTransaction.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,113 @@ | ||
/* | ||
* 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 neo4j.org.testkit.backend.messages.requests; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import neo4j.org.testkit.backend.SessionState; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.RetryableDone; | ||
import neo4j.org.testkit.backend.messages.responses.RetryableTry; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitResponse; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.neo4j.driver.Session; | ||
import org.neo4j.driver.TransactionWork; | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
public class SessionWriteTransaction implements TestkitRequest | ||
{ | ||
private SessionWriteTransactionBody data; | ||
|
||
@Override | ||
public TestkitResponse process( TestkitState testkitState ) | ||
{ | ||
return Optional.ofNullable( testkitState.getSessionStates().getOrDefault( data.getSessionId(), null ) ) | ||
.map( sessionState -> | ||
{ | ||
Session session = sessionState.getSession(); | ||
session.writeTransaction( handle( testkitState, sessionState ) ); | ||
return retryableDone(); | ||
} ).orElseThrow( () -> new RuntimeException( "Could not find session" ) ); | ||
} | ||
|
||
private TransactionWork<Integer> handle( TestkitState testkitState, SessionState sessionState ) | ||
{ | ||
return tx -> | ||
{ | ||
System.out.println( "Start" ); | ||
sessionState.setRetryableState( 0 ); | ||
String txId = testkitState.newId(); | ||
testkitState.getTransactions().put( txId, tx ); | ||
testkitState.getResponseWriter().accept( retryableTry( txId ) ); | ||
|
||
while ( true ) | ||
{ | ||
// Process commands as usual but blocking in here | ||
testkitState.getProcessor().get(); | ||
|
||
// Check if state changed on session | ||
switch ( sessionState.retryableState ) | ||
{ | ||
case 0: | ||
// Nothing happened to session state while processing command | ||
break; | ||
case 1: | ||
// Client is happy to commit | ||
return 0; | ||
case -1: | ||
// Client wants to rollback | ||
if ( !"".equals( sessionState.retryableErrorId ) ) | ||
{ | ||
throw testkitState.getErrors().get( sessionState.retryableErrorId ); | ||
} | ||
else | ||
{ | ||
throw new RuntimeException( "Error from client in retryable tx" ); | ||
} | ||
} | ||
} | ||
}; | ||
} | ||
|
||
private RetryableTry retryableTry( String txId ) | ||
{ | ||
return RetryableTry.builder().data( RetryableTry.RetryableTryBody.builder().id( txId ).build() ).build(); | ||
} | ||
|
||
private RetryableDone retryableDone() | ||
{ | ||
return RetryableDone.builder().build(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor | ||
public static class SessionWriteTransactionBody | ||
{ | ||
private String sessionId; | ||
private Map<String,String> txMeta; | ||
private String timeout; | ||
} | ||
} |
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
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
Oops, something went wrong.