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

NEXUS-10527 Added validation support to httpfixture. #49

Merged
merged 19 commits into from
Aug 17, 2016
Merged

Conversation

ebaersoft
Copy link
Contributor

@ebaersoft ebaersoft commented Jul 29, 2016

Jira: https://issues.sonatype.org/browse/NEXUS-10527

Bamboo: http://bamboo.s/browse/OSS-GOODIESF15-9

Added validating proxy server and validation support to goodies-httpfixture.

@@ -28,7 +28,7 @@
<artifactId>goodies</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<packaging>pom</packaging>
<version>2.1.3-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
Copy link
Contributor Author

@ebaersoft ebaersoft Jul 29, 2016

Choose a reason for hiding this comment

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

Note, updated to 2.2.0 to represent added functionality. Let me know if this version doesn't seem appropriate for some reason.

@bentmann
Copy link
Contributor

bentmann commented Aug 1, 2016

This seems to conflate two things which should really have been two PRs:

  • a real/full proxy impl using littleproxy
  • a new ValidatingBehavior

I can see the value of the real proxy but I'm currently not convinced that this ValidatingBehavior buys us anything other than overenginnering/complication: Behavior is already a simple interface with only a single method which can be easily implemented to add custom request behavior/validation. As such I strongly suspect that whatever Validator impl you build over in the NX codebase could just as well be a Behavior impl.

@ebaersoft
Copy link
Contributor Author

@bentmann The behavior implmentation was moved to NX3, see #911.

/**
* Reset the success counter to zero.
*/
public void resetSuccessCount();
Copy link
Contributor

Choose a reason for hiding this comment

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

With the recent refactoring HttpValidator implementations should be cheap to create, so there's no reason to have static instances of them. This means there's less reason to have a resetSuccessCount method, in fact it would be better to remove this just to make sure it can't be accidentally reset.

Note that other 'counting' behaviours in this codebase (BasicAuth and Fail) don't include reset methods - instead they expect each test to use a distinct instance, as that means the tests can be run in parallel.

Copy link
Contributor

@mcculls mcculls Aug 8, 2016

Choose a reason for hiding this comment

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

After thinking this over it's much cleaner to track success/failures in the validating behaviour according to the result of the validate method as suggested above, in which case both counting methods can be removed from this API.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As mentioned in the NX3 PR, moving the count/reset out one layer to the behavior or proxy server with validation.

@dbradicich
Copy link
Member

+1

@@ -20,7 +20,7 @@
<parent>
<groupId>org.sonatype.goodies</groupId>
<artifactId>goodies</artifactId>
<version>2.1.3-SNAPSHOT</version>
<version>2.2.0-SNAPSHOT</version>
Copy link
Member

Choose a reason for hiding this comment

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

has there already been a discussion of 2.1.3 VS 2.2.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No one has mentioned anything about the version. I switched everything to 2.2.0 because it seems like adding new features warrants a new minor version at least.

Copy link
Member

Choose a reason for hiding this comment

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

works for me

@kellyrob99
Copy link
Member

Needs a Bamboo build please :)


@Override
public AsyncContext startAsync(ServletRequest servletRequest, ServletResponse servletResponse)
throws IllegalStateException
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Comes from the HttpServeltRequest interface, nothing to do here.

@Override
public HttpResponse clientToProxyRequest(HttpObject httpObject) {
for (HttpValidator v : validation) {
v.validate(new NettyHttpRequestWrapper(originalRequest));
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this wrapping outside of this loop to only incur the cost once, rather than for every validation.

@mcculls mcculls changed the title NEXUS-10528 Added validation support to httpfixture. NEXUS-10527 Added validation support to httpfixture. Aug 16, 2016
private AtomicInteger successCount = new AtomicInteger();

public ValidatingBehavior(HttpValidator... validators) {
checkArgument(validators != null && validators.length > 0, "Must have at least one validator set.");
Copy link
Contributor

@mrprescott mrprescott Aug 16, 2016

Choose a reason for hiding this comment

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

Minor: ValidatingBehavior(null,null) could sneak in some nulls and NPE down on line 53.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding more robust verification of validators.

@mrprescott
Copy link
Contributor

+1

1 similar comment
@mcculls
Copy link
Contributor

mcculls commented Aug 16, 2016

+1

@ebaersoft
Copy link
Contributor Author

That last commit msg is incorrect, i fixed the "withPort" method so it takes effect.

@kellyrob99
Copy link
Member

+1

@ebaersoft ebaersoft merged commit 39f3d25 into master Aug 17, 2016
@bentmann bentmann deleted the NEXUS-10528 branch October 25, 2016 15:39
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.

8 participants