-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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 Dev Services inside Neo4j module.
This change adds one additional processor that conditionally (when docker is working and Neo4j is not reachable on the default address) starts up a Neo4j Test container based on the latest image. Tests have been added that will be executed when docker is enabled. The existing functional integration tests won't be affected as they use explicit configuration.
- Loading branch information
1 parent
879c866
commit 6edf61c
Showing
9 changed files
with
519 additions
and
1 deletion.
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
77 changes: 77 additions & 0 deletions
77
extensions/neo4j/deployment/src/main/java/io/quarkus/neo4j/deployment/BoltHandshaker.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,77 @@ | ||
package io.quarkus.neo4j.deployment; | ||
|
||
import java.io.DataInputStream; | ||
import java.io.DataOutputStream; | ||
import java.io.IOException; | ||
import java.net.InetSocketAddress; | ||
import java.net.Socket; | ||
import java.time.Duration; | ||
|
||
/** | ||
* This implements the protocol version negotiation of bolt. Testing to see if in address will respond to this is a | ||
* quick way to find out if it's a running bolt server. | ||
* <p> | ||
* This class first appeared in https://github.com/michael-simons/junit-jupiter-causal-cluster-testcontainer-extension | ||
* by Andrew Jefferson and Michael Simons | ||
*/ | ||
final class BoltHandshaker { | ||
|
||
private static final int magicToken = 1616949271; | ||
|
||
// Versions message that cannot be matched because it is all zeros. | ||
private static final byte[] versionsMessage = { | ||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, | ||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, | ||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, | ||
(byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00 | ||
}; | ||
|
||
private final String address; | ||
private final int port; | ||
|
||
BoltHandshaker(String address, int port) { | ||
this.address = address; | ||
this.port = port; | ||
} | ||
|
||
private boolean doBoltHandshake(String address, int port, int timeoutMillis) { | ||
|
||
try (Socket socket = new Socket()) { | ||
|
||
// Set the socket timeout for blocking operations | ||
socket.setSoTimeout(timeoutMillis); | ||
|
||
// Connects this socket to the server (also with the specified timeout value). | ||
socket.connect(new InetSocketAddress(address, port), timeoutMillis); | ||
|
||
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream()); | ||
DataInputStream dIn = new DataInputStream(socket.getInputStream()); | ||
|
||
// Send magic token (0x6060B017) | ||
dOut.writeInt(magicToken); | ||
dOut.flush(); | ||
|
||
// Send 4 supported versions | ||
// Except we don't support any versions and communicate that by sending all zeros | ||
dOut.write(versionsMessage); | ||
dOut.flush(); | ||
|
||
// Receive agreed version | ||
// It should be 0 because there are no possible versions we can agree on | ||
int response = dIn.readInt(); | ||
assert response == 0; | ||
|
||
// Because we cannot agree on a version the server should close its side of the connection | ||
// resulting in EOF (-1) on all subsequent reads. | ||
return dIn.read() == -1; | ||
} catch (IOException exception) { | ||
// Return false if handshake fails | ||
return false; | ||
} | ||
} | ||
|
||
boolean isBoltPortReachable(Duration timeout) { | ||
int timeoutMillis = Math.toIntExact(timeout.toMillis()); | ||
return doBoltHandshake(address, port, timeoutMillis); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...eo4j/deployment/src/main/java/io/quarkus/neo4j/deployment/DevServicesBuildTimeConfig.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,32 @@ | ||
package io.quarkus.neo4j.deployment; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import io.quarkus.runtime.annotations.ConfigGroup; | ||
import io.quarkus.runtime.annotations.ConfigItem; | ||
|
||
@ConfigGroup | ||
public class DevServicesBuildTimeConfig { | ||
|
||
/** | ||
* If DevServices has been explicitly enabled or disabled. DevServices is generally enabled | ||
* by default, unless there is an existing configuration present. | ||
* When DevServices is enabled Quarkus will attempt to automatically configure and start | ||
* a database when running in Dev or Test mode. | ||
*/ | ||
@ConfigItem | ||
public Optional<Boolean> enabled = Optional.empty(); | ||
|
||
/** | ||
* The container image name to use, for container based DevServices providers. | ||
*/ | ||
@ConfigItem(defaultValue = "neo4j:4.3") | ||
public String imageName; | ||
|
||
/** | ||
* Additional environment entries that can be added to the container before its start. | ||
*/ | ||
@ConfigItem | ||
public Map<String, String> additionalEnv; | ||
} |
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
6 changes: 6 additions & 0 deletions
6
.../neo4j/deployment/src/main/java/io/quarkus/neo4j/deployment/Neo4jDevServiceBuildItem.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,6 @@ | ||
package io.quarkus.neo4j.deployment; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class Neo4jDevServiceBuildItem extends SimpleBuildItem { | ||
} |
Oops, something went wrong.