diff options
| author | sangtran <tranquangsang12.7@gmail.com> | 2026-09-12 16:35:06 +0700 |
|---|---|---|
| committer | sangtran <tranquangsang12.7@gmail.com> | 2026-09-12 16:35:06 +0700 |
| commit | 50139c994e539f2f902fc0c06ab29ee93c1bc03c (patch) | |
| tree | 7e355de76444c4eb02a178018dcc4d7ab258c466 /core/operator/watermark_test.go | |
| parent | a7cb942d8b03e325b70ac95238d24939939a4c5a (diff) | |
| signature | Verified sangtran <tranquangsang12.7@gmail.com> Key: 8DD79823D235E1BB ultimate trust | |
| download | flux-main.tar.gz flux-main.zip | |
Diffstat (limited to 'core/operator/watermark_test.go')
| -rw-r--r-- | core/operator/watermark_test.go | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/core/operator/watermark_test.go b/core/operator/watermark_test.go new file mode 100644 index 0000000..0a0495e --- /dev/null +++ b/core/operator/watermark_test.go | |||
| @@ -0,0 +1,58 @@ | |||
| 1 | package operator_test | ||
| 2 | |||
| 3 | import ( | ||
| 4 | "context" | ||
| 5 | "flux/core" | ||
| 6 | "flux/core/operator" | ||
| 7 | "testing" | ||
| 8 | ) | ||
| 9 | |||
| 10 | type timestampEvent struct { | ||
| 11 | EventTime int64 | ||
| 12 | } | ||
| 13 | |||
| 14 | func TestWatermarkGeneratorPreservesAssignedEventTimestamp(t *testing.T) { | ||
| 15 | ctx := context.Background() | ||
| 16 | |||
| 17 | op := operator.NewWatermarkGeneratorOperator[timestampEvent](0) | ||
| 18 | |||
| 19 | if err := op.Open(ctx); err != nil { | ||
| 20 | t.Fatalf("open operator failed: %v", err) | ||
| 21 | } | ||
| 22 | |||
| 23 | t.Cleanup(func() { | ||
| 24 | if err := op.Close(ctx); err != nil { | ||
| 25 | t.Errorf("close operator: %v", err) | ||
| 26 | } | ||
| 27 | }) | ||
| 28 | |||
| 29 | out := &captureEmitter[timestampEvent]{} | ||
| 30 | input := core.NewDataRecord("user-1", timestampEvent{EventTime: 999}, 40) | ||
| 31 | |||
| 32 | if err := op.Process(ctx, input, out); err != nil { | ||
| 33 | t.Fatalf("process operator failed: %v", err) | ||
| 34 | } | ||
| 35 | |||
| 36 | records := out.Records() | ||
| 37 | if len(records) == 0 { | ||
| 38 | t.Fatal("operator emitted no records") | ||
| 39 | } | ||
| 40 | |||
| 41 | got := records[0] | ||
| 42 | |||
| 43 | if got.Type != core.RecordData { | ||
| 44 | t.Fatalf("first output type: got %v, want RecordData", got.Type) | ||
| 45 | } | ||
| 46 | |||
| 47 | if got.Key != "user-1" { | ||
| 48 | t.Errorf("data key: got %q, want %q", got.Key, "user-1") | ||
| 49 | } | ||
| 50 | |||
| 51 | if got.Value != input.Value { | ||
| 52 | t.Errorf("data value: got %+v, want %+v", got.Value, input.Value) | ||
| 53 | } | ||
| 54 | |||
| 55 | if got.Timestamp != 40 { | ||
| 56 | t.Errorf("data timestamp: got %d, want %d", got.Timestamp, 40) | ||
| 57 | } | ||
| 58 | } | ||
