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

Add helper to Properties class +cleanups #469

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

cies
Copy link
Member

@cies cies commented Oct 11, 2024

We were doing the same thing in many places.

I added a helper method. I can also think of another way to implement this: subclass Properties to PlayProperties and add the helper method there.

@xabolcs Sorry for adding some IntelliJ spelling fixes into this PR. I'm very much in the habit of scanning every file I touch for minor cleanup work.

@cies cies requested a review from asolntsev October 16, 2024 13:43
Copy link
Contributor

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

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

I would add this method to Play.configuration, not to Play.
The the usage will be easier to read:

if (Play.configuration.hasValue("mail.debug", "false", "true"))

than this:
if (configPropWithDefaultEqualsTo("mail.debug", "false", "true"))

@cies
Copy link
Member Author

cies commented Nov 5, 2024

Good point will look at it.

@cies
Copy link
Member Author

cies commented Nov 12, 2024

@asolntsev I've looked into it. I've subclassed Properties (the class of Play.configuration) to ConfigurationProperties and tried to use that instead of Properties: this is quite an invasive change. Properties (the one from java.util) is passed around quite a bit and that then should all become ConfigurationProperties.

I think the resulting PR will look a lot worse than the one I suggested.

Also: there's a Properties implementation in RePlay as well, but that is seemingly unused.

@asolntsev
Copy link
Contributor

this is quite an invasive change

Sorry, I didn't understand why is this an invasive change?
If the new class ConfigurationProperties extends Properties then you don't need to change anything. You can still pass Properties everywhere, and change the type to ConfigurationProperties only in places where the method is needed.

@cies
Copy link
Member Author

cies commented Nov 22, 2024

@asolntsev I've update the branch.

@cies
Copy link
Member Author

cies commented Jan 6, 2025

@asolntsev wrote:

You can still pass Properties everywhere, and change the type to ConfigurationProperties only in places where the method is needed.

Good point. I've updated the branch accordingly.

@cies cies requested a review from asolntsev January 10, 2025 12:25
@cies cies requested a review from asolntsev January 30, 2025 08:07
@cies cies changed the title Add configPropWithDefaultEqualsTo helper +cleanups Add helper to Properties class +cleanups Jan 30, 2025
@cies
Copy link
Member Author

cies commented Jan 30, 2025

I dont know why the ui-tests are so flaky. In CI this fails:

> Task :replay-tests:liquibase-app:uitest-netty4

PetsOverviewSpec > showsAllRegisteredPets() FAILED
    org.openqa.selenium.remote.NoSuchDriverException: Unable to obtain: chromedriver, error Failed to run command: [--browser, chrome, --language-binding, java, --output, json]
    Build info: version: '4.28.0', revision: 'ac342546e9'
    System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.8.0-1020-azure', java.version: '17.0.14'
    Driver info: driver.version: SelenideDriver
        at app//org.openqa.selenium.remote.service.DriverFinder.getBinaryPaths(DriverFinder.java:121)
        at app//org.openqa.selenium.remote.service.DriverFinder.getDriverPath(DriverFinder.java:55)
        at app//org.openqa.selenium.chrome.ChromeDriver.generateExecutor(ChromeDriver.java:99)
        at app//org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:88)
        at app//org.openqa.selenium.chrome.ChromeDriver.<init>(ChromeDriver.java:83)
        at app//com.codeborne.selenide.webdriver.ChromeDriverFactory.create(ChromeDriverFactory.java:28)
        at app//com.codeborne.selenide.webdriver.WebDriverFactory.createWebDriverInstance(WebDriverFactory.java:105)
        at app//com.codeborne.selenide.webdriver.WebDriverFactory.createWebDriver(WebDriverFactory.java:59)
        at app//com.codeborne.selenide.drivercommands.CreateDriverCommand.lambda$createDriver$0(CreateDriverCommand.java:68)
        at app//com.codeborne.selenide.logevents.SelenideLogger.wrap(SelenideLogger.java:128)
        at app//com.codeborne.selenide.logevents.SelenideLogger.get(SelenideLogger.java:106)
        at app//com.codeborne.selenide.drivercommands.CreateDriverCommand.createDriver(CreateDriverCommand.java:44)
        at app//com.codeborne.selenide.WebDriverThreadLocalContainer.createDriver(WebDriverThreadLocalContainer.java:181)
        at app//com.codeborne.selenide.WebDriverThreadLocalContainer.createDriver(WebDriverThreadLocalContainer.java:177)
        at app//com.codeborne.selenide.WebDriverThreadLocalContainer.createAndRegisterDriver(WebDriverThreadLocalContainer.java:164)
        at app//com.codeborne.selenide.WebDriverThreadLocalContainer.getAndCheckWebDriver(WebDriverThreadLocalContainer.java:130)
        at app//com.codeborne.selenide.WebDriverRunner.getAndCheckWebDriver(WebDriverRunner.java:99)
        at app//com.codeborne.selenide.StaticDriver.getAndCheckWebDriver(StaticDriver.java:41)
        at app//com.codeborne.selenide.SelenideDriver.getAndCheckWebDriver(SelenideDriver.java:183)
        at app//com.codeborne.selenide.drivercommands.Navigator.lambda$navigateTo$0(Navigator.java:67)
        at app//com.codeborne.selenide.logevents.SelenideLogger.lambda$run$0(SelenideLogger.java:99)
        at app//com.codeborne.selenide.logevents.SelenideLogger.wrap(SelenideLogger.java:128)
        at app//com.codeborne.selenide.logevents.SelenideLogger.run(SelenideLogger.java:98)
        at app//com.codeborne.selenide.drivercommands.Navigator.navigateTo(Navigator.java:65)
        at app//com.codeborne.selenide.drivercommands.Navigator.open(Navigator.java:29)
        at app//com.codeborne.selenide.SelenideDriver.open(SelenideDriver.java:86)
        at app//com.codeborne.selenide.Selenide.open(Selenide.java:50)
        at app//ui.petstore.PetsOverviewSpec.showsAllRegisteredPets(PetsOverviewSpec.java:14)

        Caused by:
        org.openqa.selenium.WebDriverException: Failed to run command: [--browser, chrome, --language-binding, java, --output, json]
        Build info: version: '4.28.0', revision: 'ac342546e9'
        System info: os.name: 'Linux', os.arch: 'amd64', os.version: '6.8.0-1020-azure', java.version: '17.0.14'
        Driver info: driver.version: SelenideDriver
            at app//org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:151)
            at app//org.openqa.selenium.manager.SeleniumManager.getBinaryPaths(SeleniumManager.java:254)
            at app//org.openqa.selenium.remote.service.DriverFinder.getBinaryPaths(DriverFinder.java:102)
            ... 27 more

            Caused by:
            java.io.UncheckedIOException: java.io.IOException: Cannot run program "/home/runner/.cache/selenium/manager/0.4.28/selenium-manager": error=26, Text file busy
                at org.openqa.selenium.os.ExternalProcess$Builder.start(ExternalProcess.java:195)
                at org.openqa.selenium.manager.SeleniumManager.runCommand(SeleniumManager.java:142)
                ... 29 more

                Caused by:
                java.io.IOException: Cannot run program "/home/runner/.cache/selenium/manager/0.4.28/selenium-manager": error=26, Text file busy
                    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1143)
                    at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1073)
                    at org.openqa.selenium.os.ExternalProcess$Builder.start(ExternalProcess.java:193)
                    ... 30 more

                    Caused by:
                    java.io.IOException: error=26, Text file busy
                        at java.base/java.lang.ProcessImpl.forkAndExec(Native Method)
                        at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:314)
                        at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:244)
                        at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1110)
                        ... 32 more

> Task :replay-tests:helloworld-kotlin:uitest-netty4
> Task :replay-tests:multi-module-app:core:compileJava UP-TO-DATE
> Task :replay-tests:multi-module-app:app:compileJava UP-TO-DATE
> Task :replay-tests:multi-module-app:app:classes UP-TO-DATE
> Task :replay-tests:multi-module-app:app:compileTestJava UP-TO-DATE
> Task :replay-tests:multi-module-app:app:testClasses UP-TO-DATE
> Task :replay-tests:multi-module-app:core:classes UP-TO-DATE
> Task :replay-tests:multi-module-app:core:jar UP-TO-DATE
> Task :replay-tests:helloworld:uitest-netty4
> Task :replay-tests:multi-module-app:core:compileTestJava NO-SOURCE
> Task :replay-tests:multi-module-app:core:testClasses UP-TO-DATE
> Task :replay-tests:multi-module-app:core:uitest-netty4 NO-SOURCE

> Task :replay-tests:liquibase-app:uitest-netty4

3 tests completed, 1 failed

> Task :replay-tests:liquibase-app:uitest-netty4 FAILED

Locally this (./gradlew uitest -Dselenide.browser=firefox -Dselenide.headless=true) failed:

> Task :replay-tests:helloworld-kotlin:uitest-netty3

HelloPdfWorldSpec > downloadHelloWorldPdf() FAILED
    java.io.IOException: Timeout while connecting to or reading from the URL: http://localhost:37701/pdf
        at com.codeborne.pdftest.PDF.readBytes(PDF.java:128)
        at com.codeborne.pdftest.PDF.<init>(PDF.java:85)
        at ui.hello.kotlin.HelloPdfWorldSpec.downloadHelloWorldPdf(HelloPdfWorldSpec.kt:12)

        Caused by:
        java.net.SocketTimeoutException: Read timed out
            at java.base/sun.nio.ch.NioSocketImpl.timedRead(NioSocketImpl.java:288)
            at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:314)
            at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:355)
            at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:808)
            at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
            at java.base/java.io.BufferedInputStream.fill(BufferedInputStream.java:244)
            at java.base/java.io.BufferedInputStream.read1(BufferedInputStream.java:284)
            at java.base/java.io.BufferedInputStream.read(BufferedInputStream.java:343)
            at java.base/sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:826)
            at java.base/sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:761)
            at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1709)
            at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1610)
            at com.codeborne.pdftest.PDF.readBytes(PDF.java:125)
            ... 2 more

3 tests completed, 1 failed

> Task :replay-tests:helloworld-kotlin:uitest-netty3 FAILED

Two completely different test failures, that do not occur consistently over the different contexts (local CLI and remote Github CI)... I think all is fine, but somehow things got flaky.

@cies cies closed this Jan 30, 2025
@cies cies reopened this Jan 30, 2025
Copy link
Contributor

@asolntsev asolntsev left a comment

Choose a reason for hiding this comment

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

LGTM!
Nice job @cies

Accepted with one suggestion to rename PropertyResult -> PropertyValue.

}

/** Helper method of an often recurring type of check on Play's configuration properties. */
public PropertyResult property(final String key, final String defaultValue) {
Copy link
Contributor

Choose a reason for hiding this comment

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

@cies I would name this class PropertyValue, not PropertyResult.
It seems that the word "result" doesn't bring any value, like "PropertyObject" or "PropertyClass".

@asolntsev asolntsev added this to the 2.6.4 milestone Feb 11, 2025
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

Successfully merging this pull request may close these issues.

2 participants