-
Notifications
You must be signed in to change notification settings - Fork 479
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
fix sending mutiple queries with single query bug #236
Conversation
Current coverage is 72.30% (diff: 63.63%)@@ master #236 diff @@
==========================================
Files 11 11
Lines 633 639 +6
Methods 0 0
Messages 0 0
Branches 75 75
==========================================
+ Hits 458 462 +4
- Misses 142 144 +2
Partials 33 33
|
I already had the same idea, thanks, would you please show the behavior in a unit-test then i will merge. |
@Test
public void testPostQuery() {
String dbName = "unittest_" + System.currentTimeMillis();
this.influxDB.createDatabase(dbName);
QueryResult result = this.influxDB.query(new Query("SELECT * FROM not_exists;SELECT * FROM not_exists", dbName, true));
Assert.assertEquals(2, result.getResults().size());
this.influxDB.deleteDatabase(dbName);
} this will fail if use |
Yes of course, but include some tests, one for failing and one for working which shows how your code modifications make it work. A note on the README.md regarding multiple Queries in one request would also be helpful. |
@Test
public void testPostQuery() {
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.readTimeout(1, TimeUnit.MINUTES);
builder.connectTimeout(1, TimeUnit.MINUTES);
builder.writeTimeout(1, TimeUnit.MINUTES);
this.influxDB = InfluxDBFactory.connect("http://" + TestUtils.getInfluxIP() + ":" + TestUtils.getInfluxPORT(true), "admin", "admin", builder);
String dbName = "unittest_" + System.currentTimeMillis();
this.influxDB.createDatabase(dbName);
String query = "SELECT * FROM not_exists";
StringBuilder sb = new StringBuilder();
for (int i = 0; i < 1 << 18; i++) {
sb.append(query).append(";");
}
sb.deleteCharAt(sb.length() - 1);
this.influxDB.query(new Query(sb.toString(), dbName, true));
this.influxDB.deleteDatabase(dbName);
} this test case should throw exception if use |
@shanexu can you please rebase and resolve the merge conflict ? |
@shanexu You should rebase, or clone again. The way you did it now does not show what you changed. Please try again |
Now, using @Test
public void testWriteEnableGzip() { this unit test case fail. influxdb does not handle a query request with |
@majst01 is it OK now? |
@shanexu you can squash your commit into one commit to make PR's commit clean: |
@jiafu1115 what do you think, i am fine with this PR |
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.
@shanexu @majst01 are you sure of this:
influxdb does not handle a query request with Content-Encoding: gzip and Content-Type: application/x-www-form-urlencoded, so we should skip compressing for query request.
are you sure that it is influxdb's issue? if so you can skip it after all that gzip's focus is on write.
I provide some tiny suggestions on unit tests. Thanks. You can go ahead!
this.influxDB.createDatabase(dbName); | ||
QueryResult result = this.influxDB.query(new Query("SELECT * FROM not_exists;SELECT * FROM not_exists", dbName, false)); | ||
Assert.assertEquals(2, result.getResults().size()); | ||
this.influxDB.deleteDatabase(dbName); |
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.
try...finally to make use tmp database to be removed
} | ||
|
||
@Test | ||
public void testPostQuery() { |
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 java doc or change test's method's name to show what's your test focus?
this.influxDB.createDatabase(dbName); | ||
QueryResult result = this.influxDB.query(new Query("SELECT * FROM not_exists;SELECT * FROM not_exists", dbName)); | ||
Assert.assertEquals(2, result.getResults().size()); | ||
this.influxDB.deleteDatabase(dbName); |
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.
should using try...finally to delete tmp db
public void testPostQuery() { | ||
String dbName = "unittest_" + System.currentTimeMillis(); | ||
try { | ||
this.influxDB.createDatabase(dbName); |
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.
move to 123 from 125.
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 don't think it's necessary. Droping a non-existent database will not cause any problem.
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 is one of best practices instead of if it is necessary for this case. So it is up to you. just one advice for best practice.
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.
why need this (I notice the encoded=true in all query methods)? if need it, why loss it in write method on 333 line?
@@ -318,8 +319,9 @@ public QueryResult query(final Query query) { | |||
call = this.influxDBService.postQuery(this.username, | |||
this.password, query.getDatabase(), query.getCommand()); | |||
} else { | |||
String encodedCommand = UrlEscapers.urlFormParameterEscaper().escape(query.getCommand()); |
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.
why need this (I notice the encoded=true in all query methods)? if need it, why loss it in write method on 333 line?
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.
okhttp-3.4.2 use different policies on encoding query parameter and form field.
For query parameter
HttpUrl.java#L1120
/** Encodes the query parameter using UTF-8 and adds it to this URL's query string. */
public Builder addQueryParameter(String name, String value) {
if (name == null) throw new NullPointerException("name == null");
if (encodedQueryNamesAndValues == null) encodedQueryNamesAndValues = new ArrayList<>();
encodedQueryNamesAndValues.add(
canonicalize(name, QUERY_COMPONENT_ENCODE_SET, false, false, true, true));
encodedQueryNamesAndValues.add(value != null
? canonicalize(value, QUERY_COMPONENT_ENCODE_SET, false, false, true, true)
: null);
return this;
}
it does not encode some characters, for example ;
, but influxdb need ;
encode into %3B
.
For form field
FormBody.java#L110
public Builder add(String name, String value) {
names.add(HttpUrl.canonicalize(name, FORM_ENCODE_SET, false, false, true, true));
values.add(HttpUrl.canonicalize(value, FORM_ENCODE_SET, false, false, true, true));
return this;
}
it does encode ;
and some other characters.
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.
So why loss encode in line 333? It is query 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.
my fault, I see, i missed this one. i will fix 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.
SHOW+DATABASES
? looks strange.....
@@ -362,7 +362,7 @@ public void deleteDatabase(final String name) { | |||
@Override | |||
public List<String> describeDatabases() { | |||
QueryResult result = execute(this.influxDBService.query(this.username, | |||
this.password, "SHOW DATABASES")); | |||
this.password, "SHOW+DATABASES")); |
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.
SHOW+DATABASES? looks strange.....
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.
a space can be encoded into +
or %20
@shanexu I have one idea that if we can move url encode into new method called query.getCommandWithEncoded()? Then we may limit the code change lines and not change every where. For known command, we can does't encode it such as "create database" WDYT? |
@shanexu do you have qq? we can talk offline. |
LGTM now. you missed the test cases so that coverage decreased |
I`m going to merge this now, thanks for all of you for digging into that issue. |
should use
@Filed
and@FormUrlEncoded
, or the arguments will encoded as query string append to request URL.