Skip to content

Commit 04ffae0

Browse files
htynknbeiwei30
authored andcommitted
fix * imports issue (#1721)
1 parent db039c6 commit 04ffae0

16 files changed

+1093
-70
lines changed

.codecov.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ coverage:
55
default:
66
threshold: 0.1%
77
ignore:
8-
- "dubbo-demo/.*"
8+
- "dubbo-demo/.*"
9+
- "dubbo-common/src/main/java/com/alibaba/dubbo/common/json/*.java" # internal JSON impl is deprecate, ignore test coverage for them
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.common.concurrent;
18+
19+
import org.junit.Before;
20+
import org.junit.Test;
21+
22+
import java.util.concurrent.CountDownLatch;
23+
import java.util.concurrent.Executor;
24+
25+
import static org.mockito.ArgumentMatchers.any;
26+
import static org.mockito.Mockito.doThrow;
27+
import static org.mockito.Mockito.mock;
28+
import static org.mockito.Mockito.times;
29+
import static org.mockito.Mockito.verify;
30+
31+
public class ExecutionListTest {
32+
private ExecutionList executionList;
33+
34+
@Before
35+
public void setUp() throws Exception {
36+
this.executionList = new ExecutionList();
37+
}
38+
39+
@Test(expected = NullPointerException.class)
40+
public void testAddNullRunnable() {
41+
this.executionList.add(null, mock(Executor.class));
42+
}
43+
44+
@Test
45+
public void testAddRunnableToExecutor() {
46+
Executor mockedExecutor = mock(Executor.class);
47+
48+
this.executionList.add(mock(Runnable.class), mockedExecutor);
49+
this.executionList.execute();
50+
51+
verify(mockedExecutor).execute(any(Runnable.class));
52+
}
53+
54+
@Test
55+
public void testExecuteRunnableWithDefaultExecutor() throws InterruptedException {
56+
final CountDownLatch countDownLatch = new CountDownLatch(1);
57+
this.executionList.add(new Runnable() {
58+
@Override
59+
public void run() {
60+
countDownLatch.countDown();
61+
}
62+
}, null);
63+
64+
this.executionList.execute();
65+
countDownLatch.await();
66+
}
67+
68+
@Test
69+
public void testExceptionForExecutor() {
70+
Executor mockedExecutor = mock(Executor.class);
71+
doThrow(new RuntimeException()).when(mockedExecutor).execute(any(Runnable.class));
72+
73+
this.executionList.add(mock(Runnable.class), mockedExecutor);
74+
this.executionList.execute();
75+
}
76+
77+
@Test
78+
public void testNotRunSameRunnableTwice() {
79+
Executor mockedExecutor = mock(Executor.class);
80+
81+
this.executionList.add(mock(Runnable.class), mockedExecutor);
82+
83+
this.executionList.execute();
84+
this.executionList.execute();
85+
86+
verify(mockedExecutor).execute(any(Runnable.class));
87+
}
88+
89+
@Test
90+
public void testRunImmediatelyAfterExecuted() {
91+
Executor mockedExecutor = mock(Executor.class);
92+
93+
this.executionList.add(mock(Runnable.class), mockedExecutor);
94+
this.executionList.execute();
95+
this.executionList.add(mock(Runnable.class), mockedExecutor);
96+
97+
verify(mockedExecutor, times(2)).execute(any(Runnable.class));
98+
}
99+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package com.alibaba.dubbo.common.concurrent;
18+
19+
import org.junit.Test;
20+
21+
import java.util.concurrent.Callable;
22+
import java.util.concurrent.CountDownLatch;
23+
import java.util.concurrent.ExecutionException;
24+
import java.util.concurrent.Executor;
25+
26+
import static org.hamcrest.CoreMatchers.is;
27+
import static org.junit.Assert.assertThat;
28+
import static org.mockito.ArgumentMatchers.any;
29+
import static org.mockito.Mockito.mock;
30+
import static org.mockito.Mockito.verify;
31+
32+
public class ListenableFutureTaskTest {
33+
@Test
34+
public void testCreate() throws InterruptedException {
35+
final CountDownLatch countDownLatch = new CountDownLatch(1);
36+
ListenableFutureTask<Boolean> futureTask = ListenableFutureTask.create(new Callable<Boolean>() {
37+
@Override
38+
public Boolean call() throws Exception {
39+
countDownLatch.countDown();
40+
return true;
41+
}
42+
});
43+
futureTask.run();
44+
countDownLatch.await();
45+
}
46+
47+
@Test
48+
public void testRunnableResponse() throws ExecutionException, InterruptedException {
49+
ListenableFutureTask<Boolean> futureTask = ListenableFutureTask.create(new Runnable() {
50+
@Override
51+
public void run() {
52+
try {
53+
Thread.sleep(500);
54+
} catch (InterruptedException e) {
55+
e.printStackTrace();
56+
}
57+
}
58+
}, true);
59+
futureTask.run();
60+
61+
Boolean result = futureTask.get();
62+
assertThat(result, is(true));
63+
}
64+
65+
@Test
66+
public void testListener() throws InterruptedException {
67+
ListenableFutureTask<String> futureTask = ListenableFutureTask.create(new Callable<String>() {
68+
@Override
69+
public String call() throws Exception {
70+
Thread.sleep(500);
71+
return "hello";
72+
}
73+
});
74+
final CountDownLatch countDownLatch = new CountDownLatch(1);
75+
futureTask.addListener(new Runnable() {
76+
@Override
77+
public void run() {
78+
countDownLatch.countDown();
79+
}
80+
});
81+
futureTask.run();
82+
countDownLatch.await();
83+
}
84+
85+
86+
@Test
87+
public void testCustomExecutor() {
88+
Executor mockedExecutor = mock(Executor.class);
89+
ListenableFutureTask<Integer> futureTask = ListenableFutureTask.create(new Callable<Integer>() {
90+
@Override
91+
public Integer call() throws Exception {
92+
return 0;
93+
}
94+
});
95+
futureTask.addListener(mock(Runnable.class), mockedExecutor);
96+
futureTask.run();
97+
98+
verify(mockedExecutor).execute(any(Runnable.class));
99+
}
100+
}

0 commit comments

Comments
 (0)