forked from apache/shenyu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[type:test] Improve the unit test coverage. (apache#3831)
* [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-web. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer. * [type:test] Improve the unit test coverage of shenyu-loadbalancer.
- Loading branch information
Showing
23 changed files
with
779 additions
and
55 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
82 changes: 82 additions & 0 deletions
82
...balancer/src/test/java/org/apache/shenyu/loadbalancer/cache/UpstreamCacheManagerTest.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,82 @@ | ||
/* | ||
* 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.shenyu.loadbalancer.cache; | ||
|
||
import org.apache.shenyu.common.config.ShenyuConfig; | ||
import org.apache.shenyu.common.utils.Singleton; | ||
import org.apache.shenyu.loadbalancer.entity.Upstream; | ||
import org.junit.jupiter.api.TestMethodOrder; | ||
import org.junit.jupiter.api.MethodOrderer; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.Order; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
|
||
/** | ||
* The type UpstreamCacheManager check task test. | ||
*/ | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
public class UpstreamCacheManagerTest { | ||
|
||
private static final String SELECTOR_ID = "SELECTOR_ID"; | ||
|
||
@Test | ||
@Order(1) | ||
public void initUpstreamCacheManagerTest() throws InterruptedException { | ||
final ShenyuConfig shenyuConfig = new ShenyuConfig(); | ||
shenyuConfig.getUpstreamCheck().setEnabled(true); | ||
shenyuConfig.getUpstreamCheck().setPrintEnabled(true); | ||
shenyuConfig.getUpstreamCheck().setPrintInterval(1); | ||
Singleton.INST.single(ShenyuConfig.class, shenyuConfig); | ||
Assertions.assertNotNull(UpstreamCacheManager.getInstance()); | ||
Thread.sleep(3); | ||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void submitTest() { | ||
final UpstreamCacheManager upstreamCacheManager = UpstreamCacheManager.getInstance(); | ||
List<Upstream> upstreamList = new ArrayList<>(2); | ||
upstreamCacheManager.submit(SELECTOR_ID, upstreamList); | ||
upstreamList.add(Upstream.builder().url("url").status(true).build()); | ||
upstreamList.add(Upstream.builder().status(true).build()); | ||
upstreamCacheManager.submit(SELECTOR_ID, upstreamList); | ||
// hit `existUpstream.stream().filter` | ||
upstreamList.clear(); | ||
upstreamList.add(Upstream.builder().url("url2").status(true).build()); | ||
upstreamList.add(Upstream.builder().url("url").status(true).build()); | ||
upstreamCacheManager.submit(SELECTOR_ID, upstreamList); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void removeByKeyTest() { | ||
final UpstreamCacheManager upstreamCacheManager = UpstreamCacheManager.getInstance(); | ||
upstreamCacheManager.removeByKey(SELECTOR_ID); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
public void findUpstreamListBySelectorIdTest() { | ||
final UpstreamCacheManager upstreamCacheManager = UpstreamCacheManager.getInstance(); | ||
Assertions.assertNull(upstreamCacheManager.findUpstreamListBySelectorId(SELECTOR_ID)); | ||
} | ||
} |
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
49 changes: 49 additions & 0 deletions
49
...lancer/src/test/java/org/apache/shenyu/loadbalancer/cache/UpstreamWithSelectorIdTest.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,49 @@ | ||
/* | ||
* 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.shenyu.loadbalancer.cache; | ||
|
||
import org.apache.shenyu.loadbalancer.entity.Upstream; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* The type UpstreamWithSelectorId check task test. | ||
*/ | ||
public class UpstreamWithSelectorIdTest { | ||
|
||
private static final String SELECTOR_ID = "selectorId"; | ||
|
||
@Test | ||
public void initUpstreamCacheManagerTest() { | ||
final UpstreamWithSelectorId upstream = new UpstreamWithSelectorId(SELECTOR_ID, null); | ||
Assertions.assertEquals(upstream, upstream); | ||
final UpstreamWithSelectorId upstream2 = new UpstreamWithSelectorId(SELECTOR_ID, null); | ||
Assertions.assertEquals(upstream, upstream2); | ||
upstream.setUpstream(null); | ||
upstream.setSelectorId(null); | ||
Assertions.assertTrue(upstream.hashCode() >= 0); | ||
Assertions.assertNotNull(upstream.toString()); | ||
Assertions.assertNotEquals(upstream, upstream2); | ||
Assertions.assertNotEquals(upstream, null); | ||
Assertions.assertNotEquals(upstream, SELECTOR_ID); | ||
final UpstreamWithSelectorId upstream3 = new UpstreamWithSelectorId(SELECTOR_ID, Upstream.builder().build()); | ||
Assertions.assertNotEquals(upstream, upstream3); | ||
final UpstreamWithSelectorId upstream4 = new UpstreamWithSelectorId(null, Upstream.builder().build()); | ||
Assertions.assertNotEquals(upstream, upstream4); | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
shenyu-loadbalancer/src/test/java/org/apache/shenyu/loadbalancer/entity/UpstreamTest.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.shenyu.loadbalancer.entity; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
/** | ||
* The type Upstream check task test. | ||
*/ | ||
public class UpstreamTest { | ||
|
||
@Test | ||
public void upstreamTest() { | ||
Upstream upstream = Upstream.builder() | ||
.group("group") | ||
.url("url") | ||
.timestamp(1) | ||
.warmup(1) | ||
.version("version") | ||
.weight(1) | ||
.status(true) | ||
.build(); | ||
upstream.setGroup("group"); | ||
upstream.setHealthy(true); | ||
upstream.setUrl("url"); | ||
upstream.setLastHealthTimestamp(1L); | ||
upstream.setStatus(true); | ||
upstream.setLastUnhealthyTimestamp(1L); | ||
upstream.setVersion("version"); | ||
Assertions.assertEquals(upstream.buildDomain(), "http://url"); | ||
Assertions.assertEquals(upstream.getGroup(), "group"); | ||
Assertions.assertNull(upstream.getProtocol()); | ||
Assertions.assertEquals(upstream.getLastHealthTimestamp(), 1L); | ||
Assertions.assertEquals(upstream.getLastUnhealthyTimestamp(), 1L); | ||
Assertions.assertEquals(upstream.getUrl(), "url"); | ||
Assertions.assertEquals(upstream.getWarmup(), 1); | ||
Assertions.assertEquals(upstream.getWeight(), 1); | ||
Assertions.assertEquals(upstream.getVersion(), "version"); | ||
Assertions.assertEquals(upstream.getTimestamp(), 1); | ||
Assertions.assertTrue(upstream.isHealthy()); | ||
Assertions.assertTrue(upstream.isStatus()); | ||
Upstream upstream2 = Upstream.builder() | ||
.protocol("https://") | ||
.url("url") | ||
.weight(1) | ||
.status(true) | ||
.build(); | ||
Assertions.assertEquals(upstream2.buildDomain(), "https://url"); | ||
Assertions.assertNotEquals(upstream, upstream2); | ||
Assertions.assertNotEquals(upstream, null); | ||
Assertions.assertNotEquals(upstream, ""); | ||
Assertions.assertEquals(upstream, upstream); | ||
Upstream upstream3 = Upstream.builder() | ||
.protocol("https://") | ||
.url("url") | ||
.weight(1) | ||
.status(true) | ||
.build(); | ||
Assertions.assertEquals(upstream2, upstream3); | ||
Assertions.assertNotNull(upstream2.toString()); | ||
Assertions.assertTrue(upstream2.hashCode() >= 0); | ||
} | ||
} |
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
Oops, something went wrong.