-
Notifications
You must be signed in to change notification settings - Fork 94
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
feat(client): replace jersey with okhttp in hugegraph-client (Draft PR) #508
Conversation
thanks and some todos:
|
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.
Overall looks good, but we need fix ci first and improve codestyle refer to https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-style.xml
hugegraph-client/src/main/java/org/apache/hugegraph/rest/BasicAuthInterceptor.java
Outdated
Show resolved
Hide resolved
hugegraph-client/src/main/java/org/apache/hugegraph/rest/OkhttpConfig.java
Outdated
Show resolved
Hide resolved
hugegraph-client/src/main/java/org/apache/hugegraph/rest/TokenInterceptor.java
Outdated
Show resolved
Hide resolved
hugegraph-client/src/test/java/org/apache/hugegraph/BaseClientTest.java
Outdated
Show resolved
Hide resolved
I've done my best to fix the issues mentioned on,but there is one more problem. When I add the licence header in the file "hugegraph-client/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker",the unit test will run error. |
Codecov Report
@@ Coverage Diff @@
## master #508 +/- ##
============================================
+ Coverage 62.42% 62.60% +0.18%
- Complexity 895 1937 +1042
============================================
Files 91 265 +174
Lines 4404 9689 +5285
Branches 519 900 +381
============================================
+ Hits 2749 6066 +3317
- Misses 1450 3228 +1778
- Partials 205 395 +190
... and 119 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
if u point this, exclude it in plugin settings if we really don't need or can't add license header in it (also check |
@@ -0,0 +1 @@ | |||
mock-maker-inline |
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.
maybe we could try to add license header for it first if (it's) necessary
mock-maker-inline | |
# license header with `#` comment | |
# .... | |
# end license | |
mock-maker-inline |
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.
maybe we could try to add license header for it first if (it's) necessary
This just works fine, thank you.
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.
Thanks for your contribution
return UriComponent.encode(raw, Type.QUERY_PARAM_SPACE_ENCODED); | ||
} | ||
// public static String encode(String raw) { | ||
// return UriComponent.encode(raw, Type.QUERY_PARAM_SPACE_ENCODED); |
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.
any alternative plan?
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.
any alternative plan?
看原来代码的意图,是要对url中的参数进行编码。但是okhttp中使用HttpUrl.Builder构建url,其实会自动进行编码的,所以感觉没必要由使用方对参数编码后再传参
@@ -55,7 +56,7 @@ | |||
|
|||
public class RestResultTest extends BaseUnitTest { | |||
|
|||
private jakarta.ws.rs.core.Response mockResponse; | |||
private okhttp3.Response mockResponse; |
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.
just import the Response 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.
这里之前用的jakartar包中的Response,现在实现改为okhttp,因此对应mock的对象也修改为okhttp包中的Response。这样做是存在什么问题?
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.
ok, I mean we can try to import okhttp3.Response
整体方案没问题的。
|
有点奇怪,我fork到自己仓库,执行是成功的,没有遇到超时的问题。两边执行是有什么区别吗? |
I've test with springboot2.X and springboot3,but just simple test. |
hugegraph-client/pom.xml
Outdated
@@ -37,28 +37,73 @@ | |||
</description> | |||
|
|||
<properties> | |||
<lombok.version>1.18.8</lombok.version> | |||
<okhttp.version>4.10.0</okhttp.version> |
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.
shoule extract dependency version to root pom.xml, sub module just import?
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.
shoule extract dependency version to root pom.xml, sub module just import?
seems no need, only extract dependencies that multiple modules need to use (leave single usage alone?)
LGTM, @zhenyuT please resolve conflicts when you are free. |
return result.readObject(User.class); | ||
} | ||
|
||
public UserRole getUserRole(Object id) { | ||
String idEncoded = RestClient.encode(formatEntityId(id)); | ||
// String idEncoded = RestClient.encode(formatEntityId(id)); |
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.
can we remove the unused code
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
headers.putSingle("Content-Encoding", BATCH_ENCODING); | ||
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
// headers.putSingle("Content-Encoding", BATCH_ENCODING); |
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.
ditto
headers.putSingle("Content-Encoding", BATCH_ENCODING); | ||
RestResult result = this.client.put(this.batchPath(), null, | ||
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
// headers.putSingle("Content-Encoding", BATCH_ENCODING); |
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.
ditto
RestResult result = this.client.put(this.batchPath(), null, | ||
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
// headers.putSingle("Content-Encoding", BATCH_ENCODING); | ||
Headers headers = new Headers.Builder().add("Content-Encoding", BATCH_ENCODING).build(); |
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.
define a const?
MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
headers.putSingle("Content-Encoding", BATCH_ENCODING); | ||
// MultivaluedHashMap<String, Object> headers = new MultivaluedHashMap<>(); | ||
// headers.putSingle("Content-Encoding", BATCH_ENCODING); |
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.
ditto
@Builder | ||
@Getter | ||
@Setter | ||
public class OkhttpConfig { |
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.
expect a blank line after the class define
|
||
import java.util.Map; | ||
|
||
public interface OkhttpRestClient { |
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.
don't need to Okhttp prefix, we expect to keep the same interface name
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OkhttpRestResult { |
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.
don't need to Okhttp prefix
@@ -55,7 +56,7 @@ | |||
|
|||
public class RestResultTest extends BaseUnitTest { | |||
|
|||
private jakarta.ws.rs.core.Response mockResponse; | |||
private okhttp3.Response mockResponse; |
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.
ok, I mean we can try to import okhttp3.Response
pom.xml
Outdated
<!-- <version>${jersey.version}</version>--> | ||
<!-- <type>pom</type>--> | ||
<!-- <scope>import</scope>--> | ||
<!-- </dependency>--> |
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.
we can remove all the unused code
implemented by apache/incubator-hugegraph-commons#133 |
Due to the lack of activity, the current pr is marked as stale and will be closed after 180 days, any update will remove the stale label |
1、直接修改hugegraph-client代码,覆盖common中的类
2、对于https自定义证书的实现暂时缺失
3、运行ci失败,且耗时较久(30min),部分单测执行出现connection timeout的异常。推测可能okhttp client的close存在问题,多次创建client实例导致内存/连接泄漏,导致存在性能问题
麻烦先看下代码,如果大体方向没问题的话,我再继续进行代码优化 (以及调整 hugegrpah-common 中的依赖, 目前是直接在 client 调整)