Skip to content

Commit b68e862

Browse files
committed
added unit tests
1 parent 31aa13f commit b68e862

File tree

2 files changed

+96
-1
lines changed

2 files changed

+96
-1
lines changed

src/main/java/com/github/jlangch/venice/util/ipc/TcpClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public long getCompressCutoffSize() {
140140
/**
141141
* @return return the client's max message size
142142
*/
143-
public long getMaximumMessageSize() {
143+
public long getMaxMessageSize() {
144144
if (!opened.get()) {
145145
throw new VncException(
146146
"The max message size cannot be queried if the client has "
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
/* __ __ _
2+
* \ \ / /__ _ __ (_) ___ ___
3+
* \ \/ / _ \ '_ \| |/ __/ _ \
4+
* \ / __/ | | | | (_| __/
5+
* \/ \___|_| |_|_|\___\___|
6+
*
7+
*
8+
* Copyright 2017-2025 Venice
9+
*
10+
* Licensed under the Apache License, Version 2.0 (the "License");
11+
* you may not use this file except in compliance with the License.
12+
* You may obtain a copy of the License at
13+
*
14+
* http://www.apache.org/licenses/LICENSE-2.0
15+
*
16+
* Unless required by applicable law or agreed to in writing, software
17+
* distributed under the License is distributed on an "AS IS" BASIS,
18+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19+
* See the License for the specific language governing permissions and
20+
* limitations under the License.
21+
*/
22+
package com.github.jlangch.venice.util.ipc;
23+
24+
import static org.junit.jupiter.api.Assertions.assertEquals;
25+
26+
import org.junit.jupiter.api.Test;
27+
28+
29+
public class TcpClientRuntimeConfigTest {
30+
31+
32+
@Test
33+
public void test_client_defaults() throws Exception {
34+
final TcpServer server = new TcpServer(33333);
35+
final TcpClient client = new TcpClient(33333);
36+
37+
server.start();
38+
39+
sleep(300);
40+
41+
client.open();
42+
43+
try {
44+
assertEquals(false, client.isEncrypted());
45+
assertEquals(-1, client.getCompressCutoffSize());
46+
assertEquals(TcpServer.MESSAGE_LIMIT_MAX, client.getMaxMessageSize());
47+
}
48+
catch(Exception ex) {
49+
// OK
50+
}
51+
finally {
52+
client.close();
53+
server.close();
54+
}
55+
}
56+
57+
@Test
58+
public void test_client_inherit_config() throws Exception {
59+
final TcpServer server = new TcpServer(33333);
60+
final TcpClient client = new TcpClient(33333);
61+
62+
server.setEncryption(true);
63+
server.setMaxMessageSize(3000);
64+
server.setCompressCutoffSize(2000);
65+
66+
server.start();
67+
68+
sleep(300);
69+
70+
client.open();
71+
72+
try {
73+
// check if the client obtained the config from the server
74+
assertEquals(false, client.isEncrypted());
75+
assertEquals(2000, client.getCompressCutoffSize());
76+
assertEquals(3000, client.getMaxMessageSize());
77+
}
78+
catch(Exception ex) {
79+
// OK
80+
}
81+
finally {
82+
client.close();
83+
server.close();
84+
}
85+
}
86+
87+
88+
private void sleep(final long millis) {
89+
try {
90+
Thread.sleep(millis);
91+
}
92+
catch (Exception ignore) {
93+
}
94+
}
95+
}

0 commit comments

Comments
 (0)