use of io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateMergedBeginExtensionWithHeadersFilter.
@Test
public void shouldGenerateMergedBeginExtensionWithHeadersFilter() {
KafkaValueMatchFW valueMatchRO = new KafkaValueMatchFW();
byte[] build = KafkaFunctions.beginEx().typeId(0x01).merged().topic("topic").partition(0, 1L).filter().headers("name").sequence("one", "two").skip(1).sequence("four").skipMany().build().build().build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaBeginExFW beginEx = new KafkaBeginExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, beginEx.typeId());
assertEquals(KafkaApi.MERGED.value(), beginEx.kind());
final KafkaMergedBeginExFW mergedBeginEx = beginEx.merged();
assertEquals("topic", mergedBeginEx.topic().asString());
assertNotNull(mergedBeginEx.partitions().matchFirst(p -> p.partitionId() == 0 && p.partitionOffset() == 1L));
final MutableInteger filterCount = new MutableInteger();
mergedBeginEx.filters().forEach(f -> filterCount.value++);
assertEquals(1, filterCount.value);
assertNotNull(mergedBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == HEADERS.value() && "name".equals(c.headers().name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
assertNotNull(mergedBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> {
boolean matches;
final Array32FW<KafkaValueMatchFW> values = c.headers().values();
final DirectBuffer items = values.items();
int progress = 0;
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches = "one".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= "two".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= KafkaSkip.SKIP == valueMatchRO.skip().get();
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= "four".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= KafkaSkip.SKIP_MANY == valueMatchRO.skip().get();
return c.kind() == HEADERS.value() && matches;
}) != null));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateFetchBeginExtensionWithHeadersFilter.
@Test
public void shouldGenerateFetchBeginExtensionWithHeadersFilter() {
KafkaValueMatchFW valueMatchRO = new KafkaValueMatchFW();
byte[] build = KafkaFunctions.beginEx().typeId(0x01).fetch().topic("topic").partition(0, 1L).filter().headers("name").sequence("one", "two").skip(1).sequence("four").skipMany().build().build().build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaBeginExFW beginEx = new KafkaBeginExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, beginEx.typeId());
assertEquals(KafkaApi.FETCH.value(), beginEx.kind());
final KafkaFetchBeginExFW fetchBeginEx = beginEx.fetch();
assertEquals("topic", fetchBeginEx.topic().asString());
final MutableInteger filterCount = new MutableInteger();
fetchBeginEx.filters().forEach(f -> filterCount.value++);
assertEquals(1, filterCount.value);
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == HEADERS.value() && "name".equals(c.headers().name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> {
boolean matches;
final Array32FW<KafkaValueMatchFW> values = c.headers().values();
final DirectBuffer items = values.items();
int progress = 0;
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches = "one".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= "two".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= KafkaSkip.SKIP == valueMatchRO.skip().get();
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= "four".equals(valueMatchRO.value().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)));
valueMatchRO.wrap(items, progress, items.capacity());
progress = valueMatchRO.limit();
matches &= KafkaSkip.SKIP_MANY == valueMatchRO.skip().get();
return c.kind() == HEADERS.value() && matches;
}) != null));
}
Aggregations