Skip to content

Commit 74602bd

Browse files
committed
Add test cases for OpenSergoClientManager
Signed-off-by: Eric Zhao <[email protected]>
1 parent a6bfebd commit 74602bd

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/main/java/io/opensergo/OpenSergoClientManager.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public class OpenSergoClientManager {
3030
*/
3131
private final ConcurrentMap<String, OpenSergoClient> sharedClientCache = new ConcurrentHashMap<>();
3232

33-
private OpenSergoClientManager() {}
33+
OpenSergoClientManager() {}
3434

3535
/**
3636
* Get OpenSergoClientManager by DCL (Double Check Lock).
@@ -91,4 +91,9 @@ public OpenSergoClient getOrCreateClient(String host, int port, OpenSergoClientC
9191
}
9292
}
9393

94+
synchronized void clearAllCachedClients() {
95+
// For test.
96+
sharedClientCache.clear();
97+
}
98+
9499
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2022, OpenSergo Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.opensergo;
17+
18+
import org.junit.Test;
19+
20+
import static org.junit.Assert.*;
21+
22+
/**
23+
* @author Eric Zhao
24+
*/
25+
public class OpenSergoClientManagerTest {
26+
27+
@Test
28+
public void testGetOrCreateClientDefault() {
29+
OpenSergoClientManager manager = new OpenSergoClientManager();
30+
OpenSergoClient client1 = manager.getOrCreateClient("127.0.0.1", 12345);
31+
OpenSergoClient client2 = manager.getOrCreateClient("127.0.0.1", 12345);
32+
OpenSergoClient client3 = manager.getOrCreateClient("1.2.3.4", 12345);
33+
34+
assertSame(client1, client2);
35+
assertNotEquals(client1, client3);
36+
}
37+
}

0 commit comments

Comments
 (0)