use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateDescribeBeginExtension.
@Test
public void shouldGenerateDescribeBeginExtension() {
byte[] build = KafkaFunctions.beginEx().typeId(0x01).describe().topic("topic").config("cleanup.policy").build().build();
DirectBuffer buffer = new UnsafeBuffer(build);
KafkaBeginExFW beginEx = new KafkaBeginExFW().wrap(buffer, 0, buffer.capacity());
assertEquals(0x01, beginEx.typeId());
assertEquals(KafkaApi.DESCRIBE.value(), beginEx.kind());
final KafkaDescribeBeginExFW describeBeginEx = beginEx.describe();
assertEquals("topic", describeBeginEx.topic().asString());
final MutableInteger configsCount = new MutableInteger();
describeBeginEx.configs().forEach(f -> configsCount.value++);
assertEquals(1, configsCount.value);
assertNotNull(describeBeginEx.configs().matchFirst(c -> "cleanup.policy".equals(c.asString())));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateFetchBeginExtensionWithLatestOffset.
@Test
public void shouldGenerateFetchBeginExtensionWithLatestOffset() {
byte[] build = KafkaFunctions.beginEx().typeId(0x01).fetch().topic("topic").partition(0, 0L, 0L).filter().key("match").build().filter().header("name", "value").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 KafkaOffsetFW partition = fetchBeginEx.partition();
assertEquals(0, partition.partitionId());
assertEquals(0L, partition.partitionOffset());
assertEquals(0L, partition.latestOffset());
final MutableInteger filterCount = new MutableInteger();
fetchBeginEx.filters().forEach(f -> filterCount.value++);
assertEquals(2, filterCount.value);
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == KEY.value() && "match".equals(c.key().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == HEADER.value() && "name".equals(c.header().name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o))) && "value".equals(c.header().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW 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));
}
use of io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW in project zilla by aklivity.
the class KafkaFunctionsTest method shouldGenerateFetchBeginExtension.
@Test
public void shouldGenerateFetchBeginExtension() {
byte[] build = KafkaFunctions.beginEx().typeId(0x01).fetch().topic("topic").partition(0, 0L).filter().key("match").build().filter().header("name", "value").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 KafkaOffsetFW partition = fetchBeginEx.partition();
assertEquals(0, partition.partitionId());
assertEquals(0L, partition.partitionOffset());
final MutableInteger filterCount = new MutableInteger();
fetchBeginEx.filters().forEach(f -> filterCount.value++);
assertEquals(2, filterCount.value);
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == KEY.value() && "match".equals(c.key().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
assertNotNull(fetchBeginEx.filters().matchFirst(f -> f.conditions().matchFirst(c -> c.kind() == HEADER.value() && "name".equals(c.header().name().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o))) && "value".equals(c.header().value().get((b, o, m) -> b.getStringWithoutLengthUtf8(o, m - o)))) != null));
}
Aggregations