Skip to content

Commit

Permalink
feat: Support auto config GroupedIdSegmentDistributor .
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang committed Jun 29, 2023
1 parent 6c75194 commit 2ab9237
Showing 1 changed file with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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()));
}
}

0 comments on commit 2ab9237

Please sign in to comment.