-
Notifications
You must be signed in to change notification settings - Fork 2k
Adding pagination utility #527
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
Adding pagination utility #527
Conversation
private Integer limit; | ||
private String _continue; | ||
|
||
public PagerParams() {} |
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.
delete
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build(); | ||
} | ||
|
||
@Test |
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.
Let's add/expand the tests so that they actually cover the pagination.
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.
+1. add let's add test when the list receives a 400
due to invalid limit
or continue
, maybe expecting a checked exception here?
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.
added 2 more tests for failure cases.
/** | ||
* Pagination in kubernetes list call depends on continue and limit variable | ||
* | ||
* @param listFunc |
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.
Either document the parameters, or delete these. (and below)
@@ -0,0 +1,107 @@ | |||
package io.kubernetes.client.pager; |
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.
Add copyright boilerplate here.
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.
added.
@@ -0,0 +1,30 @@ | |||
package io.kubernetes.client.util; |
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.
Add boilerplate here.
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.
added
@@ -0,0 +1,30 @@ | |||
package io.kubernetes.client.util; |
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.
It's weird that this is in a different package than Pager
. move to pager
? or util.pager
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.
moved to pager package.
|
||
public class PagerParams { | ||
|
||
private Integer limit; |
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.
nit, I prefer int
to Integer
but I don't feel strongly.
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'm fine w/ either. a zero int
and a null Integer
actually works the same.
public class PagerParams { | ||
|
||
private Integer limit; | ||
private String _continue; |
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.
nit: remove underscore.
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.
isn't continue
a reserved key word?
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 point, but perhaps continueToken
? underscore is pretty unusual in Java variable names...
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.
changed to continueToken.
return _continue; | ||
} | ||
|
||
public void setContinue(String _continue) { |
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.
remove underscore.
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.
continueToken as above?
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.
changed to continueToken.
This is great! Some small-ish comments. |
public class PagerParams { | ||
|
||
private Integer limit; | ||
private String _continue; |
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.
isn't continue
a reserved key word?
import java.lang.reflect.Type; | ||
import java.util.function.Function; | ||
|
||
public class Pager { |
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 don't want to make the pager shared by multiple resource types, better make it type parameterized.
public class Pager { | |
public class Pager<ApiType, ApiListType> { |
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.
added
* | ||
* @return Object | ||
*/ | ||
public <T> T next() { |
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.
nit: s/<ApiType>/<T>/g
client = new ClientBuilder().setBasePath("http://localhost:" + PORT).build(); | ||
} | ||
|
||
@Test |
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.
+1. add let's add test when the list receives a 400
due to invalid limit
or continue
, maybe expecting a checked exception here?
public static void main(String[] args) throws IOException { | ||
|
||
ApiClient client = Config.defaultClient(); | ||
client.getHttpClient().setReadTimeout(60, TimeUnit.SECONDS); |
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.
(might be an unrelated question) what's the point of this?
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 just prevents timeouts for large bodies/slow connections. I think the default is 10 seconds?
It could be that this is cargo-cult copied from other examples :)
|
||
public class PagerParams { | ||
|
||
private Integer limit; |
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'm fine w/ either. a zero int
and a null Integer
actually works the same.
return limit; | ||
} | ||
|
||
public void setLimit(Integer limit) { |
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.
how about making the limit
an immutable value here? (which is, settable by constructor but didn't have setter/getter). otherwise, what's the use-case of changing page size dynamically?
This is good enough for now, I'd still like to see a little more coverage in the unit tests, but we can defer to an additional PR. /lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: brendandburns, kondapally1989 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
@yue9944882 @adohe @kondapally1989 Let's move this into the |
pagination tool #523
@brendandburns @yue9944882