use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class ReplicationControlManagerTest method testCreateTopics.
@Test
public void testCreateTopics() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replicationControl = ctx.replicationControl;
CreateTopicsRequestData request = new CreateTopicsRequestData();
request.topics().add(new CreatableTopic().setName("foo").setNumPartitions(-1).setReplicationFactor((short) -1));
ControllerResult<CreateTopicsResponseData> result = replicationControl.createTopics(request);
CreateTopicsResponseData expectedResponse = new CreateTopicsResponseData();
expectedResponse.topics().add(new CreatableTopicResult().setName("foo").setErrorCode(Errors.INVALID_REPLICATION_FACTOR.code()).setErrorMessage("Unable to replicate the partition 3 time(s): All " + "brokers are currently fenced."));
assertEquals(expectedResponse, result.response());
ctx.registerBrokers(0, 1, 2);
ctx.unfenceBrokers(0, 1, 2);
ControllerResult<CreateTopicsResponseData> result2 = replicationControl.createTopics(request);
CreateTopicsResponseData expectedResponse2 = new CreateTopicsResponseData();
expectedResponse2.topics().add(new CreatableTopicResult().setName("foo").setNumPartitions(1).setReplicationFactor((short) 3).setErrorMessage(null).setErrorCode((short) 0).setTopicId(result2.response().topics().find("foo").topicId()));
assertEquals(expectedResponse2, result2.response());
ctx.replay(result2.records());
assertEquals(new PartitionRegistration(new int[] { 1, 2, 0 }, new int[] { 1, 2, 0 }, Replicas.NONE, Replicas.NONE, 1, 0, 0), replicationControl.getPartition(((TopicRecord) result2.records().get(0).message()).topicId(), 0));
ControllerResult<CreateTopicsResponseData> result3 = replicationControl.createTopics(request);
CreateTopicsResponseData expectedResponse3 = new CreateTopicsResponseData();
expectedResponse3.topics().add(new CreatableTopicResult().setName("foo").setErrorCode(Errors.TOPIC_ALREADY_EXISTS.code()).setErrorMessage("Topic 'foo' already exists."));
assertEquals(expectedResponse3, result3.response());
Uuid fooId = result2.response().topics().find("foo").topicId();
RecordTestUtils.assertBatchIteratorContains(asList(asList(new ApiMessageAndVersion(new PartitionRecord().setPartitionId(0).setTopicId(fooId).setReplicas(asList(1, 2, 0)).setIsr(asList(1, 2, 0)).setRemovingReplicas(Collections.emptyList()).setAddingReplicas(Collections.emptyList()).setLeader(1).setLeaderEpoch(0).setPartitionEpoch(0), (short) 0), new ApiMessageAndVersion(new TopicRecord().setTopicId(fooId).setName("foo"), (short) 0))), ctx.replicationControl.iterator(Long.MAX_VALUE));
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class PartitionReassignmentRevertTest method testSomeRemoving.
@Test
public void testSomeRemoving() {
PartitionRegistration registration = new PartitionRegistration(new int[] { 3, 2, 1 }, new int[] { 3, 2 }, new int[] { 2, 1 }, Replicas.NONE, 3, 100, 200);
PartitionReassignmentRevert revert = new PartitionReassignmentRevert(registration);
assertEquals(Arrays.asList(3, 2, 1), revert.replicas());
assertEquals(Arrays.asList(3, 2), revert.isr());
assertFalse(revert.unclean());
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class PartitionReassignmentRevertTest method testSomeRemovingAndAdding.
@Test
public void testSomeRemovingAndAdding() {
PartitionRegistration registration = new PartitionRegistration(new int[] { 4, 5, 3, 2, 1 }, new int[] { 4, 5, 2 }, new int[] { 2 }, new int[] { 4, 5 }, 3, 100, 200);
PartitionReassignmentRevert revert = new PartitionReassignmentRevert(registration);
assertEquals(Arrays.asList(3, 2, 1), revert.replicas());
assertEquals(Arrays.asList(2), revert.isr());
assertFalse(revert.unclean());
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class PartitionReassignmentRevertTest method testSomeAdding.
@Test
public void testSomeAdding() {
PartitionRegistration registration = new PartitionRegistration(new int[] { 4, 5, 3, 2, 1 }, new int[] { 4, 5, 2 }, Replicas.NONE, new int[] { 4, 5 }, 3, 100, 200);
PartitionReassignmentRevert revert = new PartitionReassignmentRevert(registration);
assertEquals(Arrays.asList(3, 2, 1), revert.replicas());
assertEquals(Arrays.asList(2), revert.isr());
assertFalse(revert.unclean());
}
use of org.apache.kafka.metadata.PartitionRegistration in project kafka by apache.
the class PartitionReassignmentRevertTest method testIsrSpecialCase.
@Test
public void testIsrSpecialCase() {
PartitionRegistration registration = new PartitionRegistration(new int[] { 4, 5, 3, 2, 1 }, new int[] { 4, 5 }, new int[] { 2 }, new int[] { 4, 5 }, 3, 100, 200);
PartitionReassignmentRevert revert = new PartitionReassignmentRevert(registration);
assertEquals(Arrays.asList(3, 2, 1), revert.replicas());
assertEquals(Arrays.asList(3), revert.isr());
assertTrue(revert.unclean());
}
Aggregations