()
| 16 | }) |
| 17 | |
| 18 | function testJoin() { |
| 19 | test(`basic join operation`, () => { |
| 20 | const graph = new D2() |
| 21 | const inputA = graph.newInput<[number, string]>() |
| 22 | const inputB = graph.newInput<[number, string]>() |
| 23 | const tracker = new KeyedMessageTracker<number, [string, string]>() |
| 24 | |
| 25 | inputA.pipe( |
| 26 | join(inputB), |
| 27 | output((message) => { |
| 28 | tracker.addMessage(message as MultiSet<[number, [string, string]]>) |
| 29 | }), |
| 30 | ) |
| 31 | |
| 32 | graph.finalize() |
| 33 | |
| 34 | inputA.sendData( |
| 35 | new MultiSet([ |
| 36 | [[1, `a`], 1], |
| 37 | [[2, `b`], 1], |
| 38 | ]), |
| 39 | ) |
| 40 | |
| 41 | inputB.sendData( |
| 42 | new MultiSet([ |
| 43 | [[1, `x`], 1], |
| 44 | [[2, `y`], 1], |
| 45 | [[3, `z`], 1], // key 3 only exists in B, so no join output expected |
| 46 | ]), |
| 47 | ) |
| 48 | |
| 49 | graph.run() |
| 50 | |
| 51 | const result = tracker.getResult() |
| 52 | |
| 53 | // Assert only keys that can actually join (1, 2) are affected, not key 3 |
| 54 | assertOnlyKeysAffected(`basic join operation`, result.messages, [1, 2]) |
| 55 | |
| 56 | // Assert the final materialized results are correct |
| 57 | assertKeyedResults( |
| 58 | `basic join operation`, |
| 59 | result, |
| 60 | [ |
| 61 | [1, [`a`, `x`]], |
| 62 | [2, [`b`, `y`]], |
| 63 | ], |
| 64 | 4, // Expected message count |
| 65 | ) |
| 66 | }) |
| 67 | |
| 68 | test(`join with late arriving data`, () => { |
| 69 | const graph = new D2() |
| 70 | const inputA = graph.newInput<[number, string]>() |
| 71 | const inputB = graph.newInput<[number, string]>() |
| 72 | const tracker = new KeyedMessageTracker<number, [string, string]>() |
| 73 | |
| 74 | inputA.pipe( |
| 75 | join(inputB), |
no test coverage detected