def test_shift_aware_listener_obj(self): class ListenerClass(TableListener): def __init__(self): self.table_update = None def onUpdate(self, update): self.table_update = update def has_table_changed(self): return self.table_update listener = ListenerClass() table_listener_handle = listen(self.table, listener) time.sleep(2) self.assertTrue(listener.has_table_changed()) table_listener_handle.deregister()
def test_listener_obj_chunk(self): table_update_recorder = TableUpdateRecorder(self.test_table, chunk_size=4) class ListenerClass(TableListener): def on_update(self, update, is_replay): table_update_recorder.record(update, is_replay) listener = ListenerClass() table_listener_handle = listen(self.test_table, listener) ensure_ugp_cycles(table_update_recorder) table_listener_handle.stop() self.check_update_recorder(table_update_recorder, has_replay=False, has_added=True, has_removed=True, has_modified=False)
def test_listener_func_chunk(self): table_update_recorder = TableUpdateRecorder(self.test_table, chunk_size=4) def listener_func(update, is_replay): table_update_recorder.record(update, is_replay) table_listener_handle = listen(self.test_table, listener_func, do_replay=True) ensure_ugp_cycles(table_update_recorder, cycles=3) table_listener_handle.stop() self.check_update_recorder(table_update_recorder, has_replay=True, has_added=True, has_removed=True, has_modified=False)
def test_listener_func_modified_chunk(self): cols = "InWindow" table_update_recorder = TableUpdateRecorder(self.test_table2, chunk_size=1000, cols=cols) def listener_func(update, is_replay): table_update_recorder.record(update, is_replay) table_listener_handle = listen(self.test_table2, listener=listener_func) ensure_ugp_cycles(table_update_recorder) table_listener_handle.stop() self.check_update_recorder(table_update_recorder=table_update_recorder, cols=cols, has_replay=False, has_added=True, has_removed=False, has_modified=True)
def test_shift_aware_listener_func(self): def listener_func(update): added_iterator = update.added.iterator() while added_iterator.hasNext(): idx = added_iterator.nextLong() ts = self.table.j_table.getColumnSource("Timestamp").get(idx) x = self.table.j_table.getColumnSource("X").get(idx) self.table_change_processed = ts or x removed_iterator = update.removed.iterator() while removed_iterator.hasNext(): idx = removed_iterator.nextLong() ts = self.table.j_table.getColumnSource("Timestamp").getPrev( idx) x = self.table.j_table.getColumnSource("X").getPrev(idx) self.table_change_processed = ts or x table_listener_handle = listen(self.table, listener_func) time.sleep(2) self.assertTrue(self.table_change_processed) table_listener_handle.deregister()
def test_shift_oblivious_listener_obj(self): class ListenerClass(TableListener): def __init__(self): self.table_change_added = None self.table_change_removed = None self.table_change_modified = None def onUpdate(self, added, removed, modified): self.table_change_added = added self.table_change_removed = removed self.table_change_modified = modified def has_table_changed(self): return (self.table_change_removed or self.table_change_modified or self.table_change_added) listener = ListenerClass() table_listener_handle = listen(self.table, listener) time.sleep(2) self.assertTrue(listener.has_table_changed()) table_listener_handle.deregister()