use of io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY in project zilla by aklivity.
the class KafkaFunctionsTest method shouldMatchFetchDataExtensionHeaderWithNullValue.
@Test
public void shouldMatchFetchDataExtensionHeaderWithNullValue() throws Exception {
BytesMatcher matcher = KafkaFunctions.matchDataEx().fetch().header("name", null).build().build();
ByteBuffer byteBuf = ByteBuffer.allocate(1024);
new KafkaDataExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).fetch(f -> f.timestamp(12345678L).partition(p -> p.partitionId(0).partitionOffset(0L)).key(k -> k.length(5).value(v -> v.set("match".getBytes(UTF_8)))).delta(d -> d.type(t -> t.set(KafkaDeltaType.NONE))).headersItem(h -> h.nameLen(4).name(n -> n.set("name".getBytes(UTF_8))).valueLen(-1).value((OctetsFW) null))).build();
assertNotNull(matcher.match(byteBuf));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY in project zilla by aklivity.
the class KafkaFunctionsTest method shouldMatchProduceDataExtensionHeader.
@Test
public void shouldMatchProduceDataExtensionHeader() throws Exception {
BytesMatcher matcher = KafkaFunctions.matchDataEx().produce().header("name", "value").build().build();
ByteBuffer byteBuf = ByteBuffer.allocate(1024);
new KafkaDataExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).produce(p -> p.timestamp(12345678L).sequence(0).key(k -> k.length(5).value(v -> v.set("match".getBytes(UTF_8)))).headersItem(h -> h.nameLen(4).name(n -> n.set("name".getBytes(UTF_8))).valueLen(5).value(v -> v.set("value".getBytes(UTF_8))))).build();
assertNotNull(matcher.match(byteBuf));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY in project zilla by aklivity.
the class KafkaFunctionsTest method shouldNotMatchMergedDataExtensionPartition.
@Test(expected = Exception.class)
public void shouldNotMatchMergedDataExtensionPartition() throws Exception {
BytesMatcher matcher = KafkaFunctions.matchDataEx().typeId(0x01).merged().partition(0, 1L).timestamp(12345678L).build().build();
ByteBuffer byteBuf = ByteBuffer.allocate(1024);
new KafkaDataExFW.Builder().wrap(new UnsafeBuffer(byteBuf), 0, byteBuf.capacity()).typeId(0x01).merged(f -> f.timestamp(12345678L).partition(p -> p.partitionId(0).partitionOffset(0L)).progressItem(p -> p.partitionId(0).partitionOffset(1L)).key(k -> k.value(v -> v.set("match".getBytes(UTF_8)))).delta(d -> d.type(t -> t.set(KafkaDeltaType.NONE))).headersItem(h -> h.name(n -> n.set("name".getBytes(UTF_8))).value(v -> v.set("value".getBytes(UTF_8))))).build();
matcher.match(byteBuf);
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateMergedDataExtensionWithByteArrayValue.
@Test
public void shouldGenerateMergedDataExtensionWithByteArrayValue() {
byte[] build = KafkaFunctions.dataEx().typeId(0x01).merged().deferred(100).timestamp(12345678L).partition(0, 0L).progress(0, 1L).key("match").headerBytes("name", "value".getBytes(UTF_8)).build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaDataExFW dataEx = new KafkaDataExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, dataEx.typeId());
assertEquals(KafkaApi.MERGED.value(), dataEx.kind());
final KafkaMergedDataExFW mergedDataEx = dataEx.merged();
assertEquals(100, mergedDataEx.deferred());
assertEquals(12345678L, mergedDataEx.timestamp());
final KafkaOffsetFW partition = mergedDataEx.partition();
assertEquals(0, partition.partitionId());
assertEquals(0L, partition.partitionOffset());
final MutableInteger progressCount = new MutableInteger();
mergedDataEx.progress().forEach(f -> progressCount.value++);
assertEquals(1, progressCount.value);
assertNotNull(mergedDataEx.progress().matchFirst(p -> p.partitionId() == 0 && p.partitionOffset() == 1L));
assertEquals("match", mergedDataEx.key().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
final MutableInteger headersCount = new MutableInteger();
mergedDataEx.headers().forEach(f -> headersCount.value++);
assertEquals(1, headersCount.value);
assertNotNull(mergedDataEx.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