Skip to content

Commit 9f0216d

Browse files
committed
remove unused methods
1 parent b865950 commit 9f0216d

File tree

8 files changed

+48
-75
lines changed

8 files changed

+48
-75
lines changed

hitless/pool_hook_test.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,6 @@ func (mp *mockPool) RemovePoolHook(hook pool.PoolHook) {
100100
// Mock implementation - do nothing
101101
}
102102

103-
func (mp *mockPool) TrackConn(conn *pool.Conn) {
104-
// Mock implementation - do nothing
105-
}
106-
107-
func (mp *mockPool) UntrackConn(conn *pool.Conn) {
108-
// Mock implementation - do nothing
109-
}
110-
111103
func (mp *mockPool) Close() error {
112104
return nil
113105
}

internal/pool/hooks_test.go

Lines changed: 38 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ import (
1010

1111
// TestHook for testing hook functionality
1212
type TestHook struct {
13-
OnGetCalled int
14-
OnPutCalled int
15-
GetError error
16-
PutError error
17-
ShouldPool bool
13+
OnGetCalled int
14+
OnPutCalled int
15+
GetError error
16+
PutError error
17+
ShouldPool bool
1818
ShouldRemove bool
1919
}
2020

@@ -30,97 +30,97 @@ func (th *TestHook) OnPut(ctx context.Context, conn *Conn) (shouldPool bool, sho
3030

3131
func TestPoolHookManager(t *testing.T) {
3232
manager := NewPoolHookManager()
33-
33+
3434
// Test initial state
3535
if manager.GetHookCount() != 0 {
3636
t.Errorf("Expected 0 hooks initially, got %d", manager.GetHookCount())
3737
}
38-
38+
3939
// Add hooks
4040
hook1 := &TestHook{ShouldPool: true}
4141
hook2 := &TestHook{ShouldPool: true}
42-
42+
4343
manager.AddHook(hook1)
4444
manager.AddHook(hook2)
45-
45+
4646
if manager.GetHookCount() != 2 {
4747
t.Errorf("Expected 2 hooks after adding, got %d", manager.GetHookCount())
4848
}
49-
49+
5050
// Test ProcessOnGet
5151
ctx := context.Background()
5252
conn := &Conn{} // Mock connection
53-
53+
5454
err := manager.ProcessOnGet(ctx, conn, false)
5555
if err != nil {
5656
t.Errorf("ProcessOnGet should not error: %v", err)
5757
}
58-
58+
5959
if hook1.OnGetCalled != 1 {
6060
t.Errorf("Expected hook1.OnGetCalled to be 1, got %d", hook1.OnGetCalled)
6161
}
62-
62+
6363
if hook2.OnGetCalled != 1 {
6464
t.Errorf("Expected hook2.OnGetCalled to be 1, got %d", hook2.OnGetCalled)
6565
}
66-
66+
6767
// Test ProcessOnPut
6868
shouldPool, shouldRemove, err := manager.ProcessOnPut(ctx, conn)
6969
if err != nil {
7070
t.Errorf("ProcessOnPut should not error: %v", err)
7171
}
72-
72+
7373
if !shouldPool {
7474
t.Error("Expected shouldPool to be true")
7575
}
76-
76+
7777
if shouldRemove {
7878
t.Error("Expected shouldRemove to be false")
7979
}
80-
80+
8181
if hook1.OnPutCalled != 1 {
8282
t.Errorf("Expected hook1.OnPutCalled to be 1, got %d", hook1.OnPutCalled)
8383
}
84-
84+
8585
if hook2.OnPutCalled != 1 {
8686
t.Errorf("Expected hook2.OnPutCalled to be 1, got %d", hook2.OnPutCalled)
8787
}
88-
88+
8989
// Remove a hook
9090
manager.RemoveHook(hook1)
91-
91+
9292
if manager.GetHookCount() != 1 {
9393
t.Errorf("Expected 1 hook after removing, got %d", manager.GetHookCount())
9494
}
9595
}
9696

9797
func TestHookErrorHandling(t *testing.T) {
9898
manager := NewPoolHookManager()
99-
99+
100100
// Hook that returns error on Get
101101
errorHook := &TestHook{
102-
GetError: errors.New("test error"),
102+
GetError: errors.New("test error"),
103103
ShouldPool: true,
104104
}
105-
105+
106106
normalHook := &TestHook{ShouldPool: true}
107-
107+
108108
manager.AddHook(errorHook)
109109
manager.AddHook(normalHook)
110-
110+
111111
ctx := context.Background()
112112
conn := &Conn{}
113-
113+
114114
// Test that error stops processing
115115
err := manager.ProcessOnGet(ctx, conn, false)
116116
if err == nil {
117117
t.Error("Expected error from ProcessOnGet")
118118
}
119-
119+
120120
if errorHook.OnGetCalled != 1 {
121121
t.Errorf("Expected errorHook.OnGetCalled to be 1, got %d", errorHook.OnGetCalled)
122122
}
123-
123+
124124
// normalHook should not be called due to error
125125
if normalHook.OnGetCalled != 0 {
126126
t.Errorf("Expected normalHook.OnGetCalled to be 0, got %d", normalHook.OnGetCalled)
@@ -129,46 +129,44 @@ func TestHookErrorHandling(t *testing.T) {
129129

130130
func TestHookShouldRemove(t *testing.T) {
131131
manager := NewPoolHookManager()
132-
132+
133133
// Hook that says to remove connection
134134
removeHook := &TestHook{
135-
ShouldPool: false,
135+
ShouldPool: false,
136136
ShouldRemove: true,
137137
}
138-
138+
139139
normalHook := &TestHook{ShouldPool: true}
140-
140+
141141
manager.AddHook(removeHook)
142142
manager.AddHook(normalHook)
143-
143+
144144
ctx := context.Background()
145145
conn := &Conn{}
146-
146+
147147
shouldPool, shouldRemove, err := manager.ProcessOnPut(ctx, conn)
148148
if err != nil {
149149
t.Errorf("ProcessOnPut should not error: %v", err)
150150
}
151-
151+
152152
if shouldPool {
153153
t.Error("Expected shouldPool to be false")
154154
}
155-
155+
156156
if !shouldRemove {
157157
t.Error("Expected shouldRemove to be true")
158158
}
159-
159+
160160
if removeHook.OnPutCalled != 1 {
161161
t.Errorf("Expected removeHook.OnPutCalled to be 1, got %d", removeHook.OnPutCalled)
162162
}
163-
163+
164164
// normalHook should not be called due to early return
165165
if normalHook.OnPutCalled != 0 {
166166
t.Errorf("Expected normalHook.OnPutCalled to be 0, got %d", normalHook.OnPutCalled)
167167
}
168168
}
169169

170-
171-
172170
func TestPoolWithHooks(t *testing.T) {
173171
// Create a pool with hooks
174172
hookManager := NewPoolHookManager()

internal/pool/pool.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,6 @@ type Pooler interface {
7070
AddPoolHook(hook PoolHook)
7171
RemovePoolHook(hook PoolHook)
7272

73-
TrackConn(*Conn)
74-
UntrackConn(*Conn)
75-
7673
Close() error
7774
}
7875

@@ -758,15 +755,4 @@ func (p *ConnPool) isHealthyConn(cn *Conn, now time.Time) bool {
758755
return true
759756
}
760757

761-
func (p *ConnPool) TrackConn(cn *Conn) {
762-
p.connsMu.Lock()
763-
p.poolSize.Add(1)
764-
p.conns[cn.GetID()] = cn
765-
p.connsMu.Unlock()
766-
}
767758

768-
func (p *ConnPool) UntrackConn(cn *Conn) {
769-
p.connsMu.Lock()
770-
delete(p.conns, cn.GetID())
771-
p.connsMu.Unlock()
772-
}

internal/pool/pool_single.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,3 @@ func (p *SingleConnPool) Stats() *Stats {
6262
func (p *SingleConnPool) AddPoolHook(hook PoolHook) {}
6363

6464
func (p *SingleConnPool) RemovePoolHook(hook PoolHook) {}
65-
66-
func (p *SingleConnPool) TrackConn(cn *Conn) {}
67-
68-
func (p *SingleConnPool) UntrackConn(cn *Conn) {}

internal/pool/pool_sticky.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,3 @@ func (p *StickyConnPool) Stats() *Stats {
203203
func (p *StickyConnPool) AddPoolHook(hook PoolHook) {}
204204

205205
func (p *StickyConnPool) RemovePoolHook(hook PoolHook) {}
206-
207-
func (p *StickyConnPool) TrackConn(cn *Conn) {}
208-
209-
func (p *StickyConnPool) UntrackConn(cn *Conn) {}

osscluster.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1883,7 +1883,9 @@ func (c *ClusterClient) pubSub() *PubSub {
18831883
return cn, nil
18841884
},
18851885
closeConn: func(cn *pool.Conn) error {
1886-
err := node.Client.connPool.CloseConn(cn)
1886+
// Untrack connection from PubSubPool
1887+
node.Client.pubSubPool.UntrackConn(cn)
1888+
err := cn.Close()
18871889
node = nil
18881890
return err
18891891
},

redis.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,10 +1061,12 @@ func (c *Client) pubSub() *PubSub {
10611061
_ = cn.Close()
10621062
return nil, err
10631063
}
1064+
// Track connection in PubSubPool
10641065
c.pubSubPool.TrackConn(cn)
10651066
return cn, nil
10661067
},
10671068
closeConn: func(cn *pool.Conn) error {
1069+
// Untrack connection from PubSubPool
10681070
c.pubSubPool.UntrackConn(cn)
10691071
_ = cn.Close()
10701072
return nil

sentinel.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -580,22 +580,23 @@ func (c *SentinelClient) pubSub() *PubSub {
580580
pubsub := &PubSub{
581581
opt: c.opt,
582582
newConn: func(ctx context.Context, addr string, channels []string) (*pool.Conn, error) {
583-
netConn, err := c.dialHook(ctx, c.opt.Network, addr)
583+
cn, err := c.pubSubPool.NewConn(ctx, c.opt.Network, addr, channels)
584584
if err != nil {
585585
return nil, err
586586
}
587-
cn := pool.NewConnWithBufferSize(netConn, c.opt.ReadBufferSize, c.opt.WriteBufferSize)
588-
589587
// will return nil if already initialized
590588
err = c.initConn(ctx, cn)
591589
if err != nil {
592590
_ = cn.Close()
593591
return nil, err
594592
}
595-
593+
// Track connection in PubSubPool
594+
c.pubSubPool.TrackConn(cn)
596595
return cn, nil
597596
},
598597
closeConn: func(cn *pool.Conn) error {
598+
// Untrack connection from PubSubPool
599+
c.pubSubPool.UntrackConn(cn)
599600
_ = cn.Close()
600601
return nil
601602
},

0 commit comments

Comments
 (0)