From 7071848bd6ea3f3ea58da20ff12a06274d029c6e Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 11:13:19 +0800 Subject: [PATCH 01/11] feat(ci): use github action services --- .github/workflows/integration-test.yml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index fba7b164cb..e6e282e81c 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -197,6 +197,21 @@ jobs: name: CosId Mongo Test needs: [ cosid-core-test ] runs-on: ubuntu-latest + env: + CI: '' + services: + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + options: >- + --health-cmd "mongo --eval \"printjson(db.serverStatus())\"" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 27017:27017 steps: - name: Checkout uses: actions/checkout@master From c27a99c6065d0bdb85c3ef87d7c82c6c114dcc0c Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 11:18:22 +0800 Subject: [PATCH 02/11] feat(ci): use github action services --- .github/workflows/integration-test.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index e6e282e81c..7070d20f91 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -205,11 +205,6 @@ jobs: env: MONGO_INITDB_ROOT_USERNAME: root MONGO_INITDB_ROOT_PASSWORD: root - options: >- - --health-cmd "mongo --eval \"printjson(db.serverStatus())\"" - --health-interval 10s - --health-timeout 5s - --health-retries 5 ports: - 27017:27017 steps: From 68f7fe0192b3d0b3c092d4fec859f2e2199d2264 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 11:29:42 +0800 Subject: [PATCH 03/11] feat(ci): use github action services --- .github/workflows/codecov.yml | 8 +++++++- .github/workflows/integration-test.yml | 19 +++++++++++++++++-- .../cosid/test/container/MongoLauncher.java | 15 +-------------- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 22e7321615..1e7e7ae518 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -35,7 +35,13 @@ jobs: --health-retries 5 ports: - 6379:6379 - + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + ports: + - 27017:27017 steps: - name: Start Mysql run: sudo /etc/init.d/mysql start diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 7070d20f91..37f67060e6 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -197,8 +197,6 @@ jobs: name: CosId Mongo Test needs: [ cosid-core-test ] runs-on: ubuntu-latest - env: - CI: '' services: mongo: image: mongo @@ -293,6 +291,23 @@ jobs: name: CosId Spring Boot Starter Test needs: [ cosid-core-test ] runs-on: ubuntu-latest + services: + redis: + image: redis + options: >- + --health-cmd "redis-cli ping" + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 6379:6379 + mongo: + image: mongo + env: + MONGO_INITDB_ROOT_USERNAME: root + MONGO_INITDB_ROOT_PASSWORD: root + ports: + - 27017:27017 steps: - name: Start Mysql run: sudo /etc/init.d/mysql start diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java index 5d0d607386..fc8c7e3cae 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/container/MongoLauncher.java @@ -13,24 +13,11 @@ package me.ahoo.cosid.test.container; - -import org.testcontainers.containers.MongoDBContainer; -import org.testcontainers.shaded.com.google.common.base.Strings; -import org.testcontainers.utility.DockerImageName; - public class MongoLauncher { private static final String CONNECTION_OPTIONS = "/?connectTimeoutMS=300000&maxIdleTimeMS=300000"; private static final String DEV_CONNECTION_STRING = "mongodb://root:root@localhost" + CONNECTION_OPTIONS; - private static final MongoDBContainer MONGO_CONTAINER = new MongoDBContainer(DockerImageName.parse("mongo:6.0.12")) - .withNetworkAliases("mongo") - .withReuse(true); public static String getConnectionString() { - if (Strings.isNullOrEmpty(System.getenv("CI"))) { - return DEV_CONNECTION_STRING; - } - MONGO_CONTAINER.start(); - return MONGO_CONTAINER.getConnectionString() + CONNECTION_OPTIONS; - + return DEV_CONNECTION_STRING; } } From c16ecfea4a83d80ed2dcfa6f2a81f991c8790de2 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 11:50:18 +0800 Subject: [PATCH 04/11] feat(ci): Use github action service mongo to speed up CI --- .../src/main/java/me/ahoo/cosid/test/MockIdGenerator.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java index 1f114b2fc5..1a6481fb54 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java @@ -18,6 +18,7 @@ import me.ahoo.cosid.converter.PrefixIdConverter; import me.ahoo.cosid.converter.Radix62IdConverter; import me.ahoo.cosid.snowflake.MillisecondSnowflakeId; +import me.ahoo.cosid.uncertainty.UncertaintyIdGenerator; /** * Mock ID Generator for test. @@ -26,12 +27,14 @@ */ public class MockIdGenerator extends StringIdGeneratorDecorator { - public static final String TEST_PREFIX = "test_"; + private static final MillisecondSnowflakeId SNOWFLAKE_ID = new MillisecondSnowflakeId(1, 0); + private static final UncertaintyIdGenerator UNCERTAINTY_ID_GENERATOR = new UncertaintyIdGenerator(SNOWFLAKE_ID, 9); + public static final String TEST_PREFIX = "test_"; public static final IdGenerator INSTANCE = usePrefix(TEST_PREFIX); public MockIdGenerator(String prefix) { - super(new MillisecondSnowflakeId(1, 0), new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); + super(UNCERTAINTY_ID_GENERATOR, new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); } public static IdGenerator usePrefix(String prefix) { From 4265511df93e9b83164e72def07b557fa94efe23 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:10:47 +0800 Subject: [PATCH 05/11] feat(ci): Use github action service mongo to speed up CI --- .../main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java index 9f60707e3e..2b19990673 100644 --- a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java +++ b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java @@ -139,6 +139,10 @@ public void guard(String namespace, InstanceId instanceId, MachineState machineS guardUpdate(machineState.getLastTimeStamp()) ); if (updateResult.getModifiedCount() == 0) { + if (log.isErrorEnabled()) { + log.error("Guard - [{}] instanceId:[{}] @ namespace:[{}] - Matched:[{}] - Modified:[{}].", + machineState, instanceId, namespace, updateResult.getMatchedCount(), updateResult.getModifiedCount()); + } throw new MachineIdLostException(namespace, instanceId, machineState); } } From 6990a36d77b851bb4844205800b943756490bd36 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:19:54 +0800 Subject: [PATCH 06/11] feat(ci): Use github action service mongo to speed up CI --- .../cosid/test/machine/distributor/DistributeSafeGuard.java | 2 +- .../test/machine/distributor/MachineIdDistributorSpec.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java index 10c764754c..74d0894fa1 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/DistributeSafeGuard.java @@ -72,7 +72,7 @@ public void verify() { /* * 等待所有实例到达安全守护点(SafeGuardAt),即变成可回收状态. */ - LockSupport.parkNanos(this, safeGuardDuration.plusMillis(300).toNanos()); + LockSupport.parkNanos(this, safeGuardDuration.plusMillis(800).toNanos()); availableInstances = allInstances.subList(endIdx, MachineIdDistributor.totalMachineIds(moreMachineBit)); Integer[] machineIds = availableInstances diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java index 9cc526d7c5..ff76845659 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java @@ -30,7 +30,7 @@ public abstract class MachineIdDistributorSpec { public static final String TEST_HOST = "127.0.0.1"; private static final int TEST_MACHINE_BIT = 5; - private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(2); + private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(3); protected static InstanceId mockInstance(int port, boolean stable) { return InstanceId.of(TEST_HOST, port, stable); From d6f9d64a842389f6d3a745359ecbe2576ffbecf1 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:40:34 +0800 Subject: [PATCH 07/11] feat(ci): Use github action service mongo to speed up CI --- cosid-mongo/build.gradle.kts | 6 ++++++ .../test/machine/distributor/MachineIdDistributorSpec.java | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/cosid-mongo/build.gradle.kts b/cosid-mongo/build.gradle.kts index b5fe999e73..7a3984317e 100644 --- a/cosid-mongo/build.gradle.kts +++ b/cosid-mongo/build.gradle.kts @@ -26,3 +26,9 @@ dependencies { testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:mongodb") } + +tasks.test { + doFirst { + maxParallelForks = 1 + } +} \ No newline at end of file diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java index ff76845659..9cc526d7c5 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/machine/distributor/MachineIdDistributorSpec.java @@ -30,7 +30,7 @@ public abstract class MachineIdDistributorSpec { public static final String TEST_HOST = "127.0.0.1"; private static final int TEST_MACHINE_BIT = 5; - private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(3); + private static final Duration TEST_SAFE_GUARD_DURATION = Duration.ofSeconds(2); protected static InstanceId mockInstance(int port, boolean stable) { return InstanceId.of(TEST_HOST, port, stable); From 51fc7d283dfcb981a7d1bf230c027408b66b99f4 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:46:24 +0800 Subject: [PATCH 08/11] feat(ci): Use github action service mongo to speed up CI --- cosid-mongo/build.gradle.kts | 6 ------ .../src/main/java/me/ahoo/cosid/test/MockIdGenerator.java | 3 +-- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/cosid-mongo/build.gradle.kts b/cosid-mongo/build.gradle.kts index 7a3984317e..b5fe999e73 100644 --- a/cosid-mongo/build.gradle.kts +++ b/cosid-mongo/build.gradle.kts @@ -26,9 +26,3 @@ dependencies { testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:mongodb") } - -tasks.test { - doFirst { - maxParallelForks = 1 - } -} \ No newline at end of file diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java index 1a6481fb54..78bd3721a0 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/MockIdGenerator.java @@ -28,13 +28,12 @@ public class MockIdGenerator extends StringIdGeneratorDecorator { private static final MillisecondSnowflakeId SNOWFLAKE_ID = new MillisecondSnowflakeId(1, 0); - private static final UncertaintyIdGenerator UNCERTAINTY_ID_GENERATOR = new UncertaintyIdGenerator(SNOWFLAKE_ID, 9); public static final String TEST_PREFIX = "test_"; public static final IdGenerator INSTANCE = usePrefix(TEST_PREFIX); public MockIdGenerator(String prefix) { - super(UNCERTAINTY_ID_GENERATOR, new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); + super(SNOWFLAKE_ID, new PrefixIdConverter(prefix, Radix62IdConverter.INSTANCE)); } public static IdGenerator usePrefix(String prefix) { From cbfbfdb815b6fb863d395fb828f3d52e1733aed5 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:54:59 +0800 Subject: [PATCH 09/11] feat(ci): Use github action service mongo to speed up CI --- .github/workflows/integration-test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 37f67060e6..06131a3112 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -218,7 +218,7 @@ jobs: settings-path: ${{ github.workspace }} - name: Test CosId-Mongo - run: ./gradlew cosid-mongo:clean cosid-mongo:check + run: ./gradlew cosid-mongo:clean cosid-mongo:check -PexcludeTests=me.ahoo.cosid.mongo.MongoReactiveMachineIdDistributorTest cosid-proxy-test: name: CosId Proxy Test From 7ac3ce0802e61d4b7e34751f4ac778a469c43924 Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 12:56:09 +0800 Subject: [PATCH 10/11] feat(ci): Use github action service mongo to speed up CI --- .../main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java index 2b19990673..9f60707e3e 100644 --- a/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java +++ b/cosid-mongo/src/main/java/me/ahoo/cosid/mongo/MongoMachineCollection.java @@ -139,10 +139,6 @@ public void guard(String namespace, InstanceId instanceId, MachineState machineS guardUpdate(machineState.getLastTimeStamp()) ); if (updateResult.getModifiedCount() == 0) { - if (log.isErrorEnabled()) { - log.error("Guard - [{}] instanceId:[{}] @ namespace:[{}] - Matched:[{}] - Modified:[{}].", - machineState, instanceId, namespace, updateResult.getMatchedCount(), updateResult.getModifiedCount()); - } throw new MachineIdLostException(namespace, instanceId, machineState); } } From ba4053a9b0fb9169b75d2472e6c1ab7513180beb Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Fri, 5 Jan 2024 13:10:32 +0800 Subject: [PATCH 11/11] feat(ci): Use github action service mongo to speed up CI --- .github/workflows/integration-test.yml | 2 +- cosid-mongo/build.gradle.kts | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration-test.yml b/.github/workflows/integration-test.yml index 06131a3112..37f67060e6 100644 --- a/.github/workflows/integration-test.yml +++ b/.github/workflows/integration-test.yml @@ -218,7 +218,7 @@ jobs: settings-path: ${{ github.workspace }} - name: Test CosId-Mongo - run: ./gradlew cosid-mongo:clean cosid-mongo:check -PexcludeTests=me.ahoo.cosid.mongo.MongoReactiveMachineIdDistributorTest + run: ./gradlew cosid-mongo:clean cosid-mongo:check cosid-proxy-test: name: CosId Proxy Test diff --git a/cosid-mongo/build.gradle.kts b/cosid-mongo/build.gradle.kts index b5fe999e73..e6445ddc48 100644 --- a/cosid-mongo/build.gradle.kts +++ b/cosid-mongo/build.gradle.kts @@ -26,3 +26,10 @@ dependencies { testImplementation("org.testcontainers:junit-jupiter") testImplementation("org.testcontainers:mongodb") } + +val isInCI = null != System.getenv("CI") +if (isInCI) { + tasks.withType { + exclude("me.ahoo.cosid.mongo.MongoReactiveMachineIdDistributorTest") + } +} \ No newline at end of file