How to use _ensure_java_agent_initialized method in localstack

Best Python code snippet using localstack_python

thundra.py

Source:thundra.py Github

copy

Full Screen

...43 return thundra_apikey44#############45# JAVA AGENT46#############47def _ensure_java_agent_initialized():48 global THUNDRA_JAVA_AGENT_INITIALIZED49 if not THUNDRA_JAVA_AGENT_INITIALIZED:50 _init_java_agent_configs()51 _install_java_agent()52 THUNDRA_JAVA_AGENT_INITIALIZED = True53def _init_java_agent_configs():54 global THUNDRA_JAVA_AGENT_REMOTE_URL55 global THUNDRA_JAVA_AGENT_LOCAL_PATH56 metadata_url = (57 "https://repo.thundra.io/service/local/repositories/thundra-releases/content/"58 + "io/thundra/agent/thundra-agent-lambda-bootstrap/maven-metadata.xml"59 )60 latest_version = get_latest_java_agent_version(metadata_url)61 version = os.getenv("THUNDRA_AGENT_JAVA_VERSION", latest_version)62 jar_name = "thundra-agent-%s.jar" % version63 THUNDRA_JAVA_AGENT_REMOTE_URL = (64 "https://repo.thundra.io/service/local/artifact/maven/redirect?"65 + "r=thundra-releases&g=io.thundra.agent&a=thundra-agent-lambda-bootstrap&v={v}"66 ).format(v=version)67 THUNDRA_JAVA_AGENT_LOCAL_PATH = "%s/%s" % (config.TMP_FOLDER, jar_name)68def _install_java_agent():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 and...

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful