def setup_package(): try: infra.start_infra(async=True) except Exception as e: # make sure to tear down the infrastructure infra.stop_infra() raise e
time.sleep(6) kinesis = aws_stack.connect_to_service('kinesis', env=env) stream = aws_stack.create_kinesis_stream(TEST_STREAM_NAME) records = [ { 'Data': '0', 'ExplicitHashKey': '0', 'PartitionKey': '0' } ] # by default, no errors test_no_errors = kinesis.put_records(StreamName='test-stream-1', Records=records) assert_equal(test_no_errors['FailedRecordCount'], 0) # with a probability of 1, always throw errors constants.KINESIS_ERROR_PROBABILITY = 1.0 test_all_errors = kinesis.put_records(StreamName='test-stream-1', Records=records) assert_equal(test_all_errors['FailedRecordCount'], 1) # reset probability to zero constants.KINESIS_ERROR_PROBABILITY = 0.0 except KeyboardInterrupt, e: infra.KILLED = True finally: print("Shutdown") cleanup(files=True, env=env) infra.stop_infra()
def teardown_package(): print("Shutdown") cleanup(files=True) infra.stop_infra()
for i in range(0, num_events): table.put_item(Item={ PARTITION_KEY: 'testId123', 'data': 'foobar123' }) print("Waiting some time before finishing test.") time.sleep(10) print('DynamoDB updates retrieved via Kinesis (actual/expected): %s/%s' % (len(EVENTS), num_events)) if len(EVENTS) != num_events: print('ERROR receiving DynamoDB updates. Running processes:') print(run("ps aux | grep 'python\|java\|node'")) assert len(EVENTS) == num_events print("Test finished successfully") cleanup(env=env) except KeyboardInterrupt, e: infra.KILLED = True finally: print("Shutdown") cleanup(files=True, env=env) infra.stop_infra() if __name__ == '__main__': args = docopt(__doc__) env = args['--env'] or ENV_DEV start_test(env=env)