Skip to content

Commit

Permalink
Don't print empty operations (#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
sverrehu authored Aug 3, 2022
1 parent 61fee75 commit 3765517
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 55 deletions.
4 changes: 3 additions & 1 deletion src/main/java/com/purbon/kafka/topology/ExecutionPlan.java
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ public void run(boolean dryRun) throws IOException {

private void execute(Action action, boolean dryRun) throws IOException {
LOGGER.debug(String.format("Execution action %s (dryRun=%s)", action, dryRun));
outputStream.println(action);
if (!action.toString().isEmpty()) {
outputStream.println(action);
}
if (!dryRun) {
action.run();
auditor.log(action);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ public class MinInSyncReplicasValidation implements TopicValidation {

@Override
public void valid(Topic topic) throws ValidationException {
if (topic.replicationFactor().isPresent()
&& !validateMinInsyncReplicas(topic)) {
if (topic.replicationFactor().isPresent() && !validateMinInsyncReplicas(topic)) {
String msg =
String.format(
"Topic %s has an unexpected min.insync.replicas config vs it's replication factor: %s value",
Expand All @@ -21,9 +20,9 @@ public void valid(Topic topic) throws ValidationException {
}

private boolean validateMinInsyncReplicas(Topic topic) {
short replicationFactor = topic.replicationFactor().orElse((short)-1);
short replicationFactor = topic.replicationFactor().orElse((short) -1);
String minInSyncReplicas = topic.getConfig().get(MIN_INSYNC_REPLICAS);
return minInSyncReplicas == null || (Integer.parseInt(minInSyncReplicas) <= replicationFactor - 1);
return minInSyncReplicas == null
|| (Integer.parseInt(minInSyncReplicas) <= replicationFactor - 1);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public void dryRunTest() throws IOException {
topicManager.updatePlan(topology, plan);
plan.run(true);

verify(outputStream, times(4)).println(any(Action.class));
verify(outputStream, times(2)).println(any(Action.class));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,57 +3,54 @@
import com.purbon.kafka.topology.exceptions.ConfigurationException;
import com.purbon.kafka.topology.exceptions.ValidationException;
import com.purbon.kafka.topology.model.Topic;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;
import org.junit.Test;

public class MinInSyncReplicasValidationTest {

@Test(expected = ValidationException.class)
public void shouldCheckKoValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "3");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckMinimalValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "1");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckOkValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "2");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckMissingMinInSyncValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}
@Test(expected = ValidationException.class)
public void shouldCheckKoValuesSuccessfully() throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "3");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckMinimalValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "1");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckOkValuesSuccessfully() throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");
config.put("min.insync.replicas", "2");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}

@Test
public void shouldCheckMissingMinInSyncValuesSuccessfully()
throws ValidationException, ConfigurationException {
Map<String, String> config = new HashMap<>();
config.put("replication.factor", "3");

Topic topic = new Topic("topic", config);
MinInSyncReplicasValidation validation = new MinInSyncReplicasValidation();
validation.valid(topic);
}
}

0 comments on commit 3765517

Please sign in to comment.