Skip to content

Commit

Permalink
Add the java client external kubernetes test
Browse files Browse the repository at this point in the history
  • Loading branch information
srknzl committed Aug 26, 2024
1 parent ee88659 commit 05dd0ba
Show file tree
Hide file tree
Showing 4 changed files with 174 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/KubernetesExternalClients.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ on:
description: Default is hazelcast, but if you would like to run the workflow with your forked repo, set your github username
required: true
default: hazelcast
java_client_run:
description: Java Client (Standard), (old name is Java thin client) = Set the branch name of client to run, otherwise set it as 'no' in order to skip running this client
required: true
default: develop
python_run:
description: PYTHON = Set the branch name of client to run, otherwise set it as 'no' in order to skip running this client
required: true
Expand Down Expand Up @@ -154,6 +158,53 @@ jobs:
go run main.go &> output.txt && tail -n 20 output.txt &> last20lines.txt
cat last20lines.txt
if [ $(grep -o 'Current map size:' last20lines.txt | wc -l) != $"20" ]; then exit 1; fi
run_java:
name: Run Java Client (Standard) compatibility test
needs: [create-gke-cluster]
if: ${{ github.event.inputs.java_client_run != 'no' }}
runs-on: ubuntu-latest

steps:
- name: "Setup JRE"
uses: "actions/setup-java@v2"
with:
distribution: "zulu"
java-version: "17"

- name: Checkout to scripts
uses: actions/checkout@v4

- name: Checkout the java client repo
uses: actions/checkout@v4
with:
repository: ${{ github.event.inputs.organization_name }}/hazelcast-java-client
path: KubernetesExternalClients/java/clientSourceCode
ref: ${{ github.event.inputs.java_client_run }}

- name: "Setup Local Maven Cache"
uses: actions/cache@v4
with:
path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
- name: "Build OS"
working-directory: KubernetesExternalClients/java/clientSourceCode
run: |
chmod +x mvnw
HAZELCAST_VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "HAZELCAST_VERSION=${HAZELCAST_VERSION}" >> $GITHUB_ENV
./mvnw -B -V -e clean install -DskipTests
- name: Run test
run: |
cd KubernetesExternalClients/java
sed -i "s/<EXTERNAL-IP>/${{needs.create-gke-cluster.outputs.external-ip}}/g" src/main/java/KubernetesExternalTest.java
mvn exec:java &> output.txt && tail -n 20 output.txt &> last20lines.txt
cat last20lines.txt
if [ $(grep -o 'Current map size:' last20lines.txt | wc -l) != $"20" ]; then exit 1; fi
#TODO: More reliabe verification

Expand Down
38 changes: 38 additions & 0 deletions KubernetesExternalClients/java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
43 changes: 43 additions & 0 deletions KubernetesExternalClients/java/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.hazelcast</groupId>
<artifactId>kubernetes-external-test-java</artifactId>
<version>1.0-SNAPSHOT</version>
<name>kubernetes-external-test-java</name>

<properties>
<jdk.version>17</jdk.version>
<maven.compiler.release>${jdk.version}</maven.compiler.release>
<maven.compiler.source>${jdk.version}</maven.compiler.source>
<maven.compiler.target>${jdk.version}</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-enterprise-java-client</artifactId>
<version>5.5.1-SNAPSHOT</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.4.1</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>KubernetesExternalTest</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import com.hazelcast.client.HazelcastClient;
import com.hazelcast.client.config.ClientConfig;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.map.IMap;

import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
import java.util.logging.Logger;

/**
* Kubernetes external test for thin java client
*/
public class KubernetesExternalTest {

private static final Logger LOGGER = Logger.getLogger(KubernetesExternalTest.class.getName());

public static void main( String[] args ) throws InterruptedException {
String externalIp = "<EXTERNAL-IP>";

ClientConfig clientConfig = new ClientConfig();
clientConfig.getNetworkConfig().addAddress(externalIp);

HazelcastInstance client = HazelcastClient.newHazelcastClient(clientConfig);
LOGGER.info("Successful connection!");

IMap<String, String> map = client.getMap("mapForJava");
LOGGER.info("Starting to fill the map with random entries.");

Random random = ThreadLocalRandom.current();
for (int i = 0; i < 120; i++) {
int randomKey = random.nextInt(100000);
try {
map.put("key" + randomKey, "value" + randomKey);
} catch (Throwable exc) {
LOGGER.warning("Put operation failed: " + exc);
}
int size = map.size();
LOGGER.info("Current map size: " + size);
Thread.sleep(1000);
}
}
}

0 comments on commit 05dd0ba

Please sign in to comment.