forked from wellle/rmq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_connection.go
54 lines (43 loc) · 1.19 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
package rmq
import (
"fmt"
"sync"
)
type TestConnection struct {
queues *sync.Map
}
func NewTestConnection() TestConnection {
return TestConnection{
queues: &sync.Map{},
}
}
func (connection TestConnection) OpenQueue(name string) Queue {
queue, _ := connection.queues.LoadOrStore(name, NewTestQueue(name))
return queue.(*TestQueue)
}
func (connection TestConnection) CollectStats(queueList []string) Stats {
return Stats{}
}
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
})
}
func (connection TestConnection) GetOpenQueues() []string {
return []string{}
}