This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
shovel_dupe_headers_test.go
144 lines (135 loc) · 4.25 KB
/
shovel_dupe_headers_test.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// Copyright © 2011-2019 Guy M. Allard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package stompws
import (
"log"
"testing"
)
var _ = log.Println
/*
Test a Stomp 1.1+ duplicate header shovel.
The Stomp 1.0 specification level is silent on the subject of duplicate
headers. For STOMP 1.1+ this client package is strictly compliant: if user
logic passes duplicates, they are sent to the broker.
The STOMP 1.1 and 1.2 specifications:
a) differ slightly in specified broker behavior
b) allow quite a bit of variance in broker behavoir.
As usual: YMMV.
*/
func TestShovelDupeHeaders(t *testing.T) {
for _, sp := range oneOnePlusProtos {
n, _ = openConn(t)
ch := login_headers
ch = headersProtocol(ch, sp)
conn, e = Connect(n, ch)
if e != nil {
t.Fatalf("TestShovelDupeHeaders CONNECT expected no error, got [%v]\n", e)
}
//
ms := "A message"
d := tdest("/queue/subunsub.shovel.01")
sh := Headers{HK_DESTINATION, d}
sh = sh.AddHeaders(tsdhHeaders)
_ = conn.Send(sh, ms)
//
sbh := Headers{HK_DESTINATION, d, HK_ID, d}
sc, e = conn.Subscribe(sbh)
if e != nil {
t.Fatalf("TestShovelDupeHeaders Expected no subscribe error, got [%v]\n", e)
}
if sc == nil {
t.Fatalf("TestShovelDupeHeaders Expected subscribe channel, got [nil]\n")
}
// Read MessageData
var md MessageData
select {
case md = <-sc:
case md = <-conn.MessageData:
t.Fatalf("TestShovelDupeHeaders read channel error: expected [nil], got: [%v]\n",
md.Message.Command)
}
//
if md.Error != nil {
t.Fatalf("TestShovelDupeHeaders Expected no message data error, got [%v]\n",
md.Error)
}
rm := md.Message
//log.Printf("TestShovelDupeHeaders SDHT01: %s <%v>\n", conn.Protocol(),
// rm.Headers)
rd := rm.Headers.Value(HK_DESTINATION)
if rd != d {
t.Fatalf("TestShovelDupeHeaders Expected destination [%v], got [%v]\n",
d, rd)
}
rs := rm.Headers.Value(HK_SUBSCRIPTION)
if rs != d {
t.Fatalf("TestShovelDupeHeaders Expected subscription [%v], got [%v]\n",
d, rs)
}
// Broker behavior can differ WRT repeated header entries
// they receive. Here we try to adjust to observed broker behavior
// with the brokers used in local testing.
// Also note that the wording of the 1.1 and 1.2 specs is slightly
// different WRT repeated header entries.
// In any case: YMMV.
//
switch brokerid {
case TEST_AMQ:
if !rm.Headers.ContainsKV("dupkey1", "value0") {
t.Fatalf("TestShovelDupeHeaders AMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
}
case TEST_RMQ:
if !rm.Headers.ContainsKV("dupkey1", "value0") {
t.Fatalf("TestShovelDupeHeaders RMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
}
case TEST_APOLLO:
if !rm.Headers.ContainsKV("dupkey1", "value0") {
t.Fatalf("TestShovelDupeHeaders APOLLO Expected true for [%v], [%v]\n", "dupkey1", "value0")
}
e = checkDupeHeaders(rm.Headers, wantedDupeVAll)
if e != nil {
t.Fatalf("TestShovelDupeHeaders APOLLO Expected dupe headers, but something is missing: %v %v\n",
rm.Headers, wantedDupeVAll)
}
case TEST_ARTEMIS:
//
if sp == SPL_11 {
if !rm.Headers.ContainsKV("dupkey1", "value2") {
t.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value2")
}
} else { // This is SPL_12
if !rm.Headers.ContainsKV("dupkey1", "value0") {
t.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value0")
}
}
break
//}
default:
}
//
uh := Headers{HK_ID, rs, HK_DESTINATION, d}
e = conn.Unsubscribe(uh)
if e != nil {
t.Fatalf("TestShovelDupeHeaders Expected no unsubscribe error, got [%v]\n",
e)
}
//
checkReceived(t, conn, false)
e = conn.Disconnect(empty_headers)
checkDisconnectError(t, e)
_ = closeConn(t, n)
}
}