mirror of https://github.com/apache/kafka.git
MINOR: Implement toString method for TopicAssignment and PartitionAssignment (#13101)
Implements `toString` method for classes `TopicAssignment` and` PartitionAssignment`. Also removes the `final` keyword from the constructor arguments for consistency. Reviewers: José Armando García Sancio <jsancio@apache.org>
This commit is contained in:
parent
6e7e2e08a9
commit
43f531d87a
|
@ -31,7 +31,7 @@ import java.util.Objects;
|
|||
public class PartitionAssignment {
|
||||
private final List<Integer> replicas;
|
||||
|
||||
public PartitionAssignment(final List<Integer> replicas) {
|
||||
public PartitionAssignment(List<Integer> replicas) {
|
||||
this.replicas = Collections.unmodifiableList(new ArrayList<>(replicas));
|
||||
}
|
||||
|
||||
|
@ -53,4 +53,11 @@ public class PartitionAssignment {
|
|||
public int hashCode() {
|
||||
return Objects.hash(replicas);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "PartitionAssignment" +
|
||||
"(replicas=" + replicas +
|
||||
")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@ import java.util.Objects;
|
|||
public class TopicAssignment {
|
||||
private final List<PartitionAssignment> assignments;
|
||||
|
||||
public TopicAssignment(final List<PartitionAssignment> assignments) {
|
||||
public TopicAssignment(List<PartitionAssignment> assignments) {
|
||||
this.assignments = Collections.unmodifiableList(new ArrayList<>(assignments));
|
||||
}
|
||||
|
||||
|
@ -52,4 +52,11 @@ public class TopicAssignment {
|
|||
public int hashCode() {
|
||||
return Objects.hash(assignments);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "TopicAssignment" +
|
||||
"(assignments=" + assignments +
|
||||
")";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -57,4 +57,11 @@ public class PartitionAssignmentTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
List<Integer> replicas = Arrays.asList(0, 1, 2);
|
||||
PartitionAssignment partitionAssignment = new PartitionAssignment(replicas);
|
||||
assertEquals("PartitionAssignment(replicas=[0, 1, 2])", partitionAssignment.toString());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class TopicAssignmentTest {
|
|||
List<Integer> replicasP1 = Arrays.asList(1, 2, 0);
|
||||
List<PartitionAssignment> partitionAssignments = Arrays.asList(
|
||||
new PartitionAssignment(replicasP0),
|
||||
new PartitionAssignment(replicasP1)
|
||||
new PartitionAssignment(replicasP1)
|
||||
);
|
||||
assertEquals(partitionAssignments, new TopicAssignment(partitionAssignments).assignments());
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ public class TopicAssignmentTest {
|
|||
new PartitionAssignment(
|
||||
Arrays.asList(1, 2, 0)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
@ -70,4 +70,14 @@ public class TopicAssignmentTest {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToString() {
|
||||
List<Integer> replicas = Arrays.asList(0, 1, 2);
|
||||
List<PartitionAssignment> partitionAssignments = Arrays.asList(
|
||||
new PartitionAssignment(replicas)
|
||||
);
|
||||
TopicAssignment topicAssignment = new TopicAssignment(partitionAssignments);
|
||||
assertEquals("TopicAssignment(assignments=[PartitionAssignment(replicas=[0, 1, 2])])", topicAssignment.toString());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue