use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceDataExFW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateProduceDataExtensionWithNullKeyAndNullHeaderValue.
@Test
public void shouldGenerateProduceDataExtensionWithNullKeyAndNullHeaderValue() {
byte[] build = KafkaFunctions.dataEx().typeId(0x01).produce().timestamp(12345678L).sequence(0).key(null).header("name", null).build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaDataExFW dataEx = new KafkaDataExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, dataEx.typeId());
assertEquals(KafkaApi.PRODUCE.value(), dataEx.kind());
final KafkaProduceDataExFW produceDataEx = dataEx.produce();
assertEquals(12345678L, produceDataEx.timestamp());
assertEquals(0, produceDataEx.sequence());
assertNull(produceDataEx.key().value());
final MutableInteger headersCount = new MutableInteger();
produceDataEx.headers().forEach(f -> headersCount.value++);
assertEquals(1, headersCount.value);
assertNotNull(produceDataEx.headers().matchFirst(h -> "name".equals(h.name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o))) && Objects.isNull(h.value())));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceDataExFW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateProduceDataExtension.
@Test
public void shouldGenerateProduceDataExtension() {
byte[] build = KafkaFunctions.dataEx().typeId(0x01).produce().deferred(10).timestamp(12345678L).sequence(0).key("match").header("name", "value").build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaDataExFW dataEx = new KafkaDataExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, dataEx.typeId());
assertEquals(KafkaApi.PRODUCE.value(), dataEx.kind());
final KafkaProduceDataExFW produceDataEx = dataEx.produce();
assertEquals(10, produceDataEx.deferred());
assertEquals(12345678L, produceDataEx.timestamp());
assertEquals(0, produceDataEx.sequence());
assertEquals("match", produceDataEx.key().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
final MutableInteger headersCount = new MutableInteger();
produceDataEx.headers().forEach(f -> headersCount.value++);
assertEquals(1, headersCount.value);
assertNotNull(produceDataEx.headers().matchFirst(h -> "name".equals(h.name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o))) && "value".equals(h.value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null);
}
Aggregations