GitHub user original-brownbear opened a pull request:

    https://github.com/apache/kafka/pull/2761

    KAFKA-4692: Make testNo thread safe

    https://issues.apache.org/jira/browse/KAFKA-4692 should be resolved by this.
    
    The problem here (or at least one problem, causing trouble) appears to have 
been that the `testNo` field is not thread-safe the way it is used here 
(`volatile` doesn't help anything really) to generate a unique test number (for 
creating non-conflicting topic names).
    If two instances of this class are set up inside the same fork and 
`testNo++;` is run in one just as the other runs e.g. 
    
    ```java
        private void createTopics() throws InterruptedException {
            streamOneInput = "stream-one-" + testNo;
            outputTopic = "output-" + testNo;
            CLUSTER.createTopic(streamOneInput, 3, 1);
            CLUSTER.createTopic(outputTopic);
        }
    ```
    
    then both will have the same value for the topic names while sharing the 
same static `CLUSTER` field too.
    I fixed this by simply making the actually used `testNo` an instance 
variable that is derived from an increasing static counter for each test in an 
atomic way. I think this should resolve any naming collisions here.


You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/original-brownbear/kafka KAFKA-4692

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/kafka/pull/2761.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #2761
    
----
commit 4d2468318897f37b00dab0ad63c36ae3004a9165
Author: Armin Braun <m...@obrown.io>
Date:   2017-03-29T19:27:59Z

    KAFKA-4692: Make testNo thread safe

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to