-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Compatible with CompleteFuture asynchronous programming #1323
Conversation
.github/workflows/maven.yml
Outdated
@@ -28,5 +28,4 @@ jobs: | |||
- name: Test with Maven | |||
run: ./mvnw package -Pci-test | |||
- name: Codecov | |||
uses: codecov/codecov-action@v1 |
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.
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.
woc,I heard about it for the first time
@@ -316,4 +316,4 @@ protected void setDoneTime() { | |||
public long getElapsedTime() { | |||
return doneTime - genTime; | |||
} | |||
} | |||
} |
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.
Same 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.
Do you know why unit testing is unstable? Sometimes through unit testing, occasionally with exceptions
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.
@EvenLjj We need to make our unit test stable. It is disgusting to try it again and again :( . How about add a task to solve it ?
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, some single tests require reconstruction, we will kick of.
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #1323 +/- ##
============================================
+ Coverage 72.01% 72.06% +0.04%
- Complexity 783 784 +1
============================================
Files 416 416
Lines 17659 17663 +4
Branches 2752 2752
============================================
+ Hits 12718 12729 +11
+ Misses 3538 3529 -9
- Partials 1403 1405 +2 ☔ View full report in Codecov by Sentry. |
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.
@Test
public void thenApply() throws InterruptedException {
AtomicBoolean applied = new AtomicBoolean(false);
MyFuture myFuture = new MyFuture(1000);
Consumer<? super String> consumer = (String str) -> {
System.out.println(str);
applied.compareAndSet(false, true);
};
myFuture.thenAccept(consumer);
myFuture.setSuccess("done");
Thread.sleep(1000);
Assert.assertTrue(applied.get());
}
@Test
public void thenApply_correctVersion() throws InterruptedException {
AtomicBoolean applied = new AtomicBoolean(false);
CountDownLatch countDownLatch = new CountDownLatch(1);
CompletableFuture<String> future = CompletableFuture.supplyAsync(() -> {
// 模拟耗时操作
try {
countDownLatch.await();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
return "Hello, World!";
});
Consumer<? super String> consumer = (String str) -> {
System.out.println(str);
applied.compareAndSet(false, true);
};
future.thenAccept(consumer);
countDownLatch.countDown();
Thread.sleep(1000);
Assert.assertTrue(applied.get());
}
I write two test case . The first one is aim to test AbstractResponseFuture, and the second one shows how CompletableFuture should work. Please make sure the first case can pass.
I found that future does not perform an operation, it needs to call complete method to modify the state @OrezzerO |
Yes, you are right. So there is a compatibility issues here. We need to make sure that when future task is complete, then it trigger 'then apply' task. |
I think this pr is ok. @EvenLjj Please check compatibility with internal version . |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
@EvenLjj Buddy, this pr is a bit long and will be marked as expired. Evaluate whether the merger will affect the existing code, thanks |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Motivation:
As shown in the following link, the Sofarpc part of the code is written based on an older version of jdk, which is not compatible with the usage of jdk8 CompleteFuture. In order to make the framework more compatible with asynchronous programming, I have modified the corresponding ResponseFuture content
#945 (comment)
Modification:
My idea is that ResponseFuture directly inherits CompleteFuture, as it already inherits Future and CompletionStage, and there is no need to implement classes to override these methods in the future
Result:
Fixes #.