Smart filter offset binding (#2732)

* adding "offset" var to smart filter binding

Co-authored-by: iliax <ikuramshin@provectus.com>
This commit is contained in:
Ilya Kuramshin 2022-10-13 22:41:43 +04:00 committed by GitHub
parent 19e38fb1bf
commit 8b91f50af5
2 changed files with 8 additions and 0 deletions

View file

@ -43,6 +43,7 @@ public class MessageFilters {
return msg -> { return msg -> {
var bindings = getGroovyEngine().createBindings(); var bindings = getGroovyEngine().createBindings();
bindings.put("partition", msg.getPartition()); bindings.put("partition", msg.getPartition());
bindings.put("offset", msg.getOffset());
bindings.put("timestampMs", msg.getTimestamp().toInstant().toEpochMilli()); bindings.put("timestampMs", msg.getTimestamp().toInstant().toEpochMilli());
bindings.put("keyAsText", msg.getKey()); bindings.put("keyAsText", msg.getKey());
bindings.put("valueAsText", msg.getContent()); bindings.put("valueAsText", msg.getContent());

View file

@ -73,6 +73,13 @@ class MessageFiltersTest {
assertFalse(f.test(msg().partition(0))); assertFalse(f.test(msg().partition(0)));
} }
@Test
void canCheckOffset() {
var f = groovyScriptFilter("offset == 100");
assertTrue(f.test(msg().offset(100L)));
assertFalse(f.test(msg().offset(200L)));
}
@Test @Test
void canCheckTimestampMs() { void canCheckTimestampMs() {
var ts = OffsetDateTime.now(); var ts = OffsetDateTime.now();