hk2
  1. hk2
  2. HK2-179

The testng facility sometimes double-populates the ServiceLocator

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: 2.2.0
    • Fix Version/s: future releases
    • Component/s: None
    • Labels:
      None
    • Environment:

      jdk 7
      linux mint 15 32bit

      Description

      It appears that multiple injection and use of IterableProvider results in multiple instances of the providers being created and returned. I have created a demo project that demonstrates the issue. See:

      https://github.com/saden1/hk2-iterableprovider

      Demo Note:
      Looking at MessageProviderTest it appears that HK2 returns duplicate instances of MessageProvider implementations when it should only return 2 unique providers (HelloMessage and WorldMessage). This behavior is exhibited if you run all the tests but not if you run the MessageProviderTest by itself.

        Activity

        Hide
        jwells added a comment -

        Turns out this bug is a bug in the testng HK2 plugin. It was basically re-populating the ServiceLocator once per test class in the suite.

        Show
        jwells added a comment - Turns out this bug is a bug in the testng HK2 plugin. It was basically re-populating the ServiceLocator once per test class in the suite.
        Hide
        jwells added a comment -

        I have made it such that by default different test classes will get different ServiceLocators by default. I also made sure that even if they DID pick the same name in different test classes that they will get the same ServiceLocator but they will not populate it more than once.

        You can fix this in your test without picking up this fix by choosing different names in @HK2 for the two different test classes.

        Show
        jwells added a comment - I have made it such that by default different test classes will get different ServiceLocators by default. I also made sure that even if they DID pick the same name in different test classes that they will get the same ServiceLocator but they will not populate it more than once. You can fix this in your test without picking up this fix by choosing different names in @HK2 for the two different test classes.
        Hide
        saden added a comment -

        I didn't notice the issue was due to testng adaptor. Thanks for the fix.

        Show
        saden added a comment - I didn't notice the issue was due to testng adaptor. Thanks for the fix.

          People

          • Assignee:
            jwells
            Reporter:
            saden
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: