use of org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition in project kafka by apache.
the class ListOffsetsRequestTest method testGetErrorResponseV0.
@Test
public void testGetErrorResponseV0() {
List<ListOffsetsTopic> topics = Arrays.asList(new ListOffsetsTopic().setName("topic").setPartitions(Collections.singletonList(new ListOffsetsPartition().setPartitionIndex(0))));
ListOffsetsRequest request = ListOffsetsRequest.Builder.forConsumer(true, IsolationLevel.READ_UNCOMMITTED, false).setTargetTimes(topics).build((short) 0);
ListOffsetsResponse response = (ListOffsetsResponse) request.getErrorResponse(0, Errors.NOT_LEADER_OR_FOLLOWER.exception());
List<ListOffsetsTopicResponse> v = Collections.singletonList(new ListOffsetsTopicResponse().setName("topic").setPartitions(Collections.singletonList(new ListOffsetsPartitionResponse().setErrorCode(Errors.NOT_LEADER_OR_FOLLOWER.code()).setOldStyleOffsets(Collections.emptyList()).setPartitionIndex(0))));
ListOffsetsResponseData data = new ListOffsetsResponseData().setThrottleTimeMs(0).setTopics(v);
ListOffsetsResponse expectedResponse = new ListOffsetsResponse(data);
assertEquals(expectedResponse.data().topics(), response.data().topics());
assertEquals(expectedResponse.throttleTimeMs(), response.throttleTimeMs());
}
use of org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition in project kafka by apache.
the class ListOffsetsRequestTest method testGetErrorResponse.
@Test
public void testGetErrorResponse() {
for (short version = 1; version <= ApiKeys.LIST_OFFSETS.latestVersion(); version++) {
List<ListOffsetsTopic> topics = Arrays.asList(new ListOffsetsTopic().setName("topic").setPartitions(Collections.singletonList(new ListOffsetsPartition().setPartitionIndex(0))));
ListOffsetsRequest request = ListOffsetsRequest.Builder.forConsumer(true, IsolationLevel.READ_COMMITTED, false).setTargetTimes(topics).build(version);
ListOffsetsResponse response = (ListOffsetsResponse) request.getErrorResponse(0, Errors.NOT_LEADER_OR_FOLLOWER.exception());
List<ListOffsetsTopicResponse> v = Collections.singletonList(new ListOffsetsTopicResponse().setName("topic").setPartitions(Collections.singletonList(new ListOffsetsPartitionResponse().setErrorCode(Errors.NOT_LEADER_OR_FOLLOWER.code()).setLeaderEpoch(ListOffsetsResponse.UNKNOWN_EPOCH).setOffset(ListOffsetsResponse.UNKNOWN_OFFSET).setPartitionIndex(0).setTimestamp(ListOffsetsResponse.UNKNOWN_TIMESTAMP))));
ListOffsetsResponseData data = new ListOffsetsResponseData().setThrottleTimeMs(0).setTopics(v);
ListOffsetsResponse expectedResponse = new ListOffsetsResponse(data);
assertEquals(expectedResponse.data().topics(), response.data().topics());
assertEquals(expectedResponse.throttleTimeMs(), response.throttleTimeMs());
}
}
use of org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition in project kafka by apache.
the class ListOffsetsRequestTest method testDuplicatePartitions.
@Test
public void testDuplicatePartitions() {
List<ListOffsetsTopic> topics = Collections.singletonList(new ListOffsetsTopic().setName("topic").setPartitions(Arrays.asList(new ListOffsetsPartition().setPartitionIndex(0), new ListOffsetsPartition().setPartitionIndex(0))));
ListOffsetsRequestData data = new ListOffsetsRequestData().setTopics(topics).setReplicaId(-1);
ListOffsetsRequest request = ListOffsetsRequest.parse(MessageUtil.toByteBuffer(data, (short) 0), (short) 0);
assertEquals(Collections.singleton(new TopicPartition("topic", 0)), request.duplicatePartitions());
}
use of org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition in project kafka by apache.
the class MessageTest method testListOffsetsRequestVersions.
@Test
public void testListOffsetsRequestVersions() throws Exception {
List<ListOffsetsTopic> v = Collections.singletonList(new ListOffsetsTopic().setName("topic").setPartitions(Collections.singletonList(new ListOffsetsPartition().setPartitionIndex(0).setTimestamp(123L))));
Supplier<ListOffsetsRequestData> newRequest = () -> new ListOffsetsRequestData().setTopics(v).setReplicaId(0);
testAllMessageRoundTrips(newRequest.get());
testAllMessageRoundTripsFromVersion((short) 2, newRequest.get().setIsolationLevel(IsolationLevel.READ_COMMITTED.id()));
}
use of org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition in project kafka by apache.
the class RequestResponseTest method createListOffsetRequest.
private ListOffsetsRequest createListOffsetRequest(short version) {
if (version == 0) {
ListOffsetsTopic topic = new ListOffsetsTopic().setName("test").setPartitions(singletonList(new ListOffsetsPartition().setPartitionIndex(0).setTimestamp(1000000L).setMaxNumOffsets(10).setCurrentLeaderEpoch(5)));
return ListOffsetsRequest.Builder.forConsumer(false, IsolationLevel.READ_UNCOMMITTED, false).setTargetTimes(singletonList(topic)).build(version);
} else if (version == 1) {
ListOffsetsTopic topic = new ListOffsetsTopic().setName("test").setPartitions(singletonList(new ListOffsetsPartition().setPartitionIndex(0).setTimestamp(1000000L).setCurrentLeaderEpoch(5)));
return ListOffsetsRequest.Builder.forConsumer(true, IsolationLevel.READ_UNCOMMITTED, false).setTargetTimes(singletonList(topic)).build(version);
} else if (version >= 2 && version <= LIST_OFFSETS.latestVersion()) {
ListOffsetsPartition partition = new ListOffsetsPartition().setPartitionIndex(0).setTimestamp(1000000L).setCurrentLeaderEpoch(5);
ListOffsetsTopic topic = new ListOffsetsTopic().setName("test").setPartitions(singletonList(partition));
return ListOffsetsRequest.Builder.forConsumer(true, IsolationLevel.READ_COMMITTED, false).setTargetTimes(singletonList(topic)).build(version);
} else {
throw new IllegalArgumentException("Illegal ListOffsetRequest version " + version);
}
}
Aggregations