Search in sources :

Example 6 with FetchSessionHandler

use of org.apache.kafka.clients.FetchSessionHandler in project kafka by apache.

the class FetchSessionBenchmark method setUp.

@Setup(Level.Trial)
public void setUp() {
    fetches = new LinkedHashMap<>();
    handler = new FetchSessionHandler(LOG_CONTEXT, 1);
    topicIds = new HashMap<>();
    FetchSessionHandler.Builder builder = handler.newBuilder();
    Uuid id = Uuid.randomUuid();
    topicIds.put("foo", id);
    LinkedHashMap<TopicIdPartition, FetchResponseData.PartitionData> respMap = new LinkedHashMap<>();
    for (int i = 0; i < partitionCount; i++) {
        TopicPartition tp = new TopicPartition("foo", i);
        FetchRequest.PartitionData partitionData = new FetchRequest.PartitionData(id, 0, 0, 200, Optional.empty());
        fetches.put(tp, partitionData);
        builder.add(tp, partitionData);
        respMap.put(new TopicIdPartition(id, tp), new FetchResponseData.PartitionData().setPartitionIndex(tp.partition()).setLastStableOffset(0).setLogStartOffset(0));
    }
    builder.build();
    // build and handle an initial response so that the next fetch will be incremental
    handler.handleResponse(FetchResponse.of(Errors.NONE, 0, 1, respMap), ApiKeys.FETCH.latestVersion());
    int counter = 0;
    for (TopicPartition topicPartition : new ArrayList<>(fetches.keySet())) {
        if (updatedPercentage != 0 && counter % (100 / updatedPercentage) == 0) {
            // reorder in fetch session, and update log start offset
            fetches.remove(topicPartition);
            fetches.put(topicPartition, new FetchRequest.PartitionData(id, 50, 40, 200, Optional.empty()));
        }
        counter++;
    }
}
Also used : ArrayList(java.util.ArrayList) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) LinkedHashMap(java.util.LinkedHashMap) FetchSessionHandler(org.apache.kafka.clients.FetchSessionHandler) Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) FetchRequest(org.apache.kafka.common.requests.FetchRequest) Setup(org.openjdk.jmh.annotations.Setup)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)6 FetchSessionHandler (org.apache.kafka.clients.FetchSessionHandler)6 TopicPartition (org.apache.kafka.common.TopicPartition)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Node (org.apache.kafka.common.Node)5 FetchRequest (org.apache.kafka.common.requests.FetchRequest)5 HashSet (java.util.HashSet)3 Set (java.util.Set)3 Uuid (org.apache.kafka.common.Uuid)3 FetchResponse (org.apache.kafka.common.requests.FetchResponse)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 ClientResponse (org.apache.kafka.clients.ClientResponse)2 Cluster (org.apache.kafka.common.Cluster)2 TopicIdPartition (org.apache.kafka.common.TopicIdPartition)2 FetchResponseData (org.apache.kafka.common.message.FetchResponseData)2 RecordBatch (org.apache.kafka.common.record.RecordBatch)2 DataOutputStream (java.io.DataOutputStream)1 Field (java.lang.reflect.Field)1