Skip to content

Commit 00a936d

Browse files
committed
feat: add address param
1 parent a606b83 commit 00a936d

1 file changed

Lines changed: 213 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
/*
2+
* Tencent is pleased to support the open source community by making tRPC available.
3+
*
4+
* Copyright (C) 2023 Tencent.
5+
* All rights reserved.
6+
*
7+
* If you have downloaded a copy of the tRPC source code from Tencent,
8+
* please note that tRPC source code is licensed under the Apache 2.0 License,
9+
* A copy of the Apache 2.0 License can be found in the LICENSE file.
10+
*/
11+
12+
package com.tencent.trpc.spring.context.configuration.schema;
13+
14+
import static org.junit.Assert.assertEquals;
15+
import static org.junit.Assert.assertNotNull;
16+
import static org.junit.Assert.assertTrue;
17+
18+
import com.google.common.collect.Maps;
19+
import java.util.Map;
20+
import org.junit.Before;
21+
import org.junit.Test;
22+
23+
public class AbstractProtocolSchemaTest {
24+
25+
/**
26+
* 使用匿名子类实例化抽象类
27+
*/
28+
private AbstractProtocolSchema schema;
29+
30+
@Before
31+
public void setUp() {
32+
schema = new AbstractProtocolSchema() {
33+
};
34+
}
35+
36+
@Test
37+
public void testProtocol() {
38+
schema.setProtocol("trpc");
39+
assertEquals("trpc", schema.getProtocol());
40+
}
41+
42+
@Test
43+
public void testProtocolType() {
44+
schema.setProtocolType("stream");
45+
assertEquals("stream", schema.getProtocolType());
46+
}
47+
48+
@Test
49+
public void testSerialization() {
50+
schema.setSerialization("pb");
51+
assertEquals("pb", schema.getSerialization());
52+
}
53+
54+
@Test
55+
public void testCompressor() {
56+
schema.setCompressor("gzip");
57+
assertEquals("gzip", schema.getCompressor());
58+
}
59+
60+
@Test
61+
public void testCompressMinBytes() {
62+
schema.setCompressMinBytes(1024);
63+
assertEquals(Integer.valueOf(1024), schema.getCompressMinBytes());
64+
}
65+
66+
@Test
67+
public void testSign() {
68+
schema.setSign("hmac");
69+
assertEquals("hmac", schema.getSign());
70+
}
71+
72+
@Test
73+
public void testKeepAlive() {
74+
schema.setKeepAlive(Boolean.TRUE);
75+
assertEquals(Boolean.TRUE, schema.getKeepAlive());
76+
77+
schema.setKeepAlive(Boolean.FALSE);
78+
assertEquals(Boolean.FALSE, schema.getKeepAlive());
79+
}
80+
81+
@Test
82+
public void testCharset() {
83+
schema.setCharset("UTF-8");
84+
assertEquals("UTF-8", schema.getCharset());
85+
}
86+
87+
@Test
88+
public void testTransporter() {
89+
schema.setTransporter("netty");
90+
assertEquals("netty", schema.getTransporter());
91+
}
92+
93+
@Test
94+
public void testMaxConns() {
95+
schema.setMaxConns(100);
96+
assertEquals(Integer.valueOf(100), schema.getMaxConns());
97+
}
98+
99+
@Test
100+
public void testBacklog() {
101+
schema.setBacklog(512);
102+
assertEquals(Integer.valueOf(512), schema.getBacklog());
103+
}
104+
105+
@Test
106+
public void testNetwork() {
107+
schema.setNetwork("tcp");
108+
assertEquals("tcp", schema.getNetwork());
109+
}
110+
111+
@Test
112+
public void testReceiveBuffer() {
113+
schema.setReceiveBuffer(8192);
114+
assertEquals(Integer.valueOf(8192), schema.getReceiveBuffer());
115+
}
116+
117+
@Test
118+
public void testSendBuffer() {
119+
schema.setSendBuffer(4096);
120+
assertEquals(Integer.valueOf(4096), schema.getSendBuffer());
121+
}
122+
123+
@Test
124+
public void testPayload() {
125+
schema.setPayload(10485760);
126+
assertEquals(Integer.valueOf(10485760), schema.getPayload());
127+
}
128+
129+
@Test
130+
public void testIdleTimeout() {
131+
schema.setIdleTimeout(180000);
132+
assertEquals(Integer.valueOf(180000), schema.getIdleTimeout());
133+
}
134+
135+
@Test
136+
public void testLazyinit() {
137+
schema.setLazyinit(Boolean.TRUE);
138+
assertEquals(Boolean.TRUE, schema.getLazyinit());
139+
140+
schema.setLazyinit(Boolean.FALSE);
141+
assertEquals(Boolean.FALSE, schema.getLazyinit());
142+
}
143+
144+
@Test
145+
public void testIoThreadGroupShare() {
146+
schema.setIoThreadGroupShare(Boolean.TRUE);
147+
assertEquals(Boolean.TRUE, schema.getIoThreadGroupShare());
148+
149+
schema.setIoThreadGroupShare(Boolean.FALSE);
150+
assertEquals(Boolean.FALSE, schema.getIoThreadGroupShare());
151+
}
152+
153+
@Test
154+
public void testIoThreads() {
155+
schema.setIoThreads(8);
156+
assertEquals(Integer.valueOf(8), schema.getIoThreads());
157+
}
158+
159+
@Test
160+
public void testFlushConsolidation() {
161+
schema.setFlushConsolidation(Boolean.TRUE);
162+
assertEquals(Boolean.TRUE, schema.getFlushConsolidation());
163+
164+
schema.setFlushConsolidation(Boolean.FALSE);
165+
assertEquals(Boolean.FALSE, schema.getFlushConsolidation());
166+
}
167+
168+
@Test
169+
public void testBatchDecoder() {
170+
schema.setBatchDecoder(Boolean.TRUE);
171+
assertEquals(Boolean.TRUE, schema.getBatchDecoder());
172+
173+
schema.setBatchDecoder(Boolean.FALSE);
174+
assertEquals(Boolean.FALSE, schema.getBatchDecoder());
175+
}
176+
177+
@Test
178+
public void testExplicitFlushAfterFlushes() {
179+
schema.setExplicitFlushAfterFlushes(256);
180+
assertEquals(Integer.valueOf(256), schema.getExplicitFlushAfterFlushes());
181+
}
182+
183+
@Test
184+
public void testAddress() {
185+
schema.setAddress("127.0.0.1:9092?topics=quickstart-events&group=quickstart-group");
186+
assertEquals("127.0.0.1:9092?topics=quickstart-events&group=quickstart-group",
187+
schema.getAddress());
188+
}
189+
190+
@Test
191+
public void testExtMap() {
192+
// 默认 extMap 不为 null
193+
assertNotNull(schema.getExtMap());
194+
195+
Map<String, Object> extMap = Maps.newHashMap();
196+
extMap.put("key1", "value1");
197+
extMap.put("key2", 42);
198+
schema.setExtMap(extMap);
199+
200+
assertEquals(2, schema.getExtMap().size());
201+
assertEquals("value1", schema.getExtMap().get("key1"));
202+
assertEquals(42, schema.getExtMap().get("key2"));
203+
}
204+
205+
@Test
206+
public void testDefaultExtMapNotNull() {
207+
// 新建实例时 extMap 默认初始化为空 Map,不为 null
208+
AbstractProtocolSchema newSchema = new AbstractProtocolSchema() {
209+
};
210+
assertNotNull(newSchema.getExtMap());
211+
assertTrue(newSchema.getExtMap().isEmpty());
212+
}
213+
}

0 commit comments

Comments
 (0)