Skip to content

Commit

Permalink
Refactor ReadwriteSplittingDataSourceMapperRuleAttributeTest (#33540)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrymanu authored Nov 4, 2024
1 parent 5dedd28 commit 894f236
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ class ReadwriteSplittingDataSourceMapperRuleAttributeTest {

@Test
void assertGetDataSourceMapper() {
Map<String, Collection<String>> actual = new ReadwriteSplittingDataSourceMapperRuleAttribute(Collections.singleton(createDataSourceGroupRule())).getDataSourceMapper();
Map<String, Collection<String>> actual = createRuleAttribute().getDataSourceMapper();
Map<String, Collection<String>> expected = Collections.singletonMap("readwrite", Arrays.asList("write_ds", "read_ds_0", "read_ds_1"));
assertThat(actual, is(expected));
}

private ReadwriteSplittingDataSourceGroupRule createDataSourceGroupRule() {
return new ReadwriteSplittingDataSourceGroupRule(
private ReadwriteSplittingDataSourceMapperRuleAttribute createRuleAttribute() {
ReadwriteSplittingDataSourceGroupRule dataSourceGroupRule = new ReadwriteSplittingDataSourceGroupRule(
new ReadwriteSplittingDataSourceGroupRuleConfiguration("readwrite", "write_ds", Arrays.asList("read_ds_0", "read_ds_1"), "random"), null, null);
return new ReadwriteSplittingDataSourceMapperRuleAttribute(Collections.singleton(dataSourceGroupRule));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.junit.jupiter.api.Test;

import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.Map;

Expand All @@ -31,8 +32,13 @@ class ShadowDataSourceMapperRuleAttributeTest {

@Test
void assertGetDataSourceMapper() {
Map<String, Collection<String>> actual = createRuleAttribute().getDataSourceMapper();
Map<String, Collection<String>> expected = Collections.singletonMap("foo_ds", Arrays.asList("prod_ds", "shadow_ds"));
assertThat(actual, is(expected));
}

ShadowDataSourceMapperRuleAttribute createRuleAttribute() {
Map<String, ShadowDataSourceRule> dataSourceRules = Collections.singletonMap("foo_ds", new ShadowDataSourceRule("prod_ds", "shadow_ds"));
ShadowDataSourceMapperRuleAttribute attribute = new ShadowDataSourceMapperRuleAttribute(dataSourceRules);
assertThat(attribute.getDataSourceMapper(), is(Collections.singletonMap("foo_ds", Arrays.asList("prod_ds", "shadow_ds"))));
return new ShadowDataSourceMapperRuleAttribute(dataSourceRules);
}
}

0 comments on commit 894f236

Please sign in to comment.