1#!/usr/bin/env python 2"""Run Integ Tests based on the changed files 3 4""" 5from subprocess import call, check_call, Popen, PIPE 6 7# Minimal modules to tests when core changes are detected. 8# s3 - xml, dynamodb - json, sqs - query 9core_modules_to_test = ["s3", "dynamodb", "sqs"] 10 11# Minimal modules to tests when http client changes are detected. 12# s3 - streaming/non streaming, kinesis - h2 13http_modules_to_test = { 14 "apache-client": ["s3", "apache-client"], 15 "netty-nio-client": ["kinesis", "s3", "netty-nio-client"], 16 "url-connection-client": ["url-connection-client"] 17} 18 19def check_diffs(): 20 """ 21 Retrieve the changed files 22 """ 23 process = Popen(["git", "diff", "HEAD^", "--name-only"], stdout=PIPE) 24 25 diff, stderr = process.communicate() 26 27 if process.returncode !=0: 28 raise Exception("Unable to do git diff") 29 return diff.splitlines(False) 30 31def get_modules(file_path): 32 """ 33 Parse the changed file path and get the respective module names 34 """ 35 path = file_path.split('/') 36 37 # filter out non-java file 38 if not path[-1].endswith(".java"): 39 return 40 41 top_directory = path[0] 42 43 if top_directory in ["core", "codegen"]: 44 return core_modules_to_test 45 if top_directory in ["http-clients"]: 46 return http_modules_to_test.get(path[1]) 47 elif top_directory== "services": 48 return path[1] 49 50def run_tests(modules): 51 """ 52 Run integration tests for the given modules 53 """ 54 print("Running integ tests in the following modules: " + ', '.join(modules)) 55 modules_to_include = "" 56 57 for m in modules: 58 modules_to_include += ":" + m + "," 59 60 # remove last comma 61 modules_to_include = modules_to_include[:-1] 62 63 # build necessary dependencies first 64 check_call(["mvn", "clean", "install", "-pl", modules_to_include, "-P", "quick", "--am"]) 65 check_call(["mvn", "verify", "-pl", modules_to_include, "-P", "integration-tests", "-Dfailsafe.rerunFailingTestsCount=1"]) 66 67if __name__ == "__main__": 68 diffs = check_diffs() 69 modules = set() 70 for d in diffs: 71 module = get_modules(d) 72 if isinstance(module, list): 73 modules.update(module) 74 elif module: 75 modules.add(module) 76 77 if modules: 78 run_tests(modules) 79 else: 80 print("No modules configured to run. Skipping integ tests") 81