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

Make buffer limit configurable in HeapBufferedConsumerFactory #23970

Merged
merged 5 commits into from
Apr 10, 2017

Conversation

javanna
Copy link
Member

@javanna javanna commented Apr 7, 2017

The buffer limit should have been configurable already, but the factory constructor is package private so it is truly configurable only from the org.elasticsearch.client package. Also the HttpAsyncResponseConsumerFactory interface was package private, so it could only be implemented from the org.elasticsearch.client package.

Closes #23958

The buffer limit should have been configurable already, but the factory constructor is package private so it is truly configurable only from the org.elasticsearch.client package. Also the HttpAsyncResponseConsumerFactory interface was package private, so it could only be implemented from the org.elasticsearch.client package.

Closes elastic#23958
Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

LGTM, I left a few comments that you can address at your discretion, they do not require another round from me.

* under the License.
*/

package org.elasticsearch.client.consumer.consumer;
Copy link
Member

Choose a reason for hiding this comment

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

Double consumer? It looks like only one should be necessary to escape the org.elasticsearch.client package.

Copy link
Member Author

Choose a reason for hiding this comment

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

yea I don't know what happened there :)

public class CustomHeapBufferedConsumerFactoryTests extends RestClientTestCase {

//Note that this test class should be in a different package than org.elasticsearch.client so we can test that
//the access modifiers are public rather than package private or protected
Copy link
Member

Choose a reason for hiding this comment

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

I appreciate this comment.

new HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory(bufferLimit);
HttpAsyncResponseConsumer<HttpResponse> consumer = consumerFactory.createHttpAsyncResponseConsumer();
assertThat(consumer, instanceOf(HeapBufferedAsyncResponseConsumer.class));
HeapBufferedAsyncResponseConsumer bufferedAsyncResponseConsumer = (HeapBufferedAsyncResponseConsumer) consumer;
Copy link
Member

Choose a reason for hiding this comment

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

This line probably exceeds the 100-column limit. I know that we are actively discussing what to do about that, so I'm fine with either bringing it under the limit or suppressing the file for now.

Copy link
Member

@nik9000 nik9000 left a comment

Choose a reason for hiding this comment

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

Left a suggestion, otherwise LGTM.


public class CustomHeapBufferedConsumerFactoryTests extends RestClientTestCase {

//Note that this test class should be in a different package than org.elasticsearch.client so we can test that
Copy link
Member

Choose a reason for hiding this comment

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

I'd probably assert this with reflection.

Copy link
Member

Choose a reason for hiding this comment

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

Oh, I like that suggestion! Then the custom package isn't needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea, I pushed a new commit. It addresses the constructor visibility problem. Also the interface was mistakenly package private, but that is not caught by the test with reflection in the same package. Do you guys have ideas on how to achieve that too?

Copy link
Member

@jasontedor jasontedor Apr 7, 2017

Choose a reason for hiding this comment

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

I think something like this would work:

    public void testVisibility() throws ClassNotFoundException {
        final Class<?> clazz =
                Class.forName("org.elasticsearch.client.HttpAsyncResponseConsumerFactory");
        assertThat(clazz.getModifiers() & Modifier.PUBLIC, equalTo(Modifier.PUBLIC));
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

of course! thank you

IllegalAccessException, InvocationTargetException, InstantiationException {
int bufferLimit = randomIntBetween(1, Integer.MAX_VALUE);
Class<?> aClass = Class.forName(HttpAsyncResponseConsumerFactory.HeapBufferedResponseConsumerFactory.class.getName());
Constructor<?> constructor = aClass.getConstructor(Integer.TYPE);
Copy link
Member

Choose a reason for hiding this comment

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

I'd add a comment that you are using reflection here to make sure that the ctor is public.

Copy link
Member Author

Choose a reason for hiding this comment

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

makes sense

}

public void testHttpAsyncResponseConsumerFactoryVisibility() throws ClassNotFoundException {
final Class<?> clazz = Class.forName(HttpAsyncResponseConsumerFactory.class.getName());
Copy link
Member

Choose a reason for hiding this comment

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

If we are going to load the class directly (i.e., via the class itself) there is no need to use Class.forName, you can just say final Class<?> class = HttpAsyncResponseConsumerFactory.class;.

Copy link
Member Author

Choose a reason for hiding this comment

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

yep that's silly, I will fix thanks

Copy link
Member

@jasontedor jasontedor left a comment

Choose a reason for hiding this comment

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

LGTM.

@javanna javanna merged commit b73f87b into elastic:master Apr 10, 2017
javanna added a commit that referenced this pull request Apr 10, 2017
The buffer limit should have been configurable already, but the factory constructor is package private so it is truly configurable only from the org.elasticsearch.client package. Also the HttpAsyncResponseConsumerFactory interface was package private, so it could only be implemented from the org.elasticsearch.client package.

Closes #23958
javanna added a commit that referenced this pull request Apr 10, 2017
The buffer limit should have been configurable already, but the factory constructor is package private so it is truly configurable only from the org.elasticsearch.client package. Also the HttpAsyncResponseConsumerFactory interface was package private, so it could only be implemented from the org.elasticsearch.client package.

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

Successfully merging this pull request may close these issues.

3 participants