Skip to content
Merged
46 changes: 42 additions & 4 deletions .github/workflows/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ jobs:
engine: ${{ fromJson(needs.load-engine-matrix.outputs.matrix) }}
host:
- {
OS: ubuntu,
RUNNER: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu
}
OS: ubuntu,
RUNNER: ubuntu-latest,
TARGET: x86_64-unknown-linux-gnu,
}
# - {
# OS: macos,
# RUNNER: macos-latest,
Expand Down Expand Up @@ -195,3 +195,41 @@ jobs:
with:
cargo-toml-folder: ./java
name: lint java rust

test-modules:
if: github.repository_owner == 'valkey-io'
name: Running Module Tests
runs-on: [self-hosted, linux, ARM64]
timeout-minutes: 15
steps:
- name: Setup self-hosted runner access
run: sudo chown -R $USER:$USER /home/ubuntu/actions-runner/_work/valkey-glide

- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: 17

- name: Install protoc (protobuf)
uses: arduino/setup-protoc@v3
with:
version: "26.1"
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Test java wrapper
working-directory: java
run: ./gradlew :integTest:modulesTest -Dcluster-endpoints=${{ secrets.MEMDB_MODULES_ENDPOINT }} -Dtls=true

- name: Upload test reports
if: always()
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: test-reports-modules
path: |
java/integTest/build/reports/**
21 changes: 21 additions & 0 deletions java/DEVELOPER.md
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ To run end-to-end tests, use the following command:
./gradlew :integTest:test
```

IT suite start the server for testing - standalone and cluster installation using `cluster_manager` script.
By default, it starts servers without TLS; to activate TLS add `-Dtls=true` to the command line:
```bash
./gradlew :integTest:test -Dtls=true
```

To run a single test, use the following command:
```bash
./gradlew :integTest:test --tests '*.functionLoad_and_functionList' --rerun
Expand All @@ -242,6 +248,21 @@ To run one class, use the following command:
./gradlew :client:test --tests 'TransactionTests' --rerun
```

To run IT tests against an existing cluster and/or standalone endpoint, use:
```bash
./gradlew :integTest:test -Dcluster-endpoints=localhost:7000 -Dstandalone-endpoints=localhost:6379
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we have only 1 cluster endpoint?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is an example. Actually, glide core can detect (and connection to) all cluster nodes having address of only one of them.

```

If those endpoints use TLS, add `-Dtls=true` (applied to both endpoints):
```bash
./gradlew :integTest:test -Dcluster-endpoints=localhost:7000 -Dstandalone-endpoints=localhost:6379 -Dtls=true
```

You can combine this with test filter as well:
```bash
./gradlew :integTest:test -Dcluster-endpoints=localhost:7000 -Dstandalone-endpoints=localhost:6379 --tests 'TransactionTests' -Dtls=true
```

### Generate files
To (re)generate protobuf code, use the following command:

Expand Down
74 changes: 50 additions & 24 deletions java/integTest/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,18 @@ dependencies {
testAnnotationProcessor 'org.projectlombok:lombok:1.18.32'
}

def standalonePorts = []
def clusterPorts = []
def standaloneHosts = ''
def clusterHosts = ''

ext {
extractPortsFromClusterManagerOutput = { String output ->
var res = []
extractAddressesFromClusterManagerOutput = { String output ->
for (def line : output.split("\n")) {
if (!line.startsWith("CLUSTER_NODES="))
continue

def addresses = line.split("=")[1].split(",")
for (def address : addresses)
res << address.split(":")[1]
return line.split("=")[1]
}
return res
return ''
}
}

Expand All @@ -69,26 +66,38 @@ tasks.register('clearDirs', Delete) {

tasks.register('startCluster') {
doLast {
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir "${project.rootDir}/../utils"
commandLine 'python3', 'cluster_manager.py', 'start', '--cluster-mode'
standardOutput = os
if (System.getProperty("cluster-endpoints") == null) {
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir "${project.rootDir}/../utils"
def args = ['python3', 'cluster_manager.py', 'start', '--cluster-mode']
if (System.getProperty("tls") == 'true') args.add(2, '--tls')
commandLine args
standardOutput = os
}
clusterHosts = extractAddressesFromClusterManagerOutput(os.toString())
}
clusterPorts = extractPortsFromClusterManagerOutput(os.toString())
} else {
clusterHosts = System.getProperty("cluster-endpoints")
}
}
}

tasks.register('startStandalone') {
doLast {
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir "${project.rootDir}/../utils"
commandLine 'python3', 'cluster_manager.py', 'start', '-r', '0'
standardOutput = os
if (System.getProperty("standalone-endpoints") == null) {
new ByteArrayOutputStream().withStream { os ->
exec {
workingDir "${project.rootDir}/../utils"
def args = ['python3', 'cluster_manager.py', 'start', '-r', '0']
if (System.getProperty("tls") == 'true') args.add(2, '--tls')
commandLine args
standardOutput = os
}
standaloneHosts = extractAddressesFromClusterManagerOutput(os.toString())
}
standalonePorts = extractPortsFromClusterManagerOutput(os.toString())
} else {
standaloneHosts = System.getProperty("standalone-endpoints")
}
}
}
Expand All @@ -103,10 +112,11 @@ test.dependsOn ':client:buildRustRelease'

tasks.withType(Test) {
doFirst {
println "Cluster ports = ${clusterPorts}"
println "Standalone ports = ${standalonePorts}"
systemProperty 'test.server.standalone.ports', standalonePorts.join(',')
systemProperty 'test.server.cluster.ports', clusterPorts.join(',')
println "Cluster hosts = ${clusterHosts}"
println "Standalone hosts = ${standaloneHosts}"
systemProperty 'test.server.standalone', standaloneHosts
systemProperty 'test.server.cluster', clusterHosts
systemProperty 'test.server.tls', System.getProperty("tls")
}

testLogging {
Expand All @@ -122,3 +132,19 @@ tasks.withType(Test) {
logger.quiet "${desc.className}.${desc.name}: ${result.resultType} ${(result.getEndTime() - result.getStartTime())/1000}s"
}
}

test {
filter {
excludeTestsMatching 'glide.modules.*'
}
}

tasks.register('modulesTest', Test) {
doFirst {
clusterHosts = System.getProperty("cluster-endpoints")
}

filter {
includeTestsMatching 'glide.modules.*'
}
}
23 changes: 7 additions & 16 deletions java/integTest/src/test/java/glide/ConnectionTests.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide;

import static glide.TestUtilities.commonClientConfig;
import static glide.TestUtilities.commonClusterClientConfig;

import glide.api.GlideClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.GlideClusterClient;
import lombok.SneakyThrows;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -14,25 +16,14 @@ public class ConnectionTests {
@Test
@SneakyThrows
public void basic_client() {
var regularClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get();
var regularClient = GlideClient.createClient(commonClientConfig().build()).get();
regularClient.close();
}

@Test
@SneakyThrows
public void cluster_client() {
var regularClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(NodeAddress.builder().port(TestConfiguration.CLUSTER_PORTS[0]).build())
.build())
.get();
regularClient.close();
var clusterClient = GlideClusterClient.createClient(commonClusterClientConfig().build()).get();
clusterClient.close();
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide;

import static glide.TestUtilities.commonClientConfig;
import static org.junit.jupiter.api.Assertions.assertEquals;

import glide.api.GlideClient;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.connectors.resources.EpollResource;
import glide.connectors.resources.KQueuePoolResource;
import glide.connectors.resources.Platform;
Expand Down Expand Up @@ -33,11 +32,7 @@ public void standalone_client_with_custom_threadPoolResource() {

var regularClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.threadPoolResource(customThreadPoolResource)
.build())
commonClientConfig().threadPoolResource(customThreadPoolResource).build())
.get(10, TimeUnit.SECONDS);

String payload = (String) regularClient.customCommand(new String[] {"PING"}).get();
Expand Down
17 changes: 3 additions & 14 deletions java/integTest/src/test/java/glide/ErrorHandlingTests.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide;

import static glide.TestUtilities.commonClientConfig;
import static org.junit.jupiter.api.Assertions.assertAll;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
Expand Down Expand Up @@ -39,13 +40,7 @@ public void basic_client_tries_to_connect_to_wrong_address() {
@Test
@SneakyThrows
public void basic_client_tries_wrong_command() {
try (var regularClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get()) {
try (var regularClient = GlideClient.createClient(commonClientConfig().build()).get()) {
var exception =
assertThrows(
ExecutionException.class,
Expand All @@ -59,13 +54,7 @@ public void basic_client_tries_wrong_command() {
@Test
@SneakyThrows
public void basic_client_tries_wrong_command_arguments() {
try (var regularClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(
NodeAddress.builder().port(TestConfiguration.STANDALONE_PORTS[0]).build())
.build())
.get()) {
try (var regularClient = GlideClient.createClient(commonClientConfig().build()).get()) {
var exception =
assertThrows(
ExecutionException.class,
Expand Down
18 changes: 2 additions & 16 deletions java/integTest/src/test/java/glide/SharedCommandTests.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
/** Copyright Valkey GLIDE Project Contributors - SPDX Identifier: Apache-2.0 */
package glide;

import static glide.TestConfiguration.CLUSTER_PORTS;
import static glide.TestConfiguration.SERVER_VERSION;
import static glide.TestConfiguration.STANDALONE_PORTS;
import static glide.TestUtilities.assertDeepEquals;
import static glide.TestUtilities.commonClientConfig;
import static glide.TestUtilities.commonClusterClientConfig;
Expand Down Expand Up @@ -103,9 +101,6 @@
import glide.api.models.commands.stream.StreamReadOptions;
import glide.api.models.commands.stream.StreamTrimOptions.MaxLen;
import glide.api.models.commands.stream.StreamTrimOptions.MinId;
import glide.api.models.configuration.GlideClientConfiguration;
import glide.api.models.configuration.GlideClusterClientConfiguration;
import glide.api.models.configuration.NodeAddress;
import glide.api.models.exceptions.RequestException;
import java.time.Instant;
import java.util.Arrays;
Expand Down Expand Up @@ -149,19 +144,10 @@ public class SharedCommandTests {
@SneakyThrows
public static void init() {
standaloneClient =
GlideClient.createClient(
GlideClientConfiguration.builder()
.address(NodeAddress.builder().port(STANDALONE_PORTS[0]).build())
.requestTimeout(5000)
.build())
.get();
GlideClient.createClient(commonClientConfig().requestTimeout(5000).build()).get();

clusterClient =
GlideClusterClient.createClient(
GlideClusterClientConfiguration.builder()
.address(NodeAddress.builder().port(CLUSTER_PORTS[0]).build())
.requestTimeout(5000)
.build())
GlideClusterClient.createClient(commonClusterClientConfig().requestTimeout(5000).build())
.get();

clients = List.of(Arguments.of(standaloneClient), Arguments.of(clusterClient));
Expand Down
Loading