Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Validate if car allows for using the bundled JDK #987

Merged
merged 11 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions esrally/mechanic/provisioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, build_type, car_env, car_runtime_jdks, car_provides_bundled_j
self.build_type = build_type
self.car_env = car_env
self.car_runtime_jdks = car_runtime_jdks
self.car_provides_bundled_jdk = convert.to_bool(car_provides_bundled_jdk)
self.car_provides_bundled_jdk = car_provides_bundled_jdk
self.ip = ip
self.node_name = node_name
self.node_root_path = node_root_path
Expand Down Expand Up @@ -197,7 +197,7 @@ def prepare(self, binary):
installer.invoke_install_hook(team.BootstrapPhase.post_install, provisioner_vars.copy())

return NodeConfiguration("tar", self.es_installer.car.env, self.es_installer.car.mandatory_var("runtime.jdk"),
self.es_installer.car.mandatory_var("runtime.jdk.bundled"),
convert.to_bool(self.es_installer.car.mandatory_var("runtime.jdk.bundled")),
self.es_installer.node_ip, self.es_installer.node_name,
self.es_installer.node_root_dir, self.es_installer.es_home_path,
self.es_installer.data_paths)
Expand Down Expand Up @@ -464,7 +464,7 @@ def prepare(self, binary):
f.write(docker_cfg)

return NodeConfiguration("docker", self.car.env, self.car.mandatory_var("runtime.jdk"),
self.car.mandatory_var("runtime.jdk.bundled"), self.node_ip,
convert.to_bool(self.car.mandatory_var("runtime.jdk.bundled")), self.node_ip,
self.node_name, self.node_root_dir, self.binary_path, self.data_paths)

def docker_vars(self, mounts):
Expand Down
35 changes: 9 additions & 26 deletions tests/mechanic/java_resolver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,35 @@
import unittest.mock as mock
from unittest import TestCase

from esrally import config, exceptions
from esrally import exceptions
from esrally.mechanic import java_resolver


class JavaResolverTests(TestCase):
@mock.patch("esrally.utils.jvm.resolve_path")
def test_resolves_java_home_for_default_runtime_jdk(self, resolve_jvm_path):
resolve_jvm_path.return_value = (12, "/opt/jdk12")

cfg = config.Config()
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", None)

major, java_home = java_resolver.java_home("12,11,10,9,8",
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"),
specified_runtime_jdk=None,
provides_bundled_jdk=True)

self.assertEqual(major, 12)
self.assertEqual(java_home, "/opt/jdk12")
self.assertEqual(major, resolve_jvm_path.return_value[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous implementation was more readable, even if we duplicate code. However, the scope of duplication is within the test method so this is ok IMHO.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

im fine w/ either. I just hate reusing strings in a test method in general, cuz things can get out of sync. I can revert.

self.assertEqual(java_home, resolve_jvm_path.return_value[1])

@mock.patch("esrally.utils.jvm.resolve_path")
def test_resolves_java_home_for_specific_runtime_jdk(self, resolve_jvm_path):
resolve_jvm_path.return_value = (8, "/opt/jdk8")

cfg = config.Config()
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", 8)

major, java_home = java_resolver.java_home("12,11,10,9,8",
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"),
specified_runtime_jdk=8,
provides_bundled_jdk=True)

self.assertEqual(major, 8)
self.assertEqual(java_home, "/opt/jdk8")
self.assertEqual(major, resolve_jvm_path.return_value[0])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the previous implementation was more readable, even if we duplicate code. However, the scope of duplication is within the test method so this is ok IMHO.

self.assertEqual(java_home, resolve_jvm_path.return_value[1])
resolve_jvm_path.assert_called_with([8])

def test_resolves_java_home_for_bundled_jdk(self):

cfg = config.Config()
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", "bundled")

major, java_home = java_resolver.java_home("12,11,10,9,8",
specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"),
specified_runtime_jdk="bundled",
provides_bundled_jdk=True)

# assumes most recent JDK
Expand All @@ -67,12 +55,7 @@ def test_resolves_java_home_for_bundled_jdk(self):
self.assertEqual(java_home, None)

def test_disallowed_bundled_jdk(self):

cfg = config.Config()
cfg.add(config.Scope.application, "mechanic", "runtime.jdk", "bundled")
cfg.add(config.Scope.application, "mechanic", "car.names", ["default"])

with self.assertRaises(exceptions.SystemSetupError) as ctx:
java_resolver.java_home("12,11,10,9,8", specified_runtime_jdk=cfg.opts("mechanic", "runtime.jdk"))
java_resolver.java_home("12,11,10,9,8", specified_runtime_jdk="bundled")
self.assertEqual("This Elasticsearch version does not contain a bundled JDK. Please specify a different runtime JDK.",
ctx.exception.args[0])
6 changes: 3 additions & 3 deletions tests/mechanic/launcher_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ def test_daemon_start_stop(self, wait_for_pidfile, chdir, get_size, supports, ja

node_configs = []
for node in range(2):
node_configs.append(NodeConfiguration(build_type="tar", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk="true",
node_configs.append(NodeConfiguration(build_type="tar", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk=True,
ip="127.0.0.1", node_name="testnode-{}".format(node),
node_root_path="/tmp", binary_path="/tmp", data_paths="/tmp"))

Expand Down Expand Up @@ -364,7 +364,7 @@ def test_starts_container_successfully(self, run_subprocess_with_output, run_sub
cfg = config.Config()
docker = launcher.DockerLauncher(cfg)

node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk="true",
node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk=True,
ip="127.0.0.1", node_name="testnode", node_root_path="/tmp", binary_path="/bin",
data_paths="/tmp")

Expand Down Expand Up @@ -396,7 +396,7 @@ def test_container_not_started(self, run_subprocess_with_output, run_subprocess_
stop_watch = IterationBasedStopWatch(max_iterations=2)
docker = launcher.DockerLauncher(cfg, clock=TestClock(stop_watch=stop_watch))

node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk="true",
node_config = NodeConfiguration(build_type="docker", car_env={}, car_runtime_jdks="12,11", car_provides_bundled_jdk=True,
ip="127.0.0.1", node_name="testnode", node_root_path="/tmp", binary_path="/bin",
data_paths="/tmp")

Expand Down