Search in sources :

Example 11 with PartitionRegistration

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));
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) TopicRecord(org.apache.kafka.common.metadata.TopicRecord) Uuid(org.apache.kafka.common.Uuid) CreatableTopic(org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic) CreateTopicsRequestData(org.apache.kafka.common.message.CreateTopicsRequestData) ApiMessageAndVersion(org.apache.kafka.server.common.ApiMessageAndVersion) PartitionRecord(org.apache.kafka.common.metadata.PartitionRecord) CreatableTopicResult(org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult) CreateTopicsResponseData(org.apache.kafka.common.message.CreateTopicsResponseData) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 12 with PartitionRegistration

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());
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Test(org.junit.jupiter.api.Test)

Example 13 with PartitionRegistration

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());
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Test(org.junit.jupiter.api.Test)

Example 14 with PartitionRegistration

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());
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Test(org.junit.jupiter.api.Test)

Example 15 with PartitionRegistration

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());
}
Also used : PartitionRegistration(org.apache.kafka.metadata.PartitionRegistration) Test(org.junit.jupiter.api.Test)

Aggregations

PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)26 Uuid (org.apache.kafka.common.Uuid)11 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)10 Test (org.junit.jupiter.api.Test)10 ArrayList (java.util.ArrayList)6 HashMap (java.util.HashMap)6 TopicRecord (org.apache.kafka.common.metadata.TopicRecord)5 List (java.util.List)4 UnknownTopicOrPartitionException (org.apache.kafka.common.errors.UnknownTopicOrPartitionException)4 AlterIsrRequestData (org.apache.kafka.common.message.AlterIsrRequestData)4 AlterIsrResponseData (org.apache.kafka.common.message.AlterIsrResponseData)3 AlterPartitionReassignmentsRequestData (org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData)3 ReassignableTopic (org.apache.kafka.common.message.AlterPartitionReassignmentsRequestData.ReassignableTopic)3 AlterPartitionReassignmentsResponseData (org.apache.kafka.common.message.AlterPartitionReassignmentsResponseData)3 CreatableTopicResult (org.apache.kafka.common.message.CreateTopicsResponseData.CreatableTopicResult)3 PartitionRecord (org.apache.kafka.common.metadata.PartitionRecord)3 ApiError (org.apache.kafka.common.requests.ApiError)3 TimelineInteger (org.apache.kafka.timeline.TimelineInteger)3 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)3 OptionalInt (java.util.OptionalInt)2