def test_checkpointer_exception(): exception_name = 'ThisIsATestException' checkpointer = kcl.Checkpointer( build_basic_io_handler_mock(['{"action": "checkpoint",' '"checkpoint":"456", "sequenceNumber": "1234", "subSequenceNumber": 0, ' '"error" : "' + exception_name + '"}'])) try: checkpointer.checkpoint() assert 0, "Checkpointing should have raised an exception" except kcl.CheckpointError as e: assert e.value == exception_name
def test_checkpointer_unexpected_message_after_checkpointing(): io_handler = Mock() io_handler.read_line.side_effect = ['{"action":"initialize", "shardId" : "shardid-123", ' '"sequenceNumber": "1234", "subSequenceNumber": 1}', ] io_handler.load_action.side_effect = lambda x: json.loads(x, object_hook=dispatch.message_decode) checkpointer = kcl.Checkpointer( build_basic_io_handler_mock( ['{"action":"initialize", "shardId" : "shardid-123", "sequenceNumber": "1234", "subSequenceNumber": 1}'])) try: checkpointer.checkpoint() assert 0, "Checkpointing should have raised an exception" except kcl.CheckpointError as e: assert e.value == 'InvalidStateException'