refactor: remove unused connectionPool.get and connectionPool.count methods

This commit is contained in:
xfy 2026-06-03 13:46:25 +08:00
parent caae75ff96
commit 596237e484
3 changed files with 8 additions and 22 deletions

View File

@ -431,25 +431,25 @@ func TestConnectionPoolOperations(t *testing.T) {
pool.add("client1", conn2) pool.add("client1", conn2)
// 验证连接数 // 验证连接数
if count := pool.count("client1"); count != 2 { if count := len(pool.conns["client1"]); count != 2 {
t.Errorf("Expected 2 connections, got %d", count) t.Errorf("Expected 2 connections, got %d", count)
} }
// 获取连接 // 获取连接
conns := pool.get("client1") conns := pool.conns["client1"]
if len(conns) != 2 { if len(conns) != 2 {
t.Errorf("Expected 2 connections, got %d", len(conns)) t.Errorf("Expected 2 connections, got %d", len(conns))
} }
// 移除连接 // 移除连接
pool.remove("client1", conn1) pool.remove("client1", conn1)
if count := pool.count("client1"); count != 1 { if count := len(pool.conns["client1"]); count != 1 {
t.Errorf("Expected 1 connection after removal, got %d", count) t.Errorf("Expected 1 connection after removal, got %d", count)
} }
// 关闭所有连接 // 关闭所有连接
pool.closeAll() pool.closeAll()
if count := pool.count("client1"); count != 0 { if count := len(pool.conns["client1"]); count != 0 {
t.Errorf("Expected 0 connections after closeAll, got %d", count) t.Errorf("Expected 0 connections after closeAll, got %d", count)
} }
} }

View File

@ -572,20 +572,6 @@ func (p *connectionPool) remove(key string, conn net.Conn) {
} }
} }
// get 获取连接。
func (p *connectionPool) get(key string) []net.Conn {
p.mu.RLock()
defer p.mu.RUnlock()
return p.conns[key]
}
// count 获取连接数。
func (p *connectionPool) count(key string) int {
p.mu.RLock()
defer p.mu.RUnlock()
return len(p.conns[key])
}
// closeAll 关闭所有连接。 // closeAll 关闭所有连接。
func (p *connectionPool) closeAll() { func (p *connectionPool) closeAll() {
p.mu.Lock() p.mu.Lock()

View File

@ -444,19 +444,19 @@ func TestConnectionPool(t *testing.T) {
pool.add("key1", conn1) pool.add("key1", conn1)
// 测试获取连接 // 测试获取连接
conns := pool.get("key1") conns := pool.conns["key1"]
if len(conns) != 1 { if len(conns) != 1 {
t.Errorf("Expected 1 connection, got %d", len(conns)) t.Errorf("Expected 1 connection, got %d", len(conns))
} }
// 测试计数 // 测试计数
if count := pool.count("key1"); count != 1 { if count := len(pool.conns["key1"]); count != 1 {
t.Errorf("Expected count 1, got %d", count) t.Errorf("Expected count 1, got %d", count)
} }
// 测试移除连接 // 测试移除连接
pool.remove("key1", conn1) pool.remove("key1", conn1)
if count := pool.count("key1"); count != 0 { if count := len(pool.conns["key1"]); count != 0 {
t.Errorf("Expected count 0 after remove, got %d", count) t.Errorf("Expected count 0 after remove, got %d", count)
} }
} }
@ -953,7 +953,7 @@ func TestConnectionPool_CloseAll(t *testing.T) {
pool.closeAll() pool.closeAll()
// 验证连接池已清空 // 验证连接池已清空
if count := pool.count("key1"); count != 0 { if count := len(pool.conns["key1"]); count != 0 {
t.Errorf("Expected count 0 after closeAll, got %d", count) t.Errorf("Expected count 0 after closeAll, got %d", count)
} }
} }