diff --git a/cosid-core/src/main/java/me/ahoo/cosid/machine/HostAddressSupplier.java b/cosid-core/src/main/java/me/ahoo/cosid/machine/HostAddressSupplier.java new file mode 100644 index 0000000000..4448b56c96 --- /dev/null +++ b/cosid-core/src/main/java/me/ahoo/cosid/machine/HostAddressSupplier.java @@ -0,0 +1,20 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed 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. + */ + +package me.ahoo.cosid.machine; + +@FunctionalInterface +public interface HostAddressSupplier { + String getHostAddress(); +} + diff --git a/cosid-core/src/main/java/me/ahoo/cosid/machine/LocalHostAddressSupplier.java b/cosid-core/src/main/java/me/ahoo/cosid/machine/LocalHostAddressSupplier.java new file mode 100644 index 0000000000..301b8e0059 --- /dev/null +++ b/cosid-core/src/main/java/me/ahoo/cosid/machine/LocalHostAddressSupplier.java @@ -0,0 +1,55 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed 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. + */ + +package me.ahoo.cosid.machine; + +import lombok.SneakyThrows; +import lombok.extern.slf4j.Slf4j; + +import java.net.Inet4Address; +import java.net.InetAddress; +import java.net.NetworkInterface; +import java.util.Enumeration; + +@Slf4j +public final class LocalHostAddressSupplier implements HostAddressSupplier { + public static final LocalHostAddressSupplier INSTANCE = new LocalHostAddressSupplier(); + + @SneakyThrows + @Override + public String getHostAddress() { + String hostAddress = InetAddress.getLocalHost().getHostAddress(); + try { + Enumeration networkInterfaces = NetworkInterface.getNetworkInterfaces(); + while (networkInterfaces.hasMoreElements()) { + NetworkInterface eachNetworkInterface = networkInterfaces.nextElement(); + if (!eachNetworkInterface.isUp() || eachNetworkInterface.isLoopback()) { + continue; + } + Enumeration inetAddresses = eachNetworkInterface.getInetAddresses(); + while (inetAddresses.hasMoreElements()) { + InetAddress inetAddress = inetAddresses.nextElement(); + if (inetAddress instanceof Inet4Address + && !inetAddress.isLoopbackAddress() + && !inetAddress.isAnyLocalAddress() + ) { + hostAddress = inetAddress.getHostAddress(); + } + } + } + } catch (Exception ex) { + log.error("Cannot get first non-loopback address", ex); + } + return hostAddress; + } +} diff --git a/cosid-core/src/test/java/me/ahoo/cosid/machine/LocalHostAddressSupplierTest.java b/cosid-core/src/test/java/me/ahoo/cosid/machine/LocalHostAddressSupplierTest.java new file mode 100644 index 0000000000..7d5ee1cdf7 --- /dev/null +++ b/cosid-core/src/test/java/me/ahoo/cosid/machine/LocalHostAddressSupplierTest.java @@ -0,0 +1,27 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed 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. + */ + +package me.ahoo.cosid.machine; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +import org.junit.jupiter.api.Test; + +class LocalHostAddressSupplierTest { + + @Test + void getHostName() { + assertThat(LocalHostAddressSupplier.INSTANCE.getHostAddress(), notNullValue()); + } +} \ No newline at end of file diff --git a/cosid-spring-boot-starter/build.gradle.kts b/cosid-spring-boot-starter/build.gradle.kts index d4ce749310..41645bb1d5 100644 --- a/cosid-spring-boot-starter/build.gradle.kts +++ b/cosid-spring-boot-starter/build.gradle.kts @@ -36,6 +36,10 @@ java { usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) capability(group.toString(), "mybatis-support", version.toString()) } + registerFeature("cloudSupport") { + usingSourceSet(sourceSets[SourceSet.MAIN_SOURCE_SET_NAME]) + capability(group.toString(), "cloud-support", version.toString()) + } } dependencies { @@ -54,7 +58,7 @@ dependencies { "mybatisSupportImplementation"(project(":cosid-mybatis")) api("org.springframework.boot:spring-boot-starter") - api("org.springframework.cloud:spring-cloud-commons") + "cloudSupportImplementation"("org.springframework.cloud:spring-cloud-commons") compileOnly("org.mongodb:mongodb-driver-sync") compileOnly("org.mongodb:mongodb-driver-reactivestreams") annotationProcessor("org.springframework.boot:spring-boot-configuration-processor") diff --git a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfiguration.java b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfiguration.java new file mode 100644 index 0000000000..b78bcfcd52 --- /dev/null +++ b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfiguration.java @@ -0,0 +1,60 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed 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. + */ + +package me.ahoo.cosid.spring.boot.starter.machine; + +import me.ahoo.cosid.machine.HostAddressSupplier; +import me.ahoo.cosid.machine.LocalHostAddressSupplier; +import me.ahoo.cosid.spring.boot.starter.ConditionalOnCosIdEnabled; + +import org.springframework.boot.autoconfigure.AutoConfiguration; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.cloud.commons.util.InetUtils; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@AutoConfiguration(afterName = "org.springframework.cloud.commons.util.UtilAutoConfiguration") +@ConditionalOnCosIdEnabled +public class CosIdHostNameAutoConfiguration { + + @Bean + @ConditionalOnMissingBean + public HostAddressSupplier hostNameSupplier() { + return LocalHostAddressSupplier.INSTANCE; + } + + @Configuration + @ConditionalOnClass(InetUtils.class) + static class CloudUtilInstanceIdConfiguration { + @Bean + @ConditionalOnBean(InetUtils.class) + public HostAddressSupplier hostNameSupplier(InetUtils inetUtils) { + return new CloudUtilHostAddressSupplier(inetUtils); + } + } + + static class CloudUtilHostAddressSupplier implements HostAddressSupplier { + private final InetUtils inetUtils; + + CloudUtilHostAddressSupplier(InetUtils inetUtils) { + this.inetUtils = inetUtils; + } + + @Override + public String getHostAddress() { + return inetUtils.findFirstNonLoopbackHostInfo().getIpAddress(); + } + } +} diff --git a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfiguration.java b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfiguration.java index 5c2208044c..0f984190a8 100644 --- a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfiguration.java +++ b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfiguration.java @@ -16,6 +16,7 @@ import me.ahoo.cosid.machine.ClockBackwardsSynchronizer; import me.ahoo.cosid.machine.DefaultClockBackwardsSynchronizer; import me.ahoo.cosid.machine.DefaultMachineIdGuarder; +import me.ahoo.cosid.machine.HostAddressSupplier; import me.ahoo.cosid.machine.InstanceId; import me.ahoo.cosid.machine.LocalMachineStateStorage; import me.ahoo.cosid.machine.MachineId; @@ -34,7 +35,6 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.cloud.commons.util.InetUtils; import org.springframework.context.annotation.Bean; import java.util.Objects; @@ -54,7 +54,7 @@ public CosIdMachineAutoConfiguration(CosIdProperties cosIdProperties, MachinePro @Bean @ConditionalOnMissingBean - public InstanceId instanceId(InetUtils inetUtils) { + public InstanceId instanceId(HostAddressSupplier hostAddressSupplier) { boolean stable = Boolean.TRUE.equals(machineProperties.getStable()); @@ -62,14 +62,12 @@ public InstanceId instanceId(InetUtils inetUtils) { return InstanceId.of(machineProperties.getInstanceId(), stable); } - InetUtils.HostInfo hostInfo = inetUtils.findFirstNonLoopbackHostInfo(); - int port = ProcessId.CURRENT.getProcessId(); if (Objects.nonNull(machineProperties.getPort()) && machineProperties.getPort() > 0) { port = machineProperties.getPort(); } - return InstanceId.of(hostInfo.getIpAddress(), port, stable); + return InstanceId.of(hostAddressSupplier.getHostAddress(), port, stable); } @Bean @@ -136,4 +134,5 @@ public MachineIdGuarder machineIdGuarder(MachineIdDistributor machineIdDistribut public CosIdLifecycleMachineIdGuarder cosIdLifecycleMachineIdGuarder(InstanceId instanceId, MachineIdGuarder machineIdGuarder) { return new CosIdLifecycleMachineIdGuarder(cosIdProperties, instanceId, machineIdGuarder); } + } diff --git a/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports b/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports index 3c218342fc..434c8dfe32 100644 --- a/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports +++ b/cosid-spring-boot-starter/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports @@ -1,5 +1,6 @@ me.ahoo.cosid.spring.boot.starter.CosIdAutoConfiguration me.ahoo.cosid.spring.boot.starter.zookeeper.CosIdZookeeperAutoConfiguration +me.ahoo.cosid.spring.boot.starter.machine.CosIdHostNameAutoConfiguration me.ahoo.cosid.spring.boot.starter.machine.CosIdMachineAutoConfiguration me.ahoo.cosid.spring.boot.starter.cosid.CosIdGeneratorAutoConfiguration me.ahoo.cosid.spring.boot.starter.machine.CosIdJdbcMachineIdDistributorAutoConfiguration diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/cosid/CosIdGeneratorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/cosid/CosIdGeneratorAutoConfigurationTest.java index e592bc6322..1ea65a2d45 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/cosid/CosIdGeneratorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/cosid/CosIdGeneratorAutoConfigurationTest.java @@ -27,6 +27,7 @@ import me.ahoo.cosid.snowflake.SnowflakeId; import me.ahoo.cosid.spring.boot.starter.CosIdAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.ConditionalOnCosIdMachineEnabled; +import me.ahoo.cosid.spring.boot.starter.machine.CosIdHostNameAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.CosIdLifecycleMachineIdDistributor; import me.ahoo.cosid.spring.boot.starter.machine.CosIdMachineAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.MachineProperties; @@ -49,6 +50,7 @@ void contextLoads() { .withPropertyValues(MachineProperties.PREFIX + ".distributor.manual.machineId=1") .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, CosIdMachineAutoConfiguration.class, CosIdGeneratorAutoConfiguration.class) .run(context -> { @@ -74,6 +76,7 @@ void contextLoadsWithType() { .withPropertyValues(CosIdGeneratorProperties.PREFIX + ".type=RADIX36") .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, CosIdMachineAutoConfiguration.class, CosIdGeneratorAutoConfiguration.class) .run(context -> { diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfigurationTest.java new file mode 100644 index 0000000000..8fe7016305 --- /dev/null +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdHostNameAutoConfigurationTest.java @@ -0,0 +1,55 @@ +/* + * Copyright [2021-present] [ahoo wang (https://github.com/Ahoo-Wang)]. + * Licensed 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. + */ + +package me.ahoo.cosid.spring.boot.starter.machine; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; + +import me.ahoo.cosid.machine.HostAddressSupplier; +import me.ahoo.cosid.machine.LocalHostAddressSupplier; + +import org.assertj.core.api.AssertionsForInterfaceTypes; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.runner.ApplicationContextRunner; +import org.springframework.cloud.commons.util.UtilAutoConfiguration; + +class CosIdHostNameAutoConfigurationTest { + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); + + @Test + void contextLoads() { + this.contextRunner + .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") + .withUserConfiguration(CosIdHostNameAutoConfiguration.class) + .run(context -> { + AssertionsForInterfaceTypes.assertThat(context) + .hasSingleBean(LocalHostAddressSupplier.class) + ; + assertThat(context.getBean(LocalHostAddressSupplier.class).getHostAddress(), notNullValue()); + }); + } + + @Test + void contextLoadsIfCloud() { + this.contextRunner + .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") + .withUserConfiguration(UtilAutoConfiguration.class, CosIdHostNameAutoConfiguration.class) + .run(context -> { + AssertionsForInterfaceTypes.assertThat(context) + .hasSingleBean(CosIdHostNameAutoConfiguration.CloudUtilHostAddressSupplier.class) + ; + assertThat(context.getBean(HostAddressSupplier.class).getHostAddress(), notNullValue()); + }); + } +} \ No newline at end of file diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdJdbcMachineIdDistributorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdJdbcMachineIdDistributorAutoConfigurationTest.java index e99c500bee..42f5336480 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdJdbcMachineIdDistributorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdJdbcMachineIdDistributorAutoConfigurationTest.java @@ -35,7 +35,7 @@ class CosIdJdbcMachineIdDistributorAutoConfigurationTest { private final ApplicationContextRunner contextRunner = new ApplicationContextRunner(); - + @Test void contextLoads() { this.contextRunner @@ -44,7 +44,11 @@ void contextLoads() { .withPropertyValues("spring.datasource.url=jdbc:mysql://localhost:3306/cosid_db") .withPropertyValues("spring.datasource.username=root") .withPropertyValues("spring.datasource.password=root") - .withUserConfiguration(UtilAutoConfiguration.class, DataSourceAutoConfiguration.class, CosIdAutoConfiguration.class, CosIdMachineAutoConfiguration.class) + .withUserConfiguration(UtilAutoConfiguration.class, + DataSourceAutoConfiguration.class, + CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, + CosIdMachineAutoConfiguration.class) .withUserConfiguration(CosIdJdbcMachineIdDistributorAutoConfiguration.class) .run(context -> { assertThat(context) diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfigurationTest.java index 45398e4979..203e2f1cae 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMachineAutoConfigurationTest.java @@ -42,7 +42,10 @@ void contextLoadsWhenMachineIdDistributorIsStatefulSet() { this.contextRunner .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") .withPropertyValues(MachineProperties.Distributor.TYPE + "=stateful_set") - .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, CosIdMachineAutoConfiguration.class) + .withUserConfiguration(UtilAutoConfiguration.class, + CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, + CosIdMachineAutoConfiguration.class) .run(context -> { assertThat(context) .hasSingleBean(CosIdMachineAutoConfiguration.class) diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java index 4dbc8b48aa..9283d8d7b3 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdMongoMachineIdDistributorAutoConfigurationTest.java @@ -43,6 +43,7 @@ void contextLoads() { MongoAutoConfiguration.class, MongoReactiveAutoConfiguration.class, CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, CosIdMachineAutoConfiguration.class, CosIdMongoMachineIdDistributorAutoConfiguration.class) .run(context -> { diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdSpringRedisMachineIdDistributorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdSpringRedisMachineIdDistributorAutoConfigurationTest.java index ef8551df69..c3e3df360e 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdSpringRedisMachineIdDistributorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdSpringRedisMachineIdDistributorAutoConfigurationTest.java @@ -40,7 +40,10 @@ void contextLoads() { this.contextRunner .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") .withPropertyValues(MachineProperties.Distributor.TYPE + "=redis") - .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, CosIdMachineAutoConfiguration.class) + .withUserConfiguration(UtilAutoConfiguration.class, + CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, + CosIdMachineAutoConfiguration.class) .withUserConfiguration(RedisAutoConfiguration.class, CosIdSpringRedisMachineIdDistributorAutoConfiguration.class) .run(context -> { assertThat(context) diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdZookeeperMachineIdDistributorAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdZookeeperMachineIdDistributorAutoConfigurationTest.java index fcba2562ba..a5fdb68368 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdZookeeperMachineIdDistributorAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/machine/CosIdZookeeperMachineIdDistributorAutoConfigurationTest.java @@ -47,7 +47,11 @@ void contextLoads() { .withPropertyValues(ConditionalOnCosIdMachineEnabled.ENABLED_KEY + "=true") .withPropertyValues(MachineProperties.Distributor.TYPE + "=zookeeper") .withPropertyValues(CosIdZookeeperProperties.PREFIX + ".connect-string=" + testingServer.getConnectString()) - .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, CosIdZookeeperAutoConfiguration.class, CosIdMachineAutoConfiguration.class) + .withUserConfiguration(UtilAutoConfiguration.class, + CosIdAutoConfiguration.class, + CosIdZookeeperAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, + CosIdMachineAutoConfiguration.class) .withUserConfiguration(CosIdZookeeperMachineIdDistributorAutoConfiguration.class) .run(context -> { assertThat(context) diff --git a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/snowflake/CosIdSnowflakeAutoConfigurationTest.java b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/snowflake/CosIdSnowflakeAutoConfigurationTest.java index a3e132fb72..a3d0d81ef7 100644 --- a/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/snowflake/CosIdSnowflakeAutoConfigurationTest.java +++ b/cosid-spring-boot-starter/src/test/java/me/ahoo/cosid/spring/boot/starter/snowflake/CosIdSnowflakeAutoConfigurationTest.java @@ -21,6 +21,7 @@ import me.ahoo.cosid.machine.MachineStateStorage; import me.ahoo.cosid.spring.boot.starter.CosIdAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.ConditionalOnCosIdMachineEnabled; +import me.ahoo.cosid.spring.boot.starter.machine.CosIdHostNameAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.CosIdLifecycleMachineIdDistributor; import me.ahoo.cosid.spring.boot.starter.machine.CosIdMachineAutoConfiguration; import me.ahoo.cosid.spring.boot.starter.machine.MachineProperties; @@ -46,6 +47,7 @@ void contextLoads() { .withBean(CustomizeSnowflakeIdProperties.class, () -> idProperties -> idProperties.getProvider().put("test", new SnowflakeIdProperties.IdDefinition())) .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, CosIdMachineAutoConfiguration.class, CosIdSnowflakeAutoConfiguration.class) .run(context -> { @@ -74,6 +76,7 @@ void contextLoadsWithConfig() { .withPropertyValues(SnowflakeIdProperties.PREFIX + ".provider.test.converter.to_string.pad-start=true") .withUserConfiguration(UtilAutoConfiguration.class, CosIdAutoConfiguration.class, + CosIdHostNameAutoConfiguration.class, CosIdMachineAutoConfiguration.class, CosIdSnowflakeAutoConfiguration.class) .run(context -> { diff --git a/examples/cosid-example-redis/build.gradle.kts b/examples/cosid-example-redis/build.gradle.kts index df4752294a..7900ae14b8 100644 --- a/examples/cosid-example-redis/build.gradle.kts +++ b/examples/cosid-example-redis/build.gradle.kts @@ -49,8 +49,8 @@ dependencies { annotationProcessor(platform(project(":cosid-dependencies"))) implementation(project(":cosid-spring-boot-starter")) implementation(project(":cosid-jackson")) - implementation(project(":cosid-spring-redis")) +// implementation("org.springframework.cloud:spring-cloud-commons") implementation("org.springframework.boot:spring-boot-starter-data-redis") implementation("org.springframework.boot:spring-boot-starter-actuator") implementation("com.google.guava:guava") diff --git a/gradle.properties b/gradle.properties index 61293350ac..26d7c8d2e1 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ # limitations under the License. # group=me.ahoo.cosid -version=2.2.5 +version=2.2.6 description=Universal, flexible, high-performance distributed ID generator. website=https://github.com/Ahoo-Wang/CosId issues=https://github.com/Ahoo-Wang/CosId/issues