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

@Factory with dataProvider changes order of iterations #1467

Merged
merged 4 commits into from
Jul 15, 2017

Conversation

krmahadevan
Copy link
Member

Closes #799

Fixes #799 .

Did you remember to?

  • Add test case(s)
  • Update CHANGES.txt

We encourage pull requests that:

  • Add new features to TestNG (or)
  • Fix bugs in TestNG

If your pull request involves fixing SonarQube issues then we would suggest that you please discuss this with the
TestNG-dev before you spend time working on it.

@krmahadevan
Copy link
Member Author

ping @juherr

Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It really looks promising! 👍


import java.util.Comparator;

public class Systematiser {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a huge fan of the name but I've nothing better to propose :)

public class Systematiser {

private Systematiser() {
//Utility class. Defeat instantiation.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The class should be final too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@@ -121,7 +122,10 @@ public void topologicalSort() {
// Sort the nodes alphabetically to make sure that methods of the same class
// get run close to each other as much as possible
//
Collections.sort(nodes2);
Comparator<Node> comparator = Systematiser.getComparator();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add the Comparator<Node<T>> as constructor param?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didnt quite understand this observation @juherr . Can you please elaborate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comparator should be an attribute of the graph and the comparator instantiation logic should be outside.
The attribute description will be: private final Comparator<Node<T>> comparator and its usage will be Collections.sort(nodes2, comparator).

Copy link
Member Author

@krmahadevan krmahadevan Jul 12, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I understood. But why would the comparator instantiation be plugged into a Graph instance from outside ? The comparator instantiation is completely dependent on just a JVM argument and as such I thought we can have it just query the comparator on an On-Demand basis from Systematiser

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JVM argument is just a quick workaround which should not be used in the core.
I don't like it because it is a global variable which is bad by definition.
That's why I think we should manage the feature from a global point of view but offer JVM arg to the users in order to keep API in the same state.
At the same time, if the integration of the feature modifies all the structure, we may use some temporary tricks and think about the core redesign later.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I have looked at, if one were to be resorting to make this available via a configuration instead of a JVM argument, this is going to require quite a few changes. Also if you look at it, a configuration would still be applicable at the entire TestNG instance level, which is kind of what the JVM argument is doing as well. Does that add a bit of clarity to your question ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to have a deeper look asap.

break;

case NONE:
default:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of null, maybe we can use a default comparator (all params are equals)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

//Utility class. Defeat instantiation.
}

public static Comparator<Graph.Node> getComparator() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comparator<Graph.Node<ITestNGMethod>>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We cannot do this because the INSTANCES one doesn't work with a ITestNGMethod but merely works with just an Object. The ITestNGMethod based comparator also if you notice resorts to using the ITestNGMethod object iff the Node contains an ITestNGMethod object.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't catch it because o1.getObject().toString() will work with Node<ITestNGMethod> too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, this point is important IMO.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@juherr - Ok, but I would like to understand why does Node object have to be tied to ITestNGMethod ? There are tests for the Graph class viz., GraphTest which attempts at testing Graph behavior using Strings. If we basically tie down the Comparator to ITestNGMethod then this would cause changes to be required in the test as well and by behavior one shouldn't have to need an ITestNGMethod object to test the behavior of the Graph. That is why I didn't change it.

@krmahadevan
Copy link
Member Author

@juherr - I have addressed some of the review comments and responded to the ones that I have not fixed. Please help take a look and let me know if this can be approved.

Copy link
Member

@juherr juherr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Maybe we just can remove the system property from the test.

Ping @cbeust

<!--This test depends on System properties. So its intentionally being run at the end
because the toggling of the system property will affect other tests -->
<test name = "RunAtLast">
<classes>
<class name="test.dataprovider.issue128.DataProviderParametersMismatchTest"/>
</classes>
</test>

<test name="RunOrderingTest">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now, we may add a programmatically way to configure the test without system properties.


import java.util.Comparator;

public final class Systematiser {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a Javadoc for this class, especially since its name is so bizarre.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cbeust - I have added the required javadocs as well. Can you please see if thats fine ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have some other name in mind please let me know @cbeust I can rename this. I named this so, keeping in mind it helps organize methods in some fashion. But if the name is odd, I can have it named to something like ComparatorFactory or something on those lines

@cbeust cbeust merged commit 4c446b4 into testng-team:master Jul 15, 2017
@krmahadevan krmahadevan deleted the fix-799 branch July 16, 2017 04:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

@Factory with dataProvider changes order of iterations
3 participants