Search in sources :

Example 16 with Uuid

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

the class SimpleExampleMessageTest method testTaggedUuid.

@Test
public void testTaggedUuid() {
    testRoundTrip(new SimpleExampleMessageData(), message -> assertEquals(Uuid.fromString("H3KKO4NTRPaCWtEmm3vW7A"), message.taggedUuid()));
    Uuid randomUuid = Uuid.randomUuid();
    testRoundTrip(new SimpleExampleMessageData().setTaggedUuid(randomUuid), message -> assertEquals(randomUuid, message.taggedUuid()));
}
Also used : Uuid(org.apache.kafka.common.Uuid) Test(org.junit.jupiter.api.Test)

Example 17 with Uuid

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

the class SimpleExampleMessageTest method shouldRoundTripFieldThroughBuffer.

@Test
public void shouldRoundTripFieldThroughBuffer() {
    final Uuid uuid = Uuid.randomUuid();
    final ByteBuffer buf = ByteBuffer.wrap(new byte[] { 1, 2, 3 });
    final SimpleExampleMessageData out = new SimpleExampleMessageData();
    out.setProcessId(uuid);
    out.setZeroCopyByteBuffer(buf);
    final ByteBuffer buffer = MessageUtil.toByteBuffer(out, (short) 1);
    final SimpleExampleMessageData in = new SimpleExampleMessageData();
    in.read(new ByteBufferAccessor(buffer), (short) 1);
    buf.rewind();
    assertEquals(uuid, in.processId());
    assertEquals(buf, in.zeroCopyByteBuffer());
    assertEquals(ByteUtils.EMPTY_BUF, in.nullableZeroCopyByteBuffer());
}
Also used : Uuid(org.apache.kafka.common.Uuid) ByteBufferAccessor(org.apache.kafka.common.protocol.ByteBufferAccessor) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 18 with Uuid

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

the class SimpleExampleMessageTest method shouldImplementEqualsAndHashCode.

@Test
public void shouldImplementEqualsAndHashCode() {
    final Uuid uuid = Uuid.randomUuid();
    final ByteBuffer buf = ByteBuffer.wrap(new byte[] { 1, 2, 3 });
    final SimpleExampleMessageData a = new SimpleExampleMessageData();
    a.setProcessId(uuid);
    a.setZeroCopyByteBuffer(buf);
    final SimpleExampleMessageData b = new SimpleExampleMessageData();
    b.setProcessId(uuid);
    b.setZeroCopyByteBuffer(buf);
    assertEquals(a, b);
    assertEquals(a.hashCode(), b.hashCode());
    // just tagging this on here
    assertEquals(a.toString(), b.toString());
    a.setNullableZeroCopyByteBuffer(buf);
    b.setNullableZeroCopyByteBuffer(buf);
    assertEquals(a, b);
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.toString(), b.toString());
    a.setNullableZeroCopyByteBuffer(null);
    b.setNullableZeroCopyByteBuffer(null);
    assertEquals(a, b);
    assertEquals(a.hashCode(), b.hashCode());
    assertEquals(a.toString(), b.toString());
}
Also used : Uuid(org.apache.kafka.common.Uuid) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.jupiter.api.Test)

Example 19 with Uuid

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

the class RequestResponseTest method createFetchResponse.

private FetchResponse createFetchResponse(boolean includeAborted) {
    LinkedHashMap<TopicIdPartition, FetchResponseData.PartitionData> responseData = new LinkedHashMap<>();
    Uuid topicId = Uuid.randomUuid();
    MemoryRecords records = MemoryRecords.withRecords(CompressionType.NONE, new SimpleRecord("blah".getBytes()));
    responseData.put(new TopicIdPartition(topicId, new TopicPartition("test", 0)), new FetchResponseData.PartitionData().setPartitionIndex(0).setHighWatermark(1000000).setLogStartOffset(0).setRecords(records));
    List<FetchResponseData.AbortedTransaction> abortedTransactions = emptyList();
    if (includeAborted) {
        abortedTransactions = singletonList(new FetchResponseData.AbortedTransaction().setProducerId(234L).setFirstOffset(999L));
    }
    responseData.put(new TopicIdPartition(topicId, new TopicPartition("test", 1)), new FetchResponseData.PartitionData().setPartitionIndex(1).setHighWatermark(1000000).setLogStartOffset(0).setAbortedTransactions(abortedTransactions));
    return FetchResponse.parse(FetchResponse.of(Errors.NONE, 25, INVALID_SESSION_ID, responseData).serialize(FETCH.latestVersion()), FETCH.latestVersion());
}
Also used : FetchResponseData(org.apache.kafka.common.message.FetchResponseData) Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) SimpleRecord(org.apache.kafka.common.record.SimpleRecord) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) LinkedHashMap(java.util.LinkedHashMap) MemoryRecords(org.apache.kafka.common.record.MemoryRecords)

Example 20 with Uuid

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

the class RequestResponseTest method createFetchResponse.

private FetchResponse createFetchResponse(int sessionId) {
    LinkedHashMap<TopicIdPartition, FetchResponseData.PartitionData> responseData = new LinkedHashMap<>();
    Map<String, Uuid> topicIds = new HashMap<>();
    topicIds.put("test", Uuid.randomUuid());
    MemoryRecords records = MemoryRecords.withRecords(CompressionType.NONE, new SimpleRecord("blah".getBytes()));
    responseData.put(new TopicIdPartition(topicIds.get("test"), new TopicPartition("test", 0)), new FetchResponseData.PartitionData().setPartitionIndex(0).setHighWatermark(1000000).setLogStartOffset(0).setRecords(records));
    List<FetchResponseData.AbortedTransaction> abortedTransactions = singletonList(new FetchResponseData.AbortedTransaction().setProducerId(234L).setFirstOffset(999L));
    responseData.put(new TopicIdPartition(topicIds.get("test"), new TopicPartition("test", 1)), new FetchResponseData.PartitionData().setPartitionIndex(1).setHighWatermark(1000000).setLogStartOffset(0).setAbortedTransactions(abortedTransactions));
    return FetchResponse.parse(FetchResponse.of(Errors.NONE, 25, sessionId, responseData).serialize(FETCH.latestVersion()), FETCH.latestVersion());
}
Also used : LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) TopicIdPartition(org.apache.kafka.common.TopicIdPartition) LinkedHashMap(java.util.LinkedHashMap) FetchResponseData(org.apache.kafka.common.message.FetchResponseData) Uuid(org.apache.kafka.common.Uuid) TopicPartition(org.apache.kafka.common.TopicPartition) SimpleRecord(org.apache.kafka.common.record.SimpleRecord) MemoryRecords(org.apache.kafka.common.record.MemoryRecords)

Aggregations

Uuid (org.apache.kafka.common.Uuid)95 Test (org.junit.jupiter.api.Test)55 HashMap (java.util.HashMap)42 TopicPartition (org.apache.kafka.common.TopicPartition)40 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)30 ArrayList (java.util.ArrayList)29 Map (java.util.Map)21 ApiMessageAndVersion (org.apache.kafka.server.common.ApiMessageAndVersion)21 LinkedHashMap (java.util.LinkedHashMap)18 List (java.util.List)15 FetchRequest (org.apache.kafka.common.requests.FetchRequest)14 TopicIdPartition (org.apache.kafka.common.TopicIdPartition)13 Errors (org.apache.kafka.common.protocol.Errors)12 FetchResponse (org.apache.kafka.common.requests.FetchResponse)12 Collections (java.util.Collections)11 ByteBuffer (java.nio.ByteBuffer)10 Node (org.apache.kafka.common.Node)10 CreateTopicsResponseData (org.apache.kafka.common.message.CreateTopicsResponseData)10 MetadataResponse (org.apache.kafka.common.requests.MetadataResponse)10 PartitionRegistration (org.apache.kafka.metadata.PartitionRegistration)10