ksqlDB Tests
One interesting feature that ksqlDB has is the test runner, it allows you to test a query before deploying it.
Run a Test
ksql-test-runner -e kafka-ksqldb-extensions/extensions/ \
-s kafka-ksqldb/ksql/create-orders.ksql \
-i kafka-ksqldb/tests/orders-input.json \
-o kafka-ksqldb/tests/orders-output.json | grep ">>>"
Tests
A test has 2 parts, inputs and outputs, the ksqldb test runner will compare then to define if the test passes or fails.
orders-input.json
{
"inputs": [
{"topic": "ksqldb.orders", "timestamp": 0, "key": 1000000, "value": {"orderUnits": 2, "totalAmount": 100.0}},
{"topic": "ksqldb.orders", "timestamp": 0, "key": 1000001, "value": {"orderUnits": 4, "totalAmount": 200.0}},
{"topic": "ksqldb.orders", "timestamp": 0, "key": 1000002, "value": {"orderUnits": 6, "totalAmount": 300.0}},
{"topic": "ksqldb.orders", "timestamp": 0, "key": 1000003, "value": {"orderUnits": 3, "totalAmount": 150.0}},
{"topic": "ksqldb.orders", "timestamp": 0, "key": 1000004, "value": {"orderUnits": 1, "totalAmount": 50.0}}
]
}
orders-output.json
{
"outputs": [
{"topic": "ksqldb.order_sizes", "timestamp": 0, "key": 1000000, "value": {"ORDERUNITS": 2, "TOTALAMOUNT": 100.0, "ORDERSIZE": "medium", "TAX": 12.0}},
{"topic": "ksqldb.order_sizes", "timestamp": 0, "key": 1000001, "value": {"ORDERUNITS": 4, "TOTALAMOUNT": 200.0, "ORDERSIZE": "large" , "TAX": 24.0}},
{"topic": "ksqldb.order_sizes", "timestamp": 0, "key": 1000002, "value": {"ORDERUNITS": 6, "TOTALAMOUNT": 300.0, "ORDERSIZE": "large" , "TAX": 36.0}},
{"topic": "ksqldb.order_sizes", "timestamp": 0, "key": 1000003, "value": {"ORDERUNITS": 3, "TOTALAMOUNT": 150.0, "ORDERSIZE": "medium", "TAX": 18.0}},
{"topic": "ksqldb.order_sizes", "timestamp": 0, "key": 1000004, "value": {"ORDERUNITS": 1, "TOTALAMOUNT": 50.0, "ORDERSIZE": "small" , "TAX": 6.0}}
]
}