use of org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic in project kafka by apache.
the class RequestResponseTest method createCreateTopicRequest.
private CreateTopicsRequest createCreateTopicRequest(short version, boolean validateOnly) {
CreateTopicsRequestData data = new CreateTopicsRequestData().setTimeoutMs(123).setValidateOnly(validateOnly);
data.topics().add(new CreatableTopic().setNumPartitions(3).setReplicationFactor((short) 5));
CreatableTopic topic2 = new CreatableTopic();
data.topics().add(topic2);
topic2.assignments().add(new CreatableReplicaAssignment().setPartitionIndex(0).setBrokerIds(asList(1, 2, 3)));
topic2.assignments().add(new CreatableReplicaAssignment().setPartitionIndex(1).setBrokerIds(asList(2, 3, 4)));
topic2.configs().add(new CreateableTopicConfig().setName("config1").setValue("value1"));
return new CreateTopicsRequest.Builder(data).build(version);
}
use of org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic in project kafka by apache.
the class RequestResponseTest method testCreateTopicRequestV3FailsIfNoPartitionsOrReplicas.
@Test
public void testCreateTopicRequestV3FailsIfNoPartitionsOrReplicas() {
final UnsupportedVersionException exception = assertThrows(UnsupportedVersionException.class, () -> {
CreateTopicsRequestData data = new CreateTopicsRequestData().setTimeoutMs(123).setValidateOnly(false);
data.topics().add(new CreatableTopic().setName("foo").setNumPartitions(CreateTopicsRequest.NO_NUM_PARTITIONS).setReplicationFactor((short) 1));
data.topics().add(new CreatableTopic().setName("bar").setNumPartitions(1).setReplicationFactor(CreateTopicsRequest.NO_REPLICATION_FACTOR));
new Builder(data).build((short) 3);
});
assertTrue(exception.getMessage().contains("supported in CreateTopicRequest version 4+"));
assertTrue(exception.getMessage().contains("[foo, bar]"));
}
use of org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic in project kafka by apache.
the class QuorumControllerTest method testSnapshotConfiguration.
@Test
public void testSnapshotConfiguration() throws Throwable {
final int numBrokers = 4;
final int maxNewRecordBytes = 4;
Map<Integer, Long> brokerEpochs = new HashMap<>();
Uuid fooId;
try (LocalLogManagerTestEnv logEnv = new LocalLogManagerTestEnv(3, Optional.empty())) {
try (QuorumControllerTestEnv controlEnv = new QuorumControllerTestEnv(logEnv, builder -> {
builder.setConfigDefs(CONFIGS).setSnapshotMaxNewRecordBytes(maxNewRecordBytes);
})) {
QuorumController active = controlEnv.activeController();
for (int i = 0; i < numBrokers; i++) {
BrokerRegistrationReply reply = active.registerBroker(new BrokerRegistrationRequestData().setBrokerId(i).setRack(null).setClusterId(active.clusterId()).setIncarnationId(Uuid.fromString("kxAT73dKQsitIedpiPtwB" + i)).setListeners(new ListenerCollection(Arrays.asList(new Listener().setName("PLAINTEXT").setHost("localhost").setPort(9092 + i)).iterator()))).get();
brokerEpochs.put(i, reply.epoch());
}
for (int i = 0; i < numBrokers - 1; i++) {
assertEquals(new BrokerHeartbeatReply(true, false, false, false), active.processBrokerHeartbeat(new BrokerHeartbeatRequestData().setWantFence(false).setBrokerEpoch(brokerEpochs.get(i)).setBrokerId(i).setCurrentMetadataOffset(100000L)).get());
}
CreateTopicsResponseData fooData = active.createTopics(new CreateTopicsRequestData().setTopics(new CreatableTopicCollection(Collections.singleton(new CreatableTopic().setName("foo").setNumPartitions(-1).setReplicationFactor((short) -1).setAssignments(new CreatableReplicaAssignmentCollection(Arrays.asList(new CreatableReplicaAssignment().setPartitionIndex(0).setBrokerIds(Arrays.asList(0, 1, 2)), new CreatableReplicaAssignment().setPartitionIndex(1).setBrokerIds(Arrays.asList(1, 2, 0))).iterator()))).iterator()))).get();
fooId = fooData.topics().find("foo").topicId();
active.allocateProducerIds(new AllocateProducerIdsRequestData().setBrokerId(0).setBrokerEpoch(brokerEpochs.get(0))).get();
SnapshotReader<ApiMessageAndVersion> snapshot = createSnapshotReader(logEnv.waitForLatestSnapshot());
checkSnapshotSubcontent(expectedSnapshotContent(fooId, brokerEpochs), snapshot);
}
}
}
use of org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic in project kafka by apache.
the class ReplicationControlManagerTest method testGlobalTopicAndPartitionMetrics.
@Test
public void testGlobalTopicAndPartitionMetrics() 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));
ctx.registerBrokers(0, 1, 2);
ctx.unfenceBrokers(0, 1, 2);
List<Uuid> topicsToDelete = new ArrayList<>();
ControllerResult<CreateTopicsResponseData> result = replicationControl.createTopics(request);
topicsToDelete.add(result.response().topics().find("foo").topicId());
RecordTestUtils.replayAll(replicationControl, result.records());
assertEquals(1, ctx.metrics.globalTopicsCount());
request = new CreateTopicsRequestData();
request.topics().add(new CreatableTopic().setName("bar").setNumPartitions(1).setReplicationFactor((short) -1));
request.topics().add(new CreatableTopic().setName("baz").setNumPartitions(2).setReplicationFactor((short) -1));
result = replicationControl.createTopics(request);
RecordTestUtils.replayAll(replicationControl, result.records());
assertEquals(3, ctx.metrics.globalTopicsCount());
assertEquals(4, ctx.metrics.globalPartitionCount());
topicsToDelete.add(result.response().topics().find("baz").topicId());
ControllerResult<Map<Uuid, ApiError>> deleteResult = replicationControl.deleteTopics(topicsToDelete);
RecordTestUtils.replayAll(replicationControl, deleteResult.records());
assertEquals(1, ctx.metrics.globalTopicsCount());
assertEquals(1, ctx.metrics.globalPartitionCount());
Uuid topicToDelete = result.response().topics().find("bar").topicId();
deleteResult = replicationControl.deleteTopics(Collections.singletonList(topicToDelete));
RecordTestUtils.replayAll(replicationControl, deleteResult.records());
assertEquals(0, ctx.metrics.globalTopicsCount());
assertEquals(0, ctx.metrics.globalPartitionCount());
}
use of org.apache.kafka.common.message.CreateTopicsRequestData.CreatableTopic in project kafka by apache.
the class ReplicationControlManagerTest method testDeleteTopics.
@Test
public void testDeleteTopics() throws Exception {
ReplicationControlTestContext ctx = new ReplicationControlTestContext();
ReplicationControlManager replicationControl = ctx.replicationControl;
CreateTopicsRequestData request = new CreateTopicsRequestData();
CreateTopicsRequestData.CreateableTopicConfigCollection requestConfigs = new CreateTopicsRequestData.CreateableTopicConfigCollection();
requestConfigs.add(new CreateTopicsRequestData.CreateableTopicConfig().setName("cleanup.policy").setValue("compact"));
requestConfigs.add(new CreateTopicsRequestData.CreateableTopicConfig().setName("min.cleanable.dirty.ratio").setValue("0.1"));
request.topics().add(new CreatableTopic().setName("foo").setNumPartitions(3).setReplicationFactor((short) 2).setConfigs(requestConfigs));
ctx.registerBrokers(0, 1);
ctx.unfenceBrokers(0, 1);
ControllerResult<CreateTopicsResponseData> createResult = replicationControl.createTopics(request);
CreateTopicsResponseData expectedResponse = new CreateTopicsResponseData();
Uuid topicId = createResult.response().topics().find("foo").topicId();
expectedResponse.topics().add(new CreatableTopicResult().setName("foo").setNumPartitions(3).setReplicationFactor((short) 2).setErrorMessage(null).setErrorCode((short) 0).setTopicId(topicId));
assertEquals(expectedResponse, createResult.response());
// Until the records are replayed, no changes are made
assertNull(replicationControl.getPartition(topicId, 0));
assertEmptyTopicConfigs(ctx, "foo");
ctx.replay(createResult.records());
assertNotNull(replicationControl.getPartition(topicId, 0));
assertNotNull(replicationControl.getPartition(topicId, 1));
assertNotNull(replicationControl.getPartition(topicId, 2));
assertNull(replicationControl.getPartition(topicId, 3));
assertCreatedTopicConfigs(ctx, "foo", requestConfigs);
assertEquals(singletonMap(topicId, new ResultOrError<>("foo")), replicationControl.findTopicNames(Long.MAX_VALUE, Collections.singleton(topicId)));
assertEquals(singletonMap("foo", new ResultOrError<>(topicId)), replicationControl.findTopicIds(Long.MAX_VALUE, Collections.singleton("foo")));
Uuid invalidId = new Uuid(topicId.getMostSignificantBits() + 1, topicId.getLeastSignificantBits());
assertEquals(singletonMap(invalidId, new ResultOrError<>(new ApiError(UNKNOWN_TOPIC_ID))), replicationControl.findTopicNames(Long.MAX_VALUE, Collections.singleton(invalidId)));
assertEquals(singletonMap("bar", new ResultOrError<>(new ApiError(UNKNOWN_TOPIC_OR_PARTITION))), replicationControl.findTopicIds(Long.MAX_VALUE, Collections.singleton("bar")));
ControllerResult<Map<Uuid, ApiError>> invalidDeleteResult = replicationControl.deleteTopics(Collections.singletonList(invalidId));
assertEquals(0, invalidDeleteResult.records().size());
assertEquals(singletonMap(invalidId, new ApiError(UNKNOWN_TOPIC_ID, null)), invalidDeleteResult.response());
ControllerResult<Map<Uuid, ApiError>> deleteResult = replicationControl.deleteTopics(Collections.singletonList(topicId));
assertTrue(deleteResult.isAtomic());
assertEquals(singletonMap(topicId, new ApiError(NONE, null)), deleteResult.response());
assertEquals(1, deleteResult.records().size());
ctx.replay(deleteResult.records());
assertNull(replicationControl.getPartition(topicId, 0));
assertNull(replicationControl.getPartition(topicId, 1));
assertNull(replicationControl.getPartition(topicId, 2));
assertNull(replicationControl.getPartition(topicId, 3));
assertEquals(singletonMap(topicId, new ResultOrError<>(new ApiError(UNKNOWN_TOPIC_ID))), replicationControl.findTopicNames(Long.MAX_VALUE, Collections.singleton(topicId)));
assertEquals(singletonMap("foo", new ResultOrError<>(new ApiError(UNKNOWN_TOPIC_OR_PARTITION))), replicationControl.findTopicIds(Long.MAX_VALUE, Collections.singleton("foo")));
assertEmptyTopicConfigs(ctx, "foo");
}
Aggregations