Skip to content

Commit

Permalink
- Add elasticjob-lite-reachability-metadata module for nativeTest
Browse files Browse the repository at this point in the history
- Update Curator to match GraalVM Reachability Metadata
- Update Zookeeper to avoid ZOOKEEPER-4460
  • Loading branch information
linghengqian committed Sep 13, 2023
1 parent 095f558 commit cfbaa9d
Show file tree
Hide file tree
Showing 35 changed files with 1,909 additions and 133 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/graalvm-ce-nativetest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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.
#

# This workflow will build a Java project with Maven
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven

name: NativeTest with GraalVM CE

on:
push:
branches: [ master ]
paths:
- '.github/workflows/graalvm-ce-nativetest.yml'
- 'elasticjob-lite/elasticjob-lite-reachability-metadata/**'
pull_request:
branches: [ master ]
paths:
- '.github/workflows/graalvm-ce-nativetest.yml'
- 'elasticjob-lite/elasticjob-lite-reachability-metadata/**'

jobs:
build:
strategy:
matrix:
java: [ '17.0.8' ]
os: [ 'windows-latest', 'ubuntu-latest' ]
runs-on: ${{ matrix.os }}
steps:
- name: Configure Git
if: matrix.os == 'windows-latest'
run: |
git config --global core.longpaths true
- name: Set up GraalVM CE ${{ matrix.java }}
uses: graalvm/setup-graalvm@v1
with:
java-version: ${{ matrix.java }}
distribution: 'graalvm-community'
github-token: ${{ secrets.GITHUB_TOKEN }}
- name: Build NativeTest with Maven
continue-on-error: true
run: |
./mvnw -PnativeTestInElasticJob -T1C -B -e clean test
6 changes: 1 addition & 5 deletions elasticjob-cloud/elasticjob-cloud-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
4 changes: 0 additions & 4 deletions elasticjob-cloud/elasticjob-cloud-scheduler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,6 @@
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,43 +19,111 @@

import lombok.AccessLevel;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.framework.imps.CuratorFrameworkState;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.test.TestingServer;
import org.apache.shardingsphere.elasticjob.reg.exception.RegExceptionHandler;
import org.apache.zookeeper.KeeperException;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.concurrent.TimeUnit;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Slf4j
public final class EmbedTestingServer {

private static final int PORT = 10181;

private static volatile TestingServer testingServer;


private static final Object INIT_LOCK = new Object();

/**
* Start the embed server.
* Start embed zookeeper server.
*/
public static void start() {
if (null != testingServer) {
log.info("Embed zookeeper server already exists 1, on {}", testingServer.getConnectString());
return;
}
log.info("Starting embed zookeeper server...");
synchronized (INIT_LOCK) {
if (null != testingServer) {
log.info("Embed zookeeper server already exists 2, on {}", testingServer.getConnectString());
return;
}
start0();
waitTestingServerReady();
}
}

private static void start0() {
try {
testingServer = new TestingServer(PORT, new File(String.format("target/test_zk_data/%s/", System.nanoTime())));
testingServer = new TestingServer(PORT, true);
// CHECKSTYLE:OFF
} catch (final Exception ex) {
// CHECKSTYLE:ON
RegExceptionHandler.handleException(ex);
if (!isIgnoredException(ex)) {
throw new RuntimeException(ex);
} else {
log.warn("Start embed zookeeper server got exception: {}", ex.getMessage());
}
} finally {
Runtime.getRuntime().addShutdownHook(new Thread(() -> {
try {
testingServer.close();
} catch (final IOException ex) {
RegExceptionHandler.handleException(ex);
} catch (final IOException ignored) {
}
log.info("Close embed zookeeper server done");
}));
}
}


private static void waitTestingServerReady() {
int maxRetries = 60;
try (CuratorFramework client = buildCuratorClient()) {
client.start();
int round = 0;
while (round < maxRetries) {
try {
if (client.getZookeeperClient().isConnected()) {
log.info("client is connected");
break;
}
if (client.blockUntilConnected(500, TimeUnit.MILLISECONDS)) {
CuratorFrameworkState state = client.getState();
Collection<String> childrenKeys = client.getChildren().forPath("/");
log.info("TestingServer connected, state={}, childrenKeys={}", state, childrenKeys);
break;
}
// CHECKSTYLE:OFF
} catch (final Exception ignored) {
// CHECKSTYLE:ON
}
++round;
}
}
}

private static CuratorFramework buildCuratorClient() {
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder();
int retryIntervalMilliseconds = 500;
int maxRetries = 3;
builder.connectString(getConnectionString())
.retryPolicy(new ExponentialBackoffRetry(retryIntervalMilliseconds, maxRetries, retryIntervalMilliseconds * maxRetries))
.namespace("test");
builder.sessionTimeoutMs(60 * 1000);
builder.connectionTimeoutMs(500);
return builder.build();
}

private static boolean isIgnoredException(final Throwable cause) {
return cause instanceof KeeperException.ConnectionLossException || cause instanceof KeeperException.NoNodeException || cause instanceof KeeperException.NodeExistsException;
}

/**
* Get the connection string.
*
Expand All @@ -65,4 +133,3 @@ public static String getConnectionString() {
return "localhost:" + PORT;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,9 @@ The text of each license is the standard Apache 2.0 license.
commons-lang3 3.4: https://github.com/apache/commons-lang, Apache 2.0
commons-logging 1.2: https://github.com/apache/commons-logging, Apache 2.0
commons-pool2 2.8.1: https://github.com/apache/commons-pool, Apache 2.0
curator-client 5.1.0: https://github.com/apache/curator, Apache 2.0
curator-framework 5.1.0: https://github.com/apache/curator, Apache 2.0
curator-recipes 5.1.0: https://github.com/apache/curator, Apache 2.0
curator-client 5.5.0: https://github.com/apache/curator, Apache 2.0
curator-framework 5.5.0: https://github.com/apache/curator, Apache 2.0
curator-recipes 5.5.0: https://github.com/apache/curator, Apache 2.0
error_prone_annotations 2.3.4: https://github.com/google/error-prone, Apache 2.0
failureaccess 1.0.1:https://github.com/google/guava, Apache 2.0
fenzo-core 0.11.1: https://github.com/Netflix/Fenzo, Apache 2.0
Expand All @@ -252,8 +252,8 @@ The text of each license is the standard Apache 2.0 license.
netty-transport-native-unix-common 4.1.45.Final: https://github.com/netty, Apache 2.0
quartz 2.3.2: https://github.com/quartz-scheduler/quartz, Apache 2.0
snakeyaml 1.26: http://www.snakeyaml.org, Apache 2.0
zookeeper 3.6.0: https://github.com/apache/zookeeper, Apache 2.0
zookeeper-jute 3.6.0: https://github.com/apache/zookeeper, Apache 2.0
zookeeper 3.9.0: https://github.com/apache/zookeeper, Apache 2.0
zookeeper-jute 3.9.0: https://github.com/apache/zookeeper, Apache 2.0

========================================================================
EPL licenses
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,5 @@
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
5 changes: 0 additions & 5 deletions elasticjob-infra/elasticjob-infra-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,5 @@
<artifactId>logback-classic</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@
<artifactId>lombok</artifactId>
</dependency>

<dependency>
<groupId>org.apache.curator</groupId>
<artifactId>curator-test</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
Loading

0 comments on commit cfbaa9d

Please sign in to comment.