Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 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
  • Nov 28 06:41
    dependabot[bot] commented #268
  • Nov 28 06:40
    dependabot[bot] edited #268
  • Nov 28 06:40

    xvik on master

    update to gradle 7.5 update to spock-junit5 1.2 (compare)

  • Nov 25 23:01

    dependabot[bot] on gradle

    Bump spock-junit5 from 1.1.0 to… (compare)

  • Nov 25 23:01
    dependabot[bot] labeled #268
  • Nov 25 23:01
    dependabot[bot] opened #268
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
now I'm trying to replace the cache with a mock cache in test. I saw in GuiceyHook it's possible but I'm using junit-5. Is there anything I can do now or shall I wait for your changes?
Vyacheslav Rusakov
@xvik
hi!

hooks is a generic mechanism:

GuiceyConfigurationHook hook  = builder -> builder.extensions(...);

here lambda used instead of direct inteface implementation

to register hook: hook.register()
there only problem is to register it before application startap
your junit extension use BeforeAll hook, so it is impossible to register anything beofre extension execution
so you will have to add hooks support inside your extension (to register them before startup)
Eddie Xie
@oeddyo
i see. I'll try out and see if I can get it work
Vyacheslav Rusakov
@xvik
and about formatting: just start ''' on new line. To activate syntax highlighting put language name after it like '''java
Eddie Xie
@oeddyo
ah ok
thanks
hooks doc
Eddie Xie
@oeddyo
neat!
Eddie Xie
@oeddyo
image.png