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

archaius2-guice and Jukito don't play well together #475

Open
petehannam opened this issue Jan 20, 2017 · 0 comments
Open

archaius2-guice and Jukito don't play well together #475

petehannam opened this issue Jan 20, 2017 · 0 comments
Labels

Comments

@petehannam
Copy link

Hi,

We use both archaius & Jukito in our platform, and found that this commit broke our tests.

The symptom is that if you use a Config in one test, then all subsequent tests won't have their Config updated:

This test will pass:

@RunWith(JukitoRunner.class)
@UseModules(Module.class)
public class HangingReferenceTest {

    public static class Module extends AbstractModule {
        @Override
        protected void configure() {
            install(new ArchaiusModule() {

                @Override
                protected void configureArchaius() {
                    Map<String, String> configurationValues = new HashMap<>();

                    configurationValues.put("value1", "one");

                    bindDefaultConfig().toInstance(MapConfig.from(configurationValues));
                }
            });
        }

    }
    
    @Inject
    Provider<Config> configProvider;

    @Test
    public void testConfig() {
        assertThat(configProvider.get().getString("value1"), is("one"));
    }

}

But this test will fail, and if you look through the values of the Config, it just has "value1":

@RunWith(JukitoRunner.class)
@UseModules(Module.class)
public class HangingReference2Test {

    public static class Module extends AbstractModule {
        @Override
        protected void configure() {
            install(new ArchaiusModule() {

                @Override
                protected void configureArchaius() {
                    Map<String, String> configurationValues = new HashMap<>();

                    configurationValues.put("value2", "two");

                    bindDefaultConfig().toInstance(MapConfig.from(configurationValues));
                }
            });
        }

    }

    @Inject
    Provider<Config> configProvider;

    @Test
    public void testConfig() {
        assertThat(configProvider.get().getString("value2"), is("two"));
    }

}

The 'fix' (more on why that's in quotes in a sec), is to change ConfigurationInjectingListener so that the injected Config is injected via a Provider:

public class ConfigurationInjectingListener implements ProvisionListener {
    private static final Logger LOG = LoggerFactory.getLogger(ConfigurationInjectingListener.class);

    @Inject
    private Provider<Config>            config;

    ...

I've been taking Jukito apart this afternoon and narrowed the problem with it down to the way inspects the bindings to identify missing bindings. I'm still not completely sure what's going on, but I'll keep digging.

However, the fact that it's happening with Jukito means it might also happen with others, so wanted to pass this back to you.

The problem I'm having is that I don't feel comfortable just submitting a PR with the above change and no UT. But I can't reproduce it without either adding a test-dependency to Jukito or more-or-less pulling a chunk of Jukito into the test classes.

So... Some sort of steer would be appreciated.
Ta.

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

No branches or pull requests

2 participants