Best Python code snippet using localstack_python
thundra.py
Source:thundra.py
...69 # install Thundra Java agent JAR file70 if not os.path.exists(THUNDRA_JAVA_AGENT_LOCAL_PATH):71 install.log_install_msg("Thundra Java agent", verbatim=True)72 install.download(THUNDRA_JAVA_AGENT_REMOTE_URL, THUNDRA_JAVA_AGENT_LOCAL_PATH)73def _is_java8_lambda(func_details):74 runtime = getattr(func_details, "runtime", func_details)75 return runtime == LAMBDA_RUNTIME_JAVA8 or runtime == LAMBDA_RUNTIME_JAVA8_AL276class LambdaExecutorPluginThundra(LambdaExecutorPlugin):77 def initialize(self):78 # If Thundra API key is initialized, init at startup79 if THUNDRA_APIKEY:80 _ensure_java_agent_initialized()81 def should_apply(self, context: InvocationContext) -> bool:82 # plugin currently only applied for Java Lambdas, if LAMBDA_REMOTE_DOCKER=0, and if API key is configured83 if not is_java_lambda(context.lambda_function.runtime):84 return False85 if "docker" in config.LAMBDA_EXECUTOR and config.LAMBDA_REMOTE_DOCKER:86 return False87 thundra_apikey = _get_apikey(context.environment)88 if not thundra_apikey:89 return False90 return True91 def prepare_invocation(92 self, context: InvocationContext93 ) -> Optional[AdditionalInvocationOptions]:94 # download and initialize Java agent95 _ensure_java_agent_initialized()96 result = AdditionalInvocationOptions()97 environment = context.environment98 agent_flag = "-javaagent:{agent_path}"99 # Inject Thundra agent path into "JAVA_TOOL_OPTIONS" env var,100 # so it will be automatically loaded on JVM startup101 java_tool_opts = environment.get("JAVA_TOOL_OPTIONS", "")102 if agent_flag not in java_tool_opts:103 java_tool_opts += f" {agent_flag}"104 result.env_updates["JAVA_TOOL_OPTIONS"] = java_tool_opts.strip()105 # Disable CDS (Class Data Sharing),106 # because "-javaagent" cannot be enabled when CDS is enabled on JDK 8.107 # CDS can only be disabled by "_JAVA_OPTIONS" env var,108 # because by default it is enabled ("-Xshare:on")109 # on Lambci by command line parameters and110 # "_JAVA_OPTIONS" has precedence over command line parameters111 # but "JAVA_TOOL_OPTIONS" is not.112 if _is_java8_lambda(context.lambda_function):113 java_opts = environment.get("_JAVA_OPTIONS", "")114 java_opts += " -Xshare:off"115 result.env_updates["_JAVA_OPTIONS"] = java_opts.strip()116 # If log disable is not configured explicitly, set it to false to enable log capturing by default117 log_disabled = environment.get(THUNDRA_AGENT_LOG_DISABLE_VAR_NAME)118 if not log_disabled:119 result.env_updates[THUNDRA_AGENT_LOG_DISABLE_VAR_NAME] = "false"120 # make sure API key is contained in environment121 result.env_updates[THUNDRA_APIKEY_ENV_VAR_NAME] = _get_apikey(environment)122 # Note: The code below doesn't seem to be required, as LAMBDA_EXECUTOR=local also picks up $JAVA_TOOL_OPTIONS123 # if context.lambda_command:124 # result.updated_command = context.lambda_command.replace(125 # "java ", f"java {agent_flag} ", 1126 # )...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!