Search in sources :

Example 36 with TopicPartition

use of org.apache.kafka.common.TopicPartition in project kafka by apache.

the class RequestResponseTest method createFetchResponse.

private FetchResponse createFetchResponse() {
    LinkedHashMap<TopicPartition, FetchResponse.PartitionData> responseData = new LinkedHashMap<>();
    MemoryRecords records = MemoryRecords.readableRecords(ByteBuffer.allocate(10));
    responseData.put(new TopicPartition("test", 0), new FetchResponse.PartitionData(Errors.NONE, 1000000, records));
    return new FetchResponse(responseData, 25);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) LinkedHashMap(java.util.LinkedHashMap) MemoryRecords(org.apache.kafka.common.record.MemoryRecords)

Example 37 with TopicPartition

use of org.apache.kafka.common.TopicPartition in project kafka by apache.

the class RequestResponseTest method createStopReplicaResponse.

private StopReplicaResponse createStopReplicaResponse() {
    Map<TopicPartition, Errors> responses = new HashMap<>();
    responses.put(new TopicPartition("test", 0), Errors.NONE);
    return new StopReplicaResponse(Errors.NONE, responses);
}
Also used : Errors(org.apache.kafka.common.protocol.Errors) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 38 with TopicPartition

use of org.apache.kafka.common.TopicPartition in project kafka by apache.

the class RequestResponseTest method createProduceRequest.

private ProduceRequest createProduceRequest() {
    Map<TopicPartition, MemoryRecords> produceData = new HashMap<>();
    produceData.put(new TopicPartition("test", 0), MemoryRecords.readableRecords(ByteBuffer.allocate(10)));
    return new ProduceRequest.Builder((short) 1, 5000, produceData).build();
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition) MemoryRecords(org.apache.kafka.common.record.MemoryRecords)

Example 39 with TopicPartition

use of org.apache.kafka.common.TopicPartition in project kafka by apache.

the class RequestResponseTest method createProduceResponse.

private ProduceResponse createProduceResponse() {
    Map<TopicPartition, ProduceResponse.PartitionResponse> responseData = new HashMap<>();
    responseData.put(new TopicPartition("test", 0), new ProduceResponse.PartitionResponse(Errors.NONE, 10000, Record.NO_TIMESTAMP));
    return new ProduceResponse(responseData, 0);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition)

Example 40 with TopicPartition

use of org.apache.kafka.common.TopicPartition in project kafka by apache.

the class RequestResponseTest method produceResponseVersionTest.

@Test
public void produceResponseVersionTest() {
    Map<TopicPartition, ProduceResponse.PartitionResponse> responseData = new HashMap<>();
    responseData.put(new TopicPartition("test", 0), new ProduceResponse.PartitionResponse(Errors.NONE, 10000, Record.NO_TIMESTAMP));
    ProduceResponse v0Response = new ProduceResponse(responseData);
    ProduceResponse v1Response = new ProduceResponse(responseData, 10);
    ProduceResponse v2Response = new ProduceResponse(responseData, 10);
    assertEquals("Throttle time must be zero", 0, v0Response.getThrottleTime());
    assertEquals("Throttle time must be 10", 10, v1Response.getThrottleTime());
    assertEquals("Throttle time must be 10", 10, v2Response.getThrottleTime());
    assertEquals("Should use schema version 0", ApiKeys.PRODUCE.responseSchema((short) 0), v0Response.toStruct((short) 0).schema());
    assertEquals("Should use schema version 1", ApiKeys.PRODUCE.responseSchema((short) 1), v1Response.toStruct((short) 1).schema());
    assertEquals("Should use schema version 2", ApiKeys.PRODUCE.responseSchema((short) 2), v2Response.toStruct((short) 2).schema());
    assertEquals("Response data does not match", responseData, v0Response.responses());
    assertEquals("Response data does not match", responseData, v1Response.responses());
    assertEquals("Response data does not match", responseData, v2Response.responses());
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TopicPartition(org.apache.kafka.common.TopicPartition) Test(org.junit.Test)

Aggregations

TopicPartition (org.apache.kafka.common.TopicPartition)257 HashMap (java.util.HashMap)135 Test (org.junit.Test)97 Map (java.util.Map)64 ArrayList (java.util.ArrayList)50 HashSet (java.util.HashSet)44 LinkedHashMap (java.util.LinkedHashMap)39 PartitionInfo (org.apache.kafka.common.PartitionInfo)34 TaskId (org.apache.kafka.streams.processor.TaskId)33 OffsetAndMetadata (org.apache.kafka.clients.consumer.OffsetAndMetadata)29 Set (java.util.Set)28 List (java.util.List)26 Metrics (org.apache.kafka.common.metrics.Metrics)20 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)19 Node (org.apache.kafka.common.Node)19 StreamsConfig (org.apache.kafka.streams.StreamsConfig)19 Properties (java.util.Properties)18 MockTime (org.apache.kafka.common.utils.MockTime)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)15 Collection (java.util.Collection)13