-
Notifications
You must be signed in to change notification settings - Fork 157
Add support for bookmark manager extension functions #1290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
39 changes: 39 additions & 0 deletions
39
...src/main/java/neo4j/org/testkit/backend/messages/requests/BookmarksConsumerCompleted.java
This file contains hidden or 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,39 @@ | ||
/* | ||
* Copyright (c) "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.Setter; | ||
|
||
@Setter | ||
@Getter | ||
public class BookmarksConsumerCompleted implements TestkitCallbackResult { | ||
private BookmarksConsumerCompletedBody data; | ||
|
||
@Override | ||
public String getCallbackId() { | ||
return data.getRequestId(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class BookmarksConsumerCompletedBody { | ||
private String requestId; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...src/main/java/neo4j/org/testkit/backend/messages/requests/BookmarksSupplierCompleted.java
This file contains hidden or 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,41 @@ | ||
/* | ||
* Copyright (c) "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 java.util.Set; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Setter | ||
@Getter | ||
public class BookmarksSupplierCompleted implements TestkitCallbackResult { | ||
private BookmarksSupplierCompletedBody data; | ||
|
||
@Override | ||
public String getCallbackId() { | ||
return data.getRequestId(); | ||
} | ||
|
||
@Setter | ||
@Getter | ||
public static class BookmarksSupplierCompletedBody { | ||
private String requestId; | ||
private Set<String> bookmarks; | ||
} | ||
} |
This file contains hidden or 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
54 changes: 54 additions & 0 deletions
54
...nd/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitBookmarkConsumer.java
This file contains hidden or 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,54 @@ | ||
/* | ||
* Copyright (c) "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 java.util.Set; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.BiFunction; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.BookmarksConsumerRequest; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitCallback; | ||
import org.neo4j.driver.Bookmark; | ||
|
||
@RequiredArgsConstructor | ||
class TestkitBookmarkConsumer implements BiConsumer<String, Set<Bookmark>> { | ||
private final TestkitState testkitState; | ||
private final BiFunction<TestkitState, TestkitCallback, CompletionStage<TestkitCallbackResult>> dispatchFunction; | ||
|
||
@Override | ||
public void accept(String database, Set<Bookmark> bookmarks) { | ||
var callbackId = testkitState.newId(); | ||
var body = BookmarksConsumerRequest.BookmarksConsumerRequestBody.builder() | ||
.id(callbackId) | ||
.database(database) | ||
.bookmarks(bookmarks.stream().map(Bookmark::value).collect(Collectors.toUnmodifiableSet())) | ||
.build(); | ||
var callback = BookmarksConsumerRequest.builder().data(body).build(); | ||
|
||
var callbackStage = dispatchFunction.apply(testkitState, callback); | ||
try { | ||
callbackStage.toCompletableFuture().get(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Unexpected failure during Testkit callback", e); | ||
} | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...nd/src/main/java/neo4j/org/testkit/backend/messages/requests/TestkitBookmarkSupplier.java
This file contains hidden or 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,71 @@ | ||
/* | ||
* Copyright (c) "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 java.util.Set; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
import lombok.RequiredArgsConstructor; | ||
import neo4j.org.testkit.backend.TestkitState; | ||
import neo4j.org.testkit.backend.messages.responses.BookmarksSupplierRequest; | ||
import neo4j.org.testkit.backend.messages.responses.TestkitCallback; | ||
import org.neo4j.driver.Bookmark; | ||
import org.neo4j.driver.BookmarkSupplier; | ||
|
||
@RequiredArgsConstructor | ||
class TestkitBookmarkSupplier implements BookmarkSupplier { | ||
private final TestkitState testkitState; | ||
private final BiFunction<TestkitState, TestkitCallback, CompletionStage<TestkitCallbackResult>> dispatchFunction; | ||
|
||
@Override | ||
public Set<Bookmark> getBookmarks(String database) { | ||
return getBookmarksFromTestkit(() -> database); | ||
} | ||
|
||
@Override | ||
public Set<Bookmark> getAllBookmarks() { | ||
return getBookmarksFromTestkit(null); | ||
} | ||
|
||
private Set<Bookmark> getBookmarksFromTestkit(Supplier<String> databaseSupplier) { | ||
var callbackId = testkitState.newId(); | ||
var bodyBuilder = | ||
BookmarksSupplierRequest.BookmarksSupplierRequestBody.builder().id(callbackId); | ||
if (databaseSupplier != null) { | ||
bodyBuilder = bodyBuilder.database(databaseSupplier.get()); | ||
} | ||
var callback = | ||
BookmarksSupplierRequest.builder().data(bodyBuilder.build()).build(); | ||
|
||
var callbackStage = dispatchFunction.apply(testkitState, callback); | ||
BookmarksSupplierCompleted resolutionCompleted; | ||
try { | ||
resolutionCompleted = (BookmarksSupplierCompleted) | ||
callbackStage.toCompletableFuture().get(); | ||
} catch (Exception e) { | ||
throw new RuntimeException("Unexpected failure during Testkit callback", e); | ||
} | ||
|
||
return resolutionCompleted.getData().getBookmarks().stream() | ||
.map(Bookmark::from) | ||
.collect(Collectors.toUnmodifiableSet()); | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.