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

Avoiding Exceptions during automatic testing #143

Open
RainerHeintzmann opened this issue Apr 23, 2021 · 16 comments
Open

Avoiding Exceptions during automatic testing #143

RainerHeintzmann opened this issue Apr 23, 2021 · 16 comments

Comments

@RainerHeintzmann
Copy link
Contributor

JavaCall throws a java.awt.HeadlessException in Linux systems due to a missing "X11" display specification, when Git-Hub automatic testing is performed. Does anyone know how to avoid this? Also on Mac the tests fail due to a missing java installation. Are there easy fixed for this?

@mkitti
Copy link
Member

mkitti commented Apr 23, 2021

For Mac, set the JAVA_HOME environmental variable to tell JavaCall where to find Java. Where are you getting Java for Mac from?

@mkitti
Copy link
Member

mkitti commented Apr 23, 2021

I will get around to setting GitHub Actions CI here soon.

I would look into something like https://github.com/marketplace/actions/gabrielbb-xvfb-action

@RainerHeintzmann
Copy link
Contributor Author

RainerHeintzmann commented Apr 23, 2021

For Mac, set the JAVA_HOME environmental variable to tell JavaCall where to find Java. Where are you getting Java for Mac from?
Thanks for the hints. Would be great, if the GitHub Actions CI can be convinced to deal with this. These tests work well on the Windows virtual machine (which seems to include a java installation) but they fail for the named reasons on Linux and Mac.

@aviks
Copy link
Collaborator

aviks commented Apr 23, 2021

For headless Java, set java.awt.headless=true

@mkitti
Copy link
Member

mkitti commented Apr 23, 2021

If you need to install Java, then use something like https://github.com/actions/setup-java

@RainerHeintzmann
Copy link
Contributor Author

Thanks. This is in my ci.yml file in .github\workflows, but it seems to have no positive effect on the tests.

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-java@v2
        with:
          distribution: 'adopt' # See 'Supported distributions' for available options
          java-version: '11'

@mkitti
Copy link
Member

mkitti commented Apr 24, 2021

The issue is that JavaCall.jl does not know where adopt put Java, so you need to set the JAVA_HOME environmental variable where it got installed.

@RainerHeintzmann
Copy link
Contributor Author

The problem seems to be the X-Windows system under Linux. GitHub actions works pretty well. Even the installation of the x-windows system seems to run through but it always stops when trying to connect to DISPLAY=:0.0 or any other number I tried.
I disabled the tests on Linux and Mac for now, since I couldn't get it to work. This was the code, which did not work when linux and mac were enabled:
https://github.com/RainerHeintzmann/View5D.jl/blob/master/.github/workflows/ci.yml

@mkitti
Copy link
Member

mkitti commented May 4, 2021

For headless Java, set java.awt.headless=true

Did you try aviks's comment above?

Concretely,

using JavaCall
JavaCall.addOpts("-Djava.awt.headless=true")
# Configure classpath here
JavaCall.init()

@mkitti
Copy link
Member

mkitti commented May 4, 2021

@RainerHeintzmann
Copy link
Contributor Author

Thanks for the hint! This causes other problems, but they are possibly fixable in my Java code.
The headless mode is understandably unhappy to report about its screensize:

Exception in thread "main" java.awt.HeadlessException
        at sun.awt.HeadlessToolkit.getScreenSize(Unknown Source)
        at view5d.View5D.Start5DViewer(View5D.java:532)
start viewers: Error During Test at C:\Users\pi96doc\Documents\Programming\Julia\View5D.jl\test\runtests.jl:9
  Got exception outside of a @test
  JavaCall.JavaCallError("Error calling Java: java.awt.HeadlessException")

I will fix this...

@RainerHeintzmann
Copy link
Contributor Author

Bad news: Even a simple new of a java.applet.Applet object causes the same exception. Rewinding ....

@mkitti
Copy link
Member

mkitti commented May 5, 2021

Aren't applets deprecated as of Java 9? I'm not really sure if there is any way to still use them in a modern browser.

https://www.oracle.com/technetwork/java/javase/migratingfromapplets-2872444.pdf

@mkitti
Copy link
Member

mkitti commented May 5, 2021

I see View5D extends java.applet.Applet so I could see how that might be a complicated to extricate.

@RainerHeintzmann
Copy link
Contributor Author

RainerHeintzmann commented May 5, 2021

Thanks for the hint. I wasn't really aware of this deprecation. So I changed the main class from extending Applet to Container and fixed a few related issues and got it working again, but then the next problem pops up. Looks a bit like a never-ending story with headless graphics:

Exception in thread "main" java.awt.HeadlessException
        at java.awt.GraphicsEnvironment.checkHeadless(Unknown Source)
        at java.awt.Label.<init>(Unknown Source)
        at java.awt.Label.<init>(Unknown Source)
        at view5d.ImgPanel.<init>(ImgPanel.java:199)
        at view5d.View5D.initLayout(View5D.java:867)
        at view5d.View5D.Prepare5DViewer(View5D.java:750)
        at view5d.View5D.Start5DViewer(View5D.java:518)
        at view5d.View5D.Start5DViewer(View5D.java:544)

@mkitti
Copy link
Member

mkitti commented May 5, 2021

See https://www.oracle.com/technical-resources/articles/javase/headless.html

For Linux, this can create a virtual X server:
https://github.com/marketplace/actions/gabrielbb-xvfb-action

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants