-
Notifications
You must be signed in to change notification settings - Fork 24.6k
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
Make buffer limit configurable in HeapBufferedConsumerFactory #23970
Conversation
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
There was a problem hiding this 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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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));
}
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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;
.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
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 #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 #23958