Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private void createNewTopics(Set<String> newSourceTopics, Map<String, Long> sour
.map(sourceTopic -> {
String remoteTopic = formatRemoteTopic(sourceTopic);
int partitionCount = sourceTopicToPartitionCounts.get(sourceTopic).intValue();
Map<String, String> configs = configToMap(sourceTopicToConfig.get(sourceTopic));
Map<String, String> configs = configToMap(targetConfig(sourceTopicToConfig.get(sourceTopic)));
return new NewTopic(remoteTopic, partitionCount, (short) replicationFactor)
.configs(configs);
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,44 @@ public void testConfigPropertyFiltering() {
.anyMatch(x -> x.name().equals("min.insync.replicas")), "should not replicate excluded properties");
}

@Test
public void testConfigPropertyFilteringExclude() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even without the code change, this test is passing. It's because it's calling connector.targetConfig() while the fix is in createNewTopics().

@bdesert bdesert Oct 29, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mimaison, thanks for the comments. Makes perfect sense.
I'm adding integration test to address your suggestion.
Along with that, i'm still keeping the unitTest committed before, so it will test configuration filtering logic without integration. The method I've added to unitTest follows the suit of the very previous test testConfigPropertyFiltering, which tests default exclude list this particular way.


Map<String, Object> mmConfig = new HashMap<>();
mmConfig.put(DefaultConfigPropertyFilter.CONFIG_PROPERTIES_EXCLUDE_CONFIG, "follower\\.replication\\.throttled\\.replicas, "
+ "leader\\.replication\\.throttled\\.replicas, "
+ "message\\.timestamp\\.difference\\.max\\.ms, "
+ "message\\.timestamp\\.type, "
+ "unclean\\.leader\\.election\\.enable, "
+ "min\\.insync\\.replicas,"
+ "exclude_param.*");

DefaultConfigPropertyFilter filter = new DefaultConfigPropertyFilter();
filter.configure(mmConfig);

MirrorSourceConnector connector = new MirrorSourceConnector(new SourceAndTarget("source", "target"),
new DefaultReplicationPolicy(), x -> true, filter);
ArrayList<ConfigEntry> entries = new ArrayList<>();
entries.add(new ConfigEntry("name-1", "value-1"));
entries.add(new ConfigEntry("exclude_param.param1", "value-param1"));
entries.add(new ConfigEntry("min.insync.replicas", "2"));
Config config = new Config(entries);
Config targetConfig = connector.targetConfig(config);

// property 'name-1' isn't defined in the exclude filter -> should be replicated
assertTrue(targetConfig.entries().stream().anyMatch(x -> x.name().equals("name-1")),
"should replicate properties");

// this property is in default list, just double check it:
String prop1 = "min.insync.replicas";
assertFalse(targetConfig.entries().stream().anyMatch(x -> x.name().equals(prop1)),
"should not replicate excluded properties " + prop1);
// this property is only in exclude filter custom parameter, also tests regex on the way:
String prop2 = "exclude_param.param1";
assertFalse(targetConfig.entries().stream().anyMatch(x -> x.name().equals(prop2)),
"should not replicate excluded properties " + prop2);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that calling verify on targetConfig() is not the best. But I think we should call verify on createNewTopics(any()) to ensure our mocked method, and the assertions, actually run.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree. with a small correction of createNewTopics(any(), any()). since the targetConfig() is being called from overloaded method with two params.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah right, the code we changed is actually in createNewTopics(any(), any()). As we explicitly call that method ourselves, I don't think the verify call adds a lot of value. But I think it's fine, it shouldn't hurt


@Test
public void testMirrorSourceConnectorTaskConfig() {
List<TopicPartition> knownSourceTopicPartitions = new ArrayList<>();
Expand Down