diff --git a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java index fe916bb71f..be28943d5c 100644 --- a/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java +++ b/cosid-mongo/src/test/java/me/ahoo/cosid/mongo/MongoReactiveIdSegmentDistributorTest.java @@ -21,6 +21,7 @@ import me.ahoo.cosid.segment.IdSegmentDistributor; import me.ahoo.cosid.segment.IdSegmentDistributorDefinition; import me.ahoo.cosid.segment.IdSegmentDistributorFactory; +import me.ahoo.cosid.segment.SegmentChainId; import me.ahoo.cosid.test.MockIdGenerator; import me.ahoo.cosid.test.segment.distributor.IdSegmentDistributorSpec; @@ -41,6 +42,7 @@ class MongoReactiveIdSegmentDistributorTest extends IdSegmentDistributorSpec { void setup() { mongoDatabase = MongoClients.create(MongoLauncher.getConnectionString()).getDatabase("cosid_db"); idSegmentInitializer = new MongoReactiveIdSegmentInitializer(mongoDatabase); + idSegmentInitializer.ensureCosIdCollection(); distributorFactory = new MongoReactiveIdSegmentDistributorFactory(mongoDatabase, true); @@ -75,4 +77,21 @@ public void nextMaxIdInParallel() { }).subscribeOn(Schedulers.parallel()); StepVerifier.create(mono).verifyComplete(); } + + @Test + public void batchNextMaxId() { + String namespace = MockIdGenerator.INSTANCE.generateAsString(); + IdSegmentDistributorDefinition definition = new IdSegmentDistributorDefinition(namespace, "batchNextMaxId", 1, 1); + IdSegmentDistributor distributor = factory().create(definition); + var segmentChainId = new SegmentChainId(distributor); + for (int i = 0; i < 1000; i++) { + segmentChainId.generateAsString(); + } + var mono = Mono.fromRunnable(() -> { + for (int i = 0; i < 1000; i++) { + segmentChainId.generateAsString(); + } + }).subscribeOn(Schedulers.single()); + StepVerifier.create(mono).verifyComplete(); + } } \ No newline at end of file diff --git a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfiguration.java b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfiguration.java index 7f9da2039b..10fcd66ee9 100644 --- a/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfiguration.java +++ b/cosid-spring-boot-starter/src/main/java/me/ahoo/cosid/spring/boot/starter/segment/CosIdMongoSegmentAutoConfiguration.java @@ -33,6 +33,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Primary; +import org.springframework.core.annotation.Order; /** * CosId Redis Segment AutoConfiguration. @@ -54,6 +55,7 @@ public CosIdMongoSegmentAutoConfiguration(SegmentIdProperties segmentIdPropertie this.segmentIdProperties = segmentIdProperties; } + @Order(0) @Configuration @ConditionalOnClass(MongoClient.class) class Sync { diff --git a/gradle.properties b/gradle.properties index 4f220cde42..a4277e803b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -11,7 +11,7 @@ # limitations under the License. # group=me.ahoo.cosid -version=2.5.1 +version=2.5.2 description=Universal, flexible, high-performance distributed ID generator. website=https://github.com/Ahoo-Wang/CosId issues=https://github.com/Ahoo-Wang/CosId/issues