Search in sources :

Example 41 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class KafkaFunctionsTest method shouldMatchFetchDataExtensionNullKey.

@Test
public void shouldMatchFetchDataExtensionNullKey() throws Exception {
    BytesMatcher matcher = KafkaFunctions.matchDataEx().fetch().key(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(-1).value((OctetsFW) null)).delta(d -> d.type(t -> t.set(KafkaDeltaType.NONE))).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));
}
Also used : KafkaDeltaType(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaDeltaType) KafkaDescribeBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDescribeBeginExFW) ExpressionFactory(javax.el.ExpressionFactory) KafkaDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDataExFW) KafkaSkip(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaSkip) KafkaBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBeginExFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) KafkaBootstrapBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaBootstrapBeginExFW) KafkaOffsetFW(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaOffsetFW) ByteBuffer(java.nio.ByteBuffer) KafkaValueMatchFW(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaValueMatchFW) KafkaMergedFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedFlushExFW) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) KafkaFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFlushExFW) HEADER(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADER) Array32FW(io.aklivity.zilla.specs.binding.kafka.internal.types.Array32FW) KafkaMetaDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMetaDataExFW) MutableInteger(org.agrona.collections.MutableInteger) Before(org.junit.Before) KafkaMergedBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedBeginExFW) KafkaFetchFlushExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchFlushExFW) ExpressionFactoryUtils.newExpressionFactory(org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.newExpressionFactory) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) KafkaMetaBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMetaBeginExFW) Test(org.junit.Test) HEADERS(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.HEADERS) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) OctetsFW(io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW) Objects(java.util.Objects) KafkaFetchDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchDataExFW) Assert.assertNull(org.junit.Assert.assertNull) ExpressionContext(org.kaazing.k3po.lang.internal.el.ExpressionContext) KafkaDescribeDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaDescribeDataExFW) KafkaFetchBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaFetchBeginExFW) NOT(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.NOT) ValueExpression(javax.el.ValueExpression) KafkaApi(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaApi) KEY(io.aklivity.zilla.specs.binding.kafka.internal.types.KafkaConditionType.KEY) KafkaProduceBeginExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceBeginExFW) ELContext(javax.el.ELContext) Assert.assertEquals(org.junit.Assert.assertEquals) KafkaMergedDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaMergedDataExFW) KafkaProduceDataExFW(io.aklivity.zilla.specs.binding.kafka.internal.types.stream.KafkaProduceDataExFW) DirectBuffer(org.agrona.DirectBuffer) OctetsFW(io.aklivity.zilla.specs.binding.kafka.internal.types.OctetsFW) UnsafeBuffer(org.agrona.concurrent.UnsafeBuffer) BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) ByteBuffer(java.nio.ByteBuffer) Test(org.junit.Test)

Example 42 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class SseFunctionsTest method shouldNotMatchDataExtensionWithDifferentTypeId.

@Test
public void shouldNotMatchDataExtensionWithDifferentTypeId() {
    byte[] dataEx = SseFunctions.dataEx().typeId(0x01).timestamp(12345678L).id("id-42").type("custom").build();
    BytesMatcher matcher = SseFunctions.matchDataEx().typeId(0x02).build();
    assertThrows(Exception.class, () -> matcher.match(ByteBuffer.wrap(dataEx)));
}
Also used : BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Test(org.junit.Test)

Example 43 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class SseFunctionsTest method shouldMatchDataExtensionWithInvalidUtf8.

@Test
public void shouldMatchDataExtensionWithInvalidUtf8() throws Exception {
    byte[] dataEx = SseFunctions.dataEx().typeId(0x01).timestamp(12345678L).idAsRawBytes(new byte[] { (byte) 0xc3, 0x28 }).typeAsRawBytes(new byte[] { (byte) 0xc3, 0x28 }).build();
    BytesMatcher matcher = SseFunctions.matchDataEx().typeId(0x01).timestamp(12345678L).idAsRawBytes(new byte[] { (byte) 0xc3, 0x28 }).typeAsRawBytes(new byte[] { (byte) 0xc3, 0x28 }).build();
    assertNotNull(matcher.match(ByteBuffer.wrap(dataEx)));
}
Also used : BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Test(org.junit.Test)

Example 44 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class SseFunctionsTest method shouldNotMatchDataExtensionWithDifferentId.

@Test
public void shouldNotMatchDataExtensionWithDifferentId() {
    byte[] dataEx = SseFunctions.dataEx().typeId(0x01).timestamp(12345678L).id("id-42").type("custom").build();
    BytesMatcher matcher = SseFunctions.matchDataEx().id("id-43").build();
    assertThrows(Exception.class, () -> matcher.match(ByteBuffer.wrap(dataEx)));
}
Also used : BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Test(org.junit.Test)

Example 45 with BytesMatcher

use of org.kaazing.k3po.lang.el.BytesMatcher in project zilla by aklivity.

the class SseFunctionsTest method shouldNotMatchDataExtensionWithDifferentTimestamp.

@Test
public void shouldNotMatchDataExtensionWithDifferentTimestamp() {
    byte[] dataEx = SseFunctions.dataEx().typeId(0x01).timestamp(12345678L).id("id-42").type("custom").build();
    BytesMatcher matcher = SseFunctions.matchDataEx().timestamp(12345679L).build();
    assertThrows(Exception.class, () -> matcher.match(ByteBuffer.wrap(dataEx)));
}
Also used : BytesMatcher(org.kaazing.k3po.lang.el.BytesMatcher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)142 BytesMatcher (org.kaazing.k3po.lang.el.BytesMatcher)142 ByteBuffer (java.nio.ByteBuffer)134 ELContext (javax.el.ELContext)129 DirectBuffer (org.agrona.DirectBuffer)129 UnsafeBuffer (org.agrona.concurrent.UnsafeBuffer)129 Assert.assertEquals (org.junit.Assert.assertEquals)129 Assert.assertNotNull (org.junit.Assert.assertNotNull)129 Assert.assertNull (org.junit.Assert.assertNull)129 ExpressionContext (org.kaazing.k3po.lang.internal.el.ExpressionContext)129 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)69 Assert.assertTrue (org.junit.Assert.assertTrue)69 Method (java.lang.reflect.Method)65 FunctionMapper (javax.el.FunctionMapper)65 Assert.assertSame (org.junit.Assert.assertSame)65 ExpressionFactory (javax.el.ExpressionFactory)64 ValueExpression (javax.el.ValueExpression)64 Assert.assertArrayEquals (org.junit.Assert.assertArrayEquals)64 Before (org.junit.Before)64 ExpressionFactoryUtils.newExpressionFactory (org.kaazing.k3po.lang.internal.el.ExpressionFactoryUtils.newExpressionFactory)64