Where communities thrive


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

    dependabot[bot] on gradle

    (compare)

  • 05:26

    xvik on master

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

  • 05:26
    xvik closed #270
  • Dec 08 23:01
    dependabot[bot] labeled #270
  • Dec 08 23:01
    dependabot[bot] opened #270
  • Dec 08 23:01

    dependabot[bot] on gradle

    Bump com.gradle.enterprise from… (compare)

  • Dec 05 06:14
    xvik closed #186
  • Dec 05 06:14

    xvik on master

    support ModelProcessor jersey e… (compare)

  • Dec 01 10:34
    xvik labeled #269
  • Dec 01 10:34
    xvik commented #269
  • Dec 01 10:33
    xvik commented #269
  • Dec 01 10:07
    anton-kapelyushok commented #269
  • Dec 01 08:32
    xvik commented #269
  • Nov 30 18:48
    anton-kapelyushok opened #269
  • Nov 30 09:40
    xvik closed #265
  • Nov 30 09:40

    xvik on master

    jersey extensions might omit `@… (compare)

  • Nov 29 07:48

    xvik on master

    fix NoClassDefFoundError(Abstra… (compare)

  • Nov 28 06:41

    dependabot[bot] on gradle

    (compare)

  • Nov 28 06:41
    dependabot[bot] closed #268
  • Nov 28 06:41
    dependabot[bot] edited #268
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
Vyacheslav Rusakov
@xvik
thank you))
Eddie Xie
@oeddyo

Hi @xvik ! I'm using a guava cache in my filter: ``` @Inject
private SessionFactory sessionFactory;

@Inject
public CredentialRequiredFilter(AppDao appDao, Cache<String, App> appCache) {
this.appDao = appDao;
this.appCache = appCache;
}
```

sorry gitter code format is always a mystery to me
image.png