-
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.
Add support for bookmark manager extension functions
The extension option `updateListener` has been updated to `bookmarkConsumer`.
- Loading branch information
1 parent
d63e21f
commit 78b3ed9
Showing
10 changed files
with
355 additions
and
34 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
39 changes: 39 additions & 0 deletions
39
...src/main/java/neo4j/org/testkit/backend/messages/requests/BookmarksConsumerCompleted.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,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 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 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 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 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 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.