Skip to content

Commit dfc4aea

Browse files
author
Mark Kittisopikul
committed
Test JavaCall under @async
1 parent 7ebf526 commit dfc4aea

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ jobs:
3030
branches:
3131
only:
3232
- master
33+
- test_async
3334
- /release-.*/
3435

3536
notifications:

test/runtests.jl

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,23 @@ import Dates
55
using Base.GC: gc
66

77

8-
JavaCall.init(["-Djava.class.path=$(@__DIR__)"])
9-
# JavaCall.init(["-verbose:gc","-Djava.class.path=$(@__DIR__)"])
10-
# JavaCall.init()
8+
macro testasync(x)
9+
:( @test (@sync @async eval($x)).result ) |> esc
10+
end
11+
macro syncasync(x)
12+
:( (@sync @async eval($x)).result ) |> esc
13+
end
14+
15+
16+
@testset "initialization" begin
17+
if JavaCall.JULIA_COPY_STACKS || Sys.iswindows()
18+
@testasync JavaCall.init(["-Djava.class.path=$(@__DIR__)"])==nothing
19+
else
20+
@test JavaCall.init(["-Djava.class.path=$(@__DIR__)"])==nothing
21+
end
22+
# JavaCall.init(["-verbose:gc","-Djava.class.path=$(@__DIR__)"])
23+
# JavaCall.init()
24+
end
1125

1226
System = @jimport java.lang.System
1327
@info "Java Version: ", jcall(System, "getProperty", JString, (JString,), "java.version")
@@ -47,6 +61,16 @@ end
4761
@test 1 == jcall(jlm, "abs", jint, (jint,), -1)
4862
end
4963

64+
@testset "static_method_call_async_1" begin
65+
jlm = @jimport "java.lang.Math"
66+
if JavaCall.JULIA_COPY_STACKS || Sys.iswindows()
67+
@testasync 1.0 jcall(jlm, "sin", jdouble, (jdouble,), pi/2)
68+
@testasync 1.0 jcall(jlm, "min", jdouble, (jdouble,jdouble), 1,2)
69+
@testasync 1 == jcall(jlm, "abs", jint, (jint,), -1)
70+
end
71+
end
72+
73+
5074
@testset "instance_methods_1" begin
5175
jnu = @jimport java.net.URL
5276
gurl = jnu((JString,), "https://en.wikipedia.org")
@@ -230,6 +254,14 @@ end
230254
@test isa(narrow(o), JString)
231255
end
232256

257+
@testset "isroottask_1" begin
258+
@test JavaCall.isroottask()
259+
@testasync JavaCall.JULIA_COPY_STACKS || ! JavaCall.isroottask()
260+
if ! JavaCall.JULIA_COPY_STACKS && ! Sys.iswindows()
261+
@test_throws CompositeException @syncasync JavaCall.assertroottask()
262+
@warn "Ran tests for root Task only. REPL and @async are not expected to work with JavaCall. Set JULIA_COPY_STACKS=1 in the environment to test @async function."
263+
end
264+
end
233265

234266
# At the end, unload the JVM before exiting
235267
JavaCall.destroy()

0 commit comments

Comments
 (0)