Search in sources :

Example 6 with ListOffsetsPartition

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());
}
Also used : ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic) ListOffsetsTopicResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse) ListOffsetsPartitionResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse) ListOffsetsResponseData(org.apache.kafka.common.message.ListOffsetsResponseData) Test(org.junit.jupiter.api.Test)

Example 7 with ListOffsetsPartition

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());
    }
}
Also used : ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic) ListOffsetsTopicResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse) ListOffsetsPartitionResponse(org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse) ListOffsetsResponseData(org.apache.kafka.common.message.ListOffsetsResponseData) Test(org.junit.jupiter.api.Test)

Example 8 with ListOffsetsPartition

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());
}
Also used : ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) ListOffsetsRequestData(org.apache.kafka.common.message.ListOffsetsRequestData) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic) TopicPartition(org.apache.kafka.common.TopicPartition) Test(org.junit.jupiter.api.Test)

Example 9 with ListOffsetsPartition

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()));
}
Also used : ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic) Test(org.junit.jupiter.api.Test)

Example 10 with ListOffsetsPartition

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);
    }
}
Also used : ListOffsetsPartition(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition) ListOffsetsTopic(org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic)

Aggregations

ListOffsetsPartition (org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsPartition)14 ListOffsetsTopic (org.apache.kafka.common.message.ListOffsetsRequestData.ListOffsetsTopic)11 TopicPartition (org.apache.kafka.common.TopicPartition)7 Test (org.junit.jupiter.api.Test)7 HashMap (java.util.HashMap)5 Node (org.apache.kafka.common.Node)5 ListOffsetsPartitionResponse (org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsPartitionResponse)5 ListOffsetsTopicResponse (org.apache.kafka.common.message.ListOffsetsResponseData.ListOffsetsTopicResponse)5 Map (java.util.Map)4 ListOffsetsResponseData (org.apache.kafka.common.message.ListOffsetsResponseData)4 ArrayList (java.util.ArrayList)3 ListOffsetsRequest (org.apache.kafka.common.requests.ListOffsetsRequest)3 LinkedHashMap (java.util.LinkedHashMap)2 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)2 RetriableException (org.apache.kafka.common.errors.RetriableException)2 InetSocketAddress (java.net.InetSocketAddress)1 InvalidKeyException (java.security.InvalidKeyException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Duration (java.time.Duration)1 Arrays (java.util.Arrays)1