Skip to content

Commit fab19c8

Browse files
committed
增加testNetworkInterface测试用例
回退flushBuffer方法抛异常处理 attributes属性调整为LinkedHashMap
1 parent fd302a5 commit fab19c8

File tree

4 files changed

+30
-4
lines changed

4 files changed

+30
-4
lines changed

foundations/foundation-common/src/test/java/org/apache/servicecomb/foundation/common/net/TestNetUtils.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,13 @@
2020
import java.io.IOException;
2121
import java.net.InetAddress;
2222
import java.net.ServerSocket;
23+
import java.util.HashMap;
24+
import java.util.Map;
2325
import java.util.function.Consumer;
2426

2527
import org.junit.jupiter.api.Assertions;
2628
import org.junit.jupiter.api.Test;
29+
import org.mockito.Mockito;
2730

2831
import mockit.Deencapsulation;
2932

@@ -136,6 +139,28 @@ public void testGetRealListenAddress() {
136139
checkException(v -> NetUtils.getRealListenAddress("http:1", "1.1.1.1:8080"));
137140
}
138141

142+
@Test
143+
public void testNetworkInterface() {
144+
Map<String, InetAddress> org = Deencapsulation.getField(NetUtils.class, "allInterfaceAddresses");
145+
146+
Map<String, InetAddress> newValue = new HashMap<>();
147+
InetAddress addr = Mockito.mock(InetAddress.class);
148+
newValue.put("eth100", addr);
149+
Deencapsulation.setField(NetUtils.class, "allInterfaceAddresses", newValue);
150+
151+
Assertions.assertEquals(addr, NetUtils.getInterfaceAddress("eth100"));
152+
Assertions.assertEquals(addr, NetUtils.ensureGetInterfaceAddress("eth100"));
153+
154+
try {
155+
NetUtils.ensureGetInterfaceAddress("xxx");
156+
Assertions.fail("must throw exception");
157+
} catch (IllegalArgumentException e) {
158+
Assertions.assertEquals("Can not find address for interface name: xxx", e.getMessage());
159+
}
160+
161+
Deencapsulation.setField(NetUtils.class, "allInterfaceAddresses", org);
162+
}
163+
139164
@Test
140165
public void testCanTcpListenNo() throws IOException {
141166
InetAddress address = InetAddress.getByName("127.0.0.1");

foundations/foundation-vertx/src/main/java/org/apache/servicecomb/foundation/vertx/http/AbstractHttpServletResponse.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public int getBufferSize() {
8585

8686
@Override
8787
public void flushBuffer() throws IOException {
88-
// for vert.x do noting
88+
throw new Error("not supported method");
8989
}
9090

9191
@Override

foundations/foundation-vertx/src/test/java/org/apache/servicecomb/foundation/vertx/http/TestAbstractHttpServletResponse.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public void testGetBufferSize() {
9191

9292
@Test
9393
public void testFlushBuffer() {
94-
Assertions.assertDoesNotThrow(() -> response.flushBuffer());
94+
Error error = Assertions.assertThrows(Error.class, () -> response.flushBuffer());
95+
checkError(error);
9596
}
9697

9798
@Test

providers/provider-springmvc/src/main/java/org/apache/servicecomb/provider/springmvc/reference/CseClientHttpRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.io.OutputStream;
2121
import java.lang.reflect.Type;
2222
import java.net.URI;
23-
import java.util.HashMap;
23+
import java.util.LinkedHashMap;
2424
import java.util.List;
2525
import java.util.Map;
2626

@@ -76,7 +76,7 @@ public class CseClientHttpRequest implements ClientHttpRequest {
7676

7777
private Type responseType;
7878

79-
private final Map<String, Object> attributes = new HashMap<>();
79+
private final Map<String, Object> attributes = new LinkedHashMap<>();
8080

8181
public CseClientHttpRequest() {
8282
}

0 commit comments

Comments
 (0)