def test_cross_language_raise_kwargs(shutdown_only): ray.init(job_config=ray.job_config.JobConfig(code_search_path=sys.path)) with pytest.raises(Exception, match="kwargs"): ray.java_function("a", "b").remote(x="arg1") with pytest.raises(Exception, match="kwargs"): ray.java_actor_class("a").remote(x="arg1")
def test_cross_language_raise_kwargs(shutdown_only): ray.init(_load_code_from_local=True, _include_java=True) with pytest.raises(Exception, match="kwargs"): ray.java_function("a", "b").remote(x="arg1") with pytest.raises(Exception, match="kwargs"): ray.java_actor_class("a").remote(x="arg1")
def py_func_call_java_actor(value): assert isinstance(value, bytes) c = ray.java_actor_class( "io.ray.test.CrossLanguageInvocationTest$TestActor") java_actor = c.remote(b"Counter") r = java_actor.concat.remote(value) return ray.get(r)
def py_func_call_java_overloaded_method(): cls = ray.java_actor_class("io.ray.test.ExampleImpl") handle = cls.remote() ref1 = handle.overloadedFunc.remote("first") ref2 = handle.overloadedFunc.remote("first", "second") result = ray.get([ref1, ref2]) assert result == ["first", "firstsecond"] return True
def py_func_call_java_overrided_method_with_default_keyword(): cls = ray.java_actor_class("io.ray.test.ExampleImpl") handle = cls.remote() return ray.get(handle.echo.remote("hi"))
""" Ray driver calling ray.init() and connecting to auto ray runtime. Ensure to start ray from the console to run this one: $ ray start --head --port=6379 """ import ray ray.init( address="auto", job_config=ray.job_config.JobConfig(code_search_path='../scala-pi.jar'), ) pi_spark_class = ray.java_actor_class("org.example.application.PiSpark") pi_spark = pi_spark_class.remote() pi_spark_compute_ref = pi_spark.computePi.remote(5000) print(f"Pi is: {ray.get(pi_spark_compute_ref)}")
def __init__(self): self._python_gateway_actor = ray.java_actor_class( GatewayClient._PYTHON_GATEWAY_CLASSNAME).remote()
import ray import time from ray_echo import RayEcho # Crates a RayEcho in a worker process. ray.init(address="auto", job_config=ray.job_config.JobConfig(code_search_path=["echo.jar"])) echo_actor = RayEcho.remote() # instantiate java actors java_echo_class = ray.java_actor_class("org.example.application.EchoClient") java_handles = [java_echo_class.remote(i) for i in range(0, 4)] java_echo_refs = [java_handle.addEcho.remote(echo_actor) for java_handle in java_handles] java_echo_results = [ ray.get(java_echo_ref) for java_echo_ref in java_echo_refs] time.sleep(2) echoes = ray.get(echo_actor.get_echoes.remote()) assert len(echoes) == 4 print(echoes)