From 2ab9237a46bd21db8cc8ea13770b06ec77efd44c Mon Sep 17 00:00:00 2001 From: Ahoo Wang Date: Thu, 29 Jun 2023 12:42:38 +0800 Subject: [PATCH] feat: Support auto config `GroupedIdSegmentDistributor` . --- .../GroupedIdSegmentDistributorSpec.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/cosid-test/src/main/java/me/ahoo/cosid/test/segment/distributor/GroupedIdSegmentDistributorSpec.java b/cosid-test/src/main/java/me/ahoo/cosid/test/segment/distributor/GroupedIdSegmentDistributorSpec.java index 6ba3f455af..623c691b14 100644 --- a/cosid-test/src/main/java/me/ahoo/cosid/test/segment/distributor/GroupedIdSegmentDistributorSpec.java +++ b/cosid-test/src/main/java/me/ahoo/cosid/test/segment/distributor/GroupedIdSegmentDistributorSpec.java @@ -13,16 +13,18 @@ package me.ahoo.cosid.test.segment.distributor; +import static me.ahoo.cosid.segment.IdSegmentDistributor.DEFAULT_SEGMENTS; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.*; import me.ahoo.cosid.segment.IdSegment; +import me.ahoo.cosid.segment.IdSegmentChain; import me.ahoo.cosid.segment.IdSegmentDistributor; import me.ahoo.cosid.segment.IdSegmentDistributorDefinition; import me.ahoo.cosid.segment.IdSegmentDistributorFactory; import me.ahoo.cosid.segment.grouped.DateGroupBySupplier; -import me.ahoo.cosid.segment.grouped.GroupedIdSegmentDistributorFactory; import me.ahoo.cosid.segment.grouped.GroupBySupplier; +import me.ahoo.cosid.segment.grouped.GroupedIdSegmentDistributorFactory; import me.ahoo.cosid.test.MockIdGenerator; import org.junit.jupiter.api.Test; @@ -61,5 +63,19 @@ public void nextIdSegment() { assertThat(actual.getSequence(), equalTo(0L)); assertThat(actual.getTtl(), equalTo(groupedSupplier().get().ttl())); } - + + @Test + @Override + public void nextIdSegmentChain() { + IdSegmentChain root = IdSegmentChain.newRoot(false); + String namespace = MockIdGenerator.INSTANCE.generateAsString(); + IdSegmentDistributorDefinition definition = new IdSegmentDistributorDefinition(namespace, "nextIdSegmentChain", TEST_OFFSET, TEST_STEP); + IdSegmentDistributor distributor = factory().create(definition); + long expectedMaxId = TEST_OFFSET + Math.multiplyExact(TEST_STEP, DEFAULT_SEGMENTS); + IdSegment actual = distributor.nextIdSegmentChain(root); + assertThat(actual.getMaxId(), equalTo(expectedMaxId)); + assertThat(actual.getStep(), equalTo(TEST_STEP)); + assertThat(actual.getSequence(), equalTo(0L)); + assertThat(actual.getTtl(), equalTo(groupedSupplier().get().ttl())); + } }