-
Notifications
You must be signed in to change notification settings - Fork 26.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enhancement] Improve code coverage and fix some code (#6197)
- Loading branch information
Showing
26 changed files
with
1,057 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
dubbo-common/src/test/java/org/apache/dubbo/common/BaseServiceMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.common; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class BaseServiceMetadataTest { | ||
|
||
@Test | ||
public void test() { | ||
BaseServiceMetadata baseServiceMetadata = new BaseServiceMetadata(); | ||
baseServiceMetadata.setGroup("group1"); | ||
baseServiceMetadata.setServiceInterfaceName("org.apache.dubbo.common.TestInterface"); | ||
baseServiceMetadata.setVersion("1.0.0"); | ||
baseServiceMetadata.setServiceKey(BaseServiceMetadata.buildServiceKey("org.apache.dubbo.common.TestInterface", "group1", "1.0.0")); | ||
|
||
assertEquals(baseServiceMetadata.getGroup(), "group1"); | ||
assertEquals(baseServiceMetadata.getServiceInterfaceName(), "org.apache.dubbo.common.TestInterface"); | ||
assertEquals(baseServiceMetadata.getVersion(), "1.0.0"); | ||
assertEquals(baseServiceMetadata.getServiceKey(), "group1/org.apache.dubbo.common.TestInterface:1.0.0"); | ||
assertEquals(baseServiceMetadata.getDisplayServiceKey(), "org.apache.dubbo.common.TestInterface:1.0.0"); | ||
|
||
baseServiceMetadata.setServiceKey(BaseServiceMetadata.buildServiceKey("org.apache.dubbo.common.TestInterface", null, null)); | ||
assertEquals(baseServiceMetadata.getServiceKey(), "org.apache.dubbo.common.TestInterface"); | ||
baseServiceMetadata.setServiceKey(BaseServiceMetadata.buildServiceKey("org.apache.dubbo.common.TestInterface", "", "")); | ||
assertEquals(baseServiceMetadata.getServiceKey(), "org.apache.dubbo.common.TestInterface"); | ||
|
||
|
||
baseServiceMetadata.setVersion("2.0.0"); | ||
baseServiceMetadata.generateServiceKey(); | ||
assertEquals(baseServiceMetadata.getServiceKey(), "group1/org.apache.dubbo.common.TestInterface:2.0.0"); | ||
|
||
assertEquals(BaseServiceMetadata.versionFromServiceKey("group1/org.apache.dubbo.common.TestInterface:1.0.0"), "1.0.0"); | ||
assertEquals(BaseServiceMetadata.groupFromServiceKey("group1/org.apache.dubbo.common.TestInterface:1.0.0"), "group1"); | ||
assertEquals(BaseServiceMetadata.interfaceFromServiceKey("group1/org.apache.dubbo.common.TestInterface:1.0.0"), "org.apache.dubbo.common.TestInterface"); | ||
|
||
assertNull(BaseServiceMetadata.versionFromServiceKey("")); | ||
assertNull(BaseServiceMetadata.groupFromServiceKey("")); | ||
assertEquals(BaseServiceMetadata.interfaceFromServiceKey(""), ""); | ||
|
||
assertEquals(BaseServiceMetadata.revertDisplayServiceKey("org.apache.dubbo.common.TestInterface:1.0.0").getDisplayServiceKey(), | ||
"org.apache.dubbo.common.TestInterface:1.0.0"); | ||
assertEquals(BaseServiceMetadata.revertDisplayServiceKey("org.apache.dubbo.common.TestInterface").getDisplayServiceKey(), | ||
"org.apache.dubbo.common.TestInterface:null"); | ||
assertEquals(BaseServiceMetadata.revertDisplayServiceKey(null).getDisplayServiceKey(),"null:null"); | ||
assertEquals(BaseServiceMetadata.revertDisplayServiceKey("org.apache.dubbo.common.TestInterface:1.0.0:1").getDisplayServiceKey(),"null:null"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
dubbo-common/src/test/java/org/apache/dubbo/common/threadpool/ThreadlessExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.common.threadpool; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.extension.ExtensionLoader; | ||
import org.apache.dubbo.common.threadpool.manager.ExecutorRepository; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.CompletableFuture; | ||
import java.util.concurrent.ExecutorService; | ||
|
||
public class ThreadlessExecutorTest { | ||
private static ThreadlessExecutor executor; | ||
|
||
static { | ||
URL url = URL.valueOf("dubbo://127.0.0.1:12345"); | ||
ExecutorService sharedExecutor = | ||
ExtensionLoader.getExtensionLoader(ExecutorRepository.class) | ||
.getDefaultExtension().createExecutorIfAbsent(url); | ||
executor = new ThreadlessExecutor(sharedExecutor); | ||
} | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
for (int i = 0; i < 10; i++) { | ||
executor.execute(()->{throw new RuntimeException("test");}); | ||
} | ||
|
||
CompletableFuture<Object> stubFuture = new CompletableFuture<>(); | ||
executor.setWaitingFuture(stubFuture); | ||
Assertions.assertEquals(executor.getWaitingFuture(),stubFuture); | ||
|
||
executor.waitAndDrain(); | ||
|
||
executor.execute(()->{}); | ||
|
||
executor.waitAndDrain(); | ||
|
||
executor.shutdown(); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
...mmon/src/test/java/org/apache/dubbo/common/threadpool/manager/ExecutorRepositoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.dubbo.common.threadpool.manager; | ||
|
||
import org.apache.dubbo.common.URL; | ||
import org.apache.dubbo.common.extension.ExtensionLoader; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.ThreadPoolExecutor; | ||
|
||
public class ExecutorRepositoryTest { | ||
private ExecutorRepository executorRepository = ExtensionLoader.getExtensionLoader(ExecutorRepository.class).getDefaultExtension(); | ||
|
||
@Test | ||
public void testGetExecutor() { | ||
testGet(URL.valueOf("dubbo://127.0.0.1:23456")); | ||
testGet(URL.valueOf("dubbo://127.0.0.1:23456?side=consumer")); | ||
|
||
Assertions.assertNotNull(executorRepository.getSharedExecutor()); | ||
Assertions.assertNotNull(executorRepository.getServiceExporterExecutor()); | ||
executorRepository.nextScheduledExecutor(); | ||
} | ||
|
||
private void testGet(URL url) { | ||
Assertions.assertNull(executorRepository.getExecutor(url)); | ||
|
||
ExecutorService executorService = executorRepository.createExecutorIfAbsent(url); | ||
executorService.shutdown(); | ||
executorService = executorRepository.createExecutorIfAbsent(url); | ||
Assertions.assertFalse(executorService.isShutdown()); | ||
|
||
Assertions.assertEquals(executorService, executorRepository.getExecutor(url)); | ||
executorService.shutdown(); | ||
Assertions.assertNotEquals(executorService, executorRepository.getExecutor(url)); | ||
} | ||
|
||
@Test | ||
public void testUpdateExecutor() { | ||
URL url = URL.valueOf("dubbo://127.0.0.1:23456?threads=5"); | ||
ThreadPoolExecutor executorService = (ThreadPoolExecutor) executorRepository.createExecutorIfAbsent(url); | ||
|
||
executorService.setCorePoolSize(3); | ||
executorRepository.updateThreadpool(url, executorService); | ||
|
||
executorService.setCorePoolSize(3); | ||
executorService.setMaximumPoolSize(3); | ||
executorRepository.updateThreadpool(url, executorService); | ||
|
||
executorService.setMaximumPoolSize(20); | ||
executorService.setCorePoolSize(10); | ||
executorRepository.updateThreadpool(url, executorService); | ||
|
||
executorService.setCorePoolSize(10); | ||
executorService.setMaximumPoolSize(10); | ||
executorRepository.updateThreadpool(url, executorService); | ||
|
||
executorService.setCorePoolSize(5); | ||
executorRepository.updateThreadpool(url, executorService); | ||
|
||
|
||
} | ||
} |
Oops, something went wrong.