Skip to content

Commit 682ed7b

Browse files
committed
test: add unit test for TypeUtils
1 parent c63d247 commit 682ed7b

2 files changed

Lines changed: 70 additions & 2 deletions

File tree

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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 org.apache.dubbo.common.utils;
18+
19+
import java.lang.reflect.Type;
20+
import java.util.List;
21+
import java.util.Map;
22+
23+
import org.junit.jupiter.api.Test;
24+
25+
import static org.junit.jupiter.api.Assertions.*;
26+
27+
class TypeUtilsTest {
28+
29+
static class StringList extends java.util.ArrayList<String> {}
30+
31+
static interface StringIntegerMap extends Map<String, Integer> {}
32+
33+
@Test
34+
void testIsParameterizedType() {
35+
// String is not parameterized
36+
assertFalse(TypeUtils.isParameterizedType(String.class));
37+
38+
// Get the generic superclass of our StringList (which is ArrayList<String>)
39+
Type genericType = StringList.class.getGenericSuperclass();
40+
assertTrue(TypeUtils.isParameterizedType(genericType));
41+
}
42+
43+
@Test
44+
void testGetRawClass() {
45+
Type genericType = StringList.class.getGenericSuperclass(); // ArrayList<String>
46+
assertEquals(java.util.ArrayList.class, TypeUtils.getRawClass(genericType));
47+
48+
// Test with a normal class
49+
assertEquals(String.class, TypeUtils.getRawClass(String.class));
50+
51+
// Test with null
52+
assertNull(TypeUtils.getRawClass(null));
53+
}
54+
55+
@Test
56+
void testFindActualTypeArguments() {
57+
// Check StringList (should find String)
58+
List<Class<?>> args = TypeUtils.findActualTypeArguments(StringList.class, List.class);
59+
assertEquals(1, args.size());
60+
assertEquals(String.class, args.get(0));
61+
}
62+
63+
@Test
64+
void testGetClassName() {
65+
assertEquals(String.class.getName(), TypeUtils.getClassName(String.class));
66+
}
67+
}

dubbo-remoting/dubbo-remoting-netty4/src/main/java/org/apache/dubbo/remoting/transport/netty4/NettyConnectionHandler.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ public void channelActive(ChannelHandlerContext ctx) {
105105
@Override
106106
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
107107
super.channelInactive(ctx);
108+
//creates the pipeline
108109
Channel ch = ctx.channel();
109110
NettyChannel channel = NettyChannel.getOrAddChannel(ch, connectionClient.getUrl(), connectionClient);
110111
try {
111-
Attribute<Boolean> goawayAttr = ch.attr(GO_AWAY_KEY);
112-
if (!Boolean.TRUE.equals(goawayAttr.get())) {
112+
Attribute<Boolean> goawayAttr=ch.attr(GO_AWAY_KEY);
113+
if (!Boolean.TRUE.equals(goawayAttr.get())){
113114
reconnect(ch);
114115
}
115116

0 commit comments

Comments
 (0)