Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • Feb 01 07:26

    dependabot[bot] on gradle

    (compare)

  • Feb 01 07:26

    xvik on master

    Bump com.github.ben-manes.versi… Merge pull request #275 from xv… (compare)

  • Feb 01 07:26
    xvik closed #275
  • Jan 31 23:01
    dependabot[bot] labeled #275
  • Jan 31 23:01
    dependabot[bot] opened #275
  • Jan 31 23:01

    dependabot[bot] on gradle

    Bump com.github.ben-manes.versi… (compare)

  • Jan 31 05:38

    dependabot[bot] on gradle

    (compare)

  • Jan 31 05:38

    xvik on master

    Bump com.gradle.enterprise from… Merge pull request #274 from xv… (compare)

  • Jan 31 05:38
    xvik closed #274
  • Jan 30 23:02
    dependabot[bot] labeled #274
  • Jan 30 23:02

    dependabot[bot] on gradle

    Bump com.gradle.enterprise from… (compare)

  • Jan 30 23:02
    dependabot[bot] opened #274
  • Jan 27 05:03

    dependabot[bot] on gradle

    (compare)

  • Jan 27 05:02

    xvik on master

    Bump system-stubs-jupiter from … Merge pull request #273 from xv… (compare)

  • Jan 27 05:02
    xvik closed #273
  • Jan 26 23:01
    dependabot[bot] labeled #273
  • Jan 26 23:01

    dependabot[bot] on gradle

    Bump system-stubs-jupiter from … (compare)

  • Jan 26 23:01
    dependabot[bot] opened #273
  • Jan 05 11:59

    xvik on freedom

    no hk2 check add contracts debug (compare)

  • Jan 05 09:41

    dependabot[bot] on gradle

    (compare)

Eddie Xie
@oeddyo
image.png
so the two classes are almost identical
if AppResourceIT runs first and bind 30000, for some reason in AccountResourceIT it will say 30000 is used (even though it should use port 20000)
Vyacheslav Rusakov
@xvik
i'll try to reproduce
Eddie Xie
@oeddyo
cool. i can make a minimized version
did you try to run multiple tests in parallel with TestDropwizardAppExtension?
Vyacheslav Rusakov
@xvik
no)
Vyacheslav Rusakov
@xvik
aaaah got it!
it wiill not work, configOverrides work through the system properties: so each test bind override with ConfigOverride#addToSystemProperties:
public void addToSystemProperties() {
        System.setProperty(propertyPrefix + key, value.get());
    }
Vyacheslav Rusakov
@xvik
Use 0 instead of exact port number: dropwizard will apply random ports itself and everythong will work
Eddie Xie
@oeddyo
wooohooo
let me try it
Eddie Xie
@oeddyo
when you say "use 0 instead off exact port number", do you mean on client use 0 or set ConfigOverride.config(server.applicationConnectors[0].port, 0)?
Vyacheslav Rusakov
@xvik
on server
on client you can retrieve application port using rule instance: DROPWIZARD.getLocalPort()
Eddie Xie
@oeddyo
got it! Trying it out now
Eddie Xie
@oeddyo
works like a charm!
Vyacheslav Rusakov
@xvik
great!
Eddie Xie
@oeddyo
thanks for a ton! I'll never discover if you set port as 0 DW will just use a random number lol
Vyacheslav Rusakov
@xvik
:)
Eddie Xie
@oeddyo
Hi @xvik I'm having some trouble setting dynamic db-jdbc. I think the problem is identical with the one we had yesterday (i.e. ConfigOverride.config will write to system property)
currently i'm doing dropwizardApp = new DropwizardAppExtension<>( HttpServer.class, "src/test/resources/dropwizard-test-config.yml", ConfigOverride.config( "database.url", singleInstancePostgresExtension.getEmbeddedPostgres().getJdbcUrl( "postgres", "postgres") ), ConfigOverride.config( "server.applicationConnectors[0].port", String.valueOf(0) ), ConfigOverride.config( "server.adminConnectors[0].port", String.valueOf(0) ), ConfigOverride.config( "engine.indexDataPrefix", tempDir.toAbsolutePath().toString() ) );
image.png
database.url is set dynamically. but then when running multiple test cases they get overriden by each other. Is there any way I can set the db url dynamically just like how we set the port?
Vyacheslav Rusakov
@xvik
hi! No, as ConfigOverride works through system propertirs it is not suitable for parallel tests. You need custom support inside your application: store embedded db credentials in some ThreadLocal variable and application should lookup it on startup and use if custom data available.
Eddie Xie
@oeddyo
does that mean I can't use DropwizardAppExtension<HttpServerConfiguration> any more since it loads from a yml file? or is there any way to override db credential programmatically?
Vyacheslav Rusakov
@xvik
there is always a way to do something programmatically. It will just be specific to your exact application. Just add a new condition somewhere (if someLookup.getUrl != null then use it else use url from configuration)

does that mean I can't use DropwizardAppExtension<HttpServerConfiguration> any more since it loads from a yml file

It's not a problem, in dropwizard you always have control how configuration is applied to code and always can modify it

Eddie Xie
@oeddyo

sorry I should've asked this better.

So my question really is for writing an extension using DropwizardAppExtension and dynamically set database (with embededPostgres). In the extension I'll construct a dropwizard app, and then for each test class I'll have a different port for postgres so they don’t conflict with each other.

Then let's say there are two test classes A, B uses this extension. So in A, the system property of database.url will be set to pg://A. When A starts, A will set the system property "dw.database.url" to "pg://A"

and when B starts, B will sets it to "pg://B". However A didn’t knonw and will keep using "pg://B" which causes problems when run in parallel.

So I guess this is where the confusion comes from. I think there might be one possibility and would like to hear what you think:

I would like to not use the same system property for A and B. Maybe "A.dw.database.url" and "B.dw.database.url". But I need to let DW know that it’s no longer "dw.database.url" that it should read DB settings from

Vyacheslav Rusakov
@xvik
mmm! i just thought! there is a way to overcome property limitation!
ConfigOverride maps configuration properties to system properties with custom prefix (dw. by default). And you can(!!!) change this prefix!
Eddie Xie
@oeddyo
saw the "prefix" param too. But I assume in DW internal it's expecting dw.database.url instead of A.dw.database.url?
Vyacheslav Rusakov
@xvik
 new DropwizardAppExtension<>(
            HttpServer.class,
            "src/test/resources/dropwizard-test-config.yml",
          "randomPrefixString",
            ConfigOverride.config("randomPrefixString",
                "database.url",
                singleInstancePostgresExtension.getEmbeddedPostgres().getJdbcUrl(
                    "postgres", "postgres")
            ),
            ConfigOverride.config("randomPrefixString",
                "server.applicationConnectors[0].port", String.valueOf(0)
            ),
            ConfigOverride.config("randomPrefixString",
                "server.adminConnectors[0].port", String.valueOf(0)
            ),
            ConfigOverride.config("randomPrefixString",
                "engine.indexDataPrefix",
                tempDir.toAbsolutePath().toString()
            )
        );
you configure prefix for DropwizardAppExtension and use the same prefix in each ConfigOverride
"randomPrefixString"
I will use this technique in guicey extensions so they would be independent out of the box! thank you for the idea! :)
Eddie Xie
@oeddyo
lol credits are all yours. I'm standing on your shoulder and peeking only
I meant that: if I use a prefix like you mentioned, for instance use the test class's name
io.dropwizard.configuration.ConfigurationValidationException: src/test/resources/dropwizard-test-config.yml has an error:
  * dataSourceFactory.url must not be empty
it complains that it needs to have url
oh
Vyacheslav Rusakov
@xvik
I suppose "oh" means you got what was wrong
Eddie Xie
@oeddyo
let me try it out. was missing the "each" part
ah!
oh my god can't believe this is real
image.png
yes your solution works!
Vyacheslav Rusakov
@xvik
))
Eddie Xie
@oeddyo
amazing! Not going to be ass kissing but this guicey project is the most amazing one-man OS project I've seen lol