async def test__stop_transactions(self, *, manager, producer): await manager._stop_transactions(['0-0', '1-0']) producer.stop_transaction.assert_has_calls([ call('0-0'), call.coro('0-0'), call('1-0'), call.coro('1-0'), ])
async def test__stop_transactions(self, *, manager, producer): await manager._stop_transactions(["0-0", "1-0"]) producer.stop_transaction.assert_has_calls([ call("0-0"), call.coro("0-0"), call("1-0"), call.coro("1-0"), ])
async def test_start_transactions(self, *, manager, producer): manager._start_new_producer = AsyncMock() await manager._start_transactions(['0-0', '1-0']) producer.maybe_begin_transaction.assert_has_calls([ call('0-0'), call.coro('0-0'), call('1-0'), call.coro('1-0'), ])
async def test_del_old_keys(self, *, table): on_window_close = table._on_window_close = AsyncMock( name="on_window_close") table.window = Mock(name="window") table._data = { ("boo", (1.1, 1.4)): "BOO", ("moo", (1.4, 1.6)): "MOO", ("faa", (1.9, 2.0)): "FAA", ("bar", (4.1, 4.2)): "BAR", } table._partition_timestamps = { TP1: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], } table._partition_timestamp_keys = { (TP1, 2.0): [ ("boo", (1.1, 1.4)), ("moo", (1.4, 1.6)), ("faa", (1.9, 2.0)), ], (TP1, 5.0): [ ("bar", (4.1, 4.2)), ], } def get_stale(limit): def is_stale(timestamp, latest_timestamp): return timestamp < limit return is_stale table.window.stale.side_effect = get_stale(4.0) await table._del_old_keys() assert table._partition_timestamps[TP1] == [4.0, 5.0, 6.0, 7.0] assert table.data == {("bar", (4.1, 4.2)): "BAR"} on_window_close.assert_has_calls([ call(("boo", (1.1, 1.4)), "BOO"), call.coro(("boo", (1.1, 1.4)), "BOO"), call(("moo", (1.4, 1.6)), "MOO"), call.coro(("moo", (1.4, 1.6)), "MOO"), call(("faa", (1.9, 2.0)), "FAA"), call.coro(("faa", (1.9, 2.0)), "FAA"), ]) table.last_closed_window = 8.0 table.window.stale.side_effect = get_stale(6.0) await table._del_old_keys() assert not table.data
async def test_on_started(self, *, livecheck): case1 = Mock(name='case1') case2 = Mock(name='case2') livecheck.cases = {'a': case1, 'b': case2} livecheck.add_runtime_dependency = AsyncMock() await livecheck.on_started() livecheck.add_runtime_dependency.assert_has_calls([ call.coro(case1), call.coro(case2), ])
async def test_del_old_keys(self, *, table): on_window_close = table._on_window_close = AsyncMock( name='on_window_close') table.window = Mock(name='window') table._data = { ('boo', (1.1, 1.4)): 'BOO', ('moo', (1.4, 1.6)): 'MOO', ('faa', (1.9, 2.0)): 'FAA', ('bar', (4.1, 4.2)): 'BAR', } table._partition_timestamps = { TP1: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0], } table._partition_timestamp_keys = { (TP1, 2.0): [ ('boo', (1.1, 1.4)), ('moo', (1.4, 1.6)), ('faa', (1.9, 2.0)), ], (TP1, 5.0): [ ('bar', (4.1, 4.2)), ], } def get_stale(limit): def is_stale(timestamp, latest_timestamp): return timestamp < limit return is_stale table.window.stale.side_effect = get_stale(4.0) await table._del_old_keys() assert table._partition_timestamps[TP1] == [4.0, 5.0, 6.0, 7.0] assert table.data == {('bar', (4.1, 4.2)): 'BAR'} on_window_close.assert_has_calls([ call(('boo', (1.1, 1.4)), 'BOO'), call.coro(('boo', (1.1, 1.4)), 'BOO'), call(('moo', (1.4, 1.6)), 'MOO'), call.coro(('moo', (1.4, 1.6)), 'MOO'), call(('faa', (1.9, 2.0)), 'FAA'), call.coro(('faa', (1.9, 2.0)), 'FAA'), ]) table.last_closed_window = 8.0 table.window.stale.side_effect = get_stale(6.0) await table._del_old_keys() assert not table.data
async def test_assign_partitions(self, *, store, app, table): app.assignor.assigned_standbys = Mock(return_value={TP4}) table.changelog_topic.topics = list({ tp.topic for tp in (TP1, TP2, TP4) }) store._try_open_db_for_partition = AsyncMock() await store.assign_partitions(table, {TP1, TP2, TP3, TP4}) store._try_open_db_for_partition.assert_has_calls([ call(TP2.partition), call.coro(TP2.partition), call(TP1.partition), call.coro(TP1.partition), ], any_order=True)