-
Notifications
You must be signed in to change notification settings - Fork 206
/
test_connection.go
64 lines (52 loc) · 2.2 KB
/
test_connection.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package rmq
import (
"errors"
"fmt"
"sync"
)
var errorNotSupported = errors.New("not supported")
type TestConnection struct {
queues *sync.Map
}
func NewTestConnection() TestConnection {
return TestConnection{
queues: &sync.Map{},
}
}
func (connection TestConnection) OpenQueue(name string) (Queue, error) {
queue, _ := connection.queues.LoadOrStore(name, NewTestQueue(name))
return queue.(*TestQueue), nil
}
func (TestConnection) CollectStats([]string) (Stats, error) { panic(errorNotSupported) }
func (TestConnection) GetOpenQueues() ([]string, error) { panic(errorNotSupported) }
func (TestConnection) StopAllConsuming() <-chan struct{} { panic(errorNotSupported) }
func (TestConnection) checkHeartbeat() error { panic(errorNotSupported) }
func (TestConnection) getConnections() ([]string, error) { panic(errorNotSupported) }
func (TestConnection) hijackConnection(string) Connection { panic(errorNotSupported) }
func (TestConnection) closeStaleConnection() error { panic(errorNotSupported) }
func (TestConnection) getConsumingQueues() ([]string, error) { panic(errorNotSupported) }
func (TestConnection) unlistAllQueues() error { panic(errorNotSupported) }
func (TestConnection) openQueue(string) Queue { panic(errorNotSupported) }
func (TestConnection) stopHeartbeat() error { panic(errorNotSupported) }
func (TestConnection) flushDb() error { panic(errorNotSupported) }
// test helpers for test inspection and similar
func (connection TestConnection) GetDeliveries(queueName string) []string {
queue, ok := connection.queues.Load(queueName)
if !ok {
return []string{}
}
return queue.(*TestQueue).LastDeliveries
}
func (connection TestConnection) GetDelivery(queueName string, index int) string {
queue, ok := connection.queues.Load(queueName)
if !ok || index < 0 || index >= len(queue.(*TestQueue).LastDeliveries) {
return fmt.Sprintf("rmq.TestConnection: delivery not found: %s[%d]", queueName, index)
}
return queue.(*TestQueue).LastDeliveries[index]
}
func (connection TestConnection) Reset() {
connection.queues.Range(func(_, v interface{}) bool {
v.(*TestQueue).Reset()
return true
})
}