Skip to content

Commit

Permalink
refactor: Prioritize MongoClient that supports synchronous mode (#431)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored Sep 5, 2023
1 parent 75c326e commit 2101ec4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -54,6 +55,7 @@ public CosIdMongoSegmentAutoConfiguration(SegmentIdProperties segmentIdPropertie
this.segmentIdProperties = segmentIdProperties;
}

@Order(0)
@Configuration
@ConditionalOnClass(MongoClient.class)
class Sync {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2101ec4

Please sign in to comment.