测试调整

This commit is contained in:
Shikong 2023-04-26 15:33:38 +08:00
parent 7d5859fa4b
commit afdf7c8187

View File

@ -77,6 +77,19 @@ public class KafkaConfigTest {
void testTopicInfo() { void testTopicInfo() {
try (AdminClient client = adminClient()) { try (AdminClient client = adminClient()) {
ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, TOPIC); ConfigResource resource = new ConfigResource(ConfigResource.Type.TOPIC, TOPIC);
log.info("原配置");
getTopicConfig(client, resource);
log.info("修改配置");
alterTopicConfig(client, resource);
log.info("修改后配置");
getTopicConfig(client, resource);
}
}
@SneakyThrows
void getTopicConfig(AdminClient client, ConfigResource resource) {
DescribeConfigsResult describeConfigsResult = client.describeConfigs(Collections.singletonList(resource)); DescribeConfigsResult describeConfigsResult = client.describeConfigs(Collections.singletonList(resource));
describeConfigsResult.all().get().forEach((source, config) -> { describeConfigsResult.all().get().forEach((source, config) -> {
log.info("{} =>", source.name()); log.info("{} =>", source.name());
@ -84,7 +97,10 @@ public class KafkaConfigTest {
log.info("\t{} => {}", entry.name(), entry.value()); log.info("\t{} => {}", entry.name(), entry.value());
}); });
}); });
}
@SneakyThrows
void alterTopicConfig(AdminClient client, ConfigResource resource) {
Collection<AlterConfigOp> configs = Arrays.asList( Collection<AlterConfigOp> configs = Arrays.asList(
new AlterConfigOp(new ConfigEntry("min.cleanable.dirty.ratio", "0.5"), AlterConfigOp.OpType.SET), new AlterConfigOp(new ConfigEntry("min.cleanable.dirty.ratio", "0.5"), AlterConfigOp.OpType.SET),
new AlterConfigOp(new ConfigEntry("unclean.leader.election.enable", "false"), AlterConfigOp.OpType.SET), new AlterConfigOp(new ConfigEntry("unclean.leader.election.enable", "false"), AlterConfigOp.OpType.SET),
@ -95,14 +111,5 @@ public class KafkaConfigTest {
AlterConfigsResult result = client.incrementalAlterConfigs(Collections.singletonMap(resource, configs)); AlterConfigsResult result = client.incrementalAlterConfigs(Collections.singletonMap(resource, configs));
result.all().get(); result.all().get();
describeConfigsResult = client.describeConfigs(Collections.singletonList(resource));
describeConfigsResult.all().get().forEach((source, config) -> {
log.info("{} =>", source.name());
config.entries().forEach(entry -> {
log.info("\t{} => {}", entry.name(), entry.value());
});
});
}
} }
} }