2 // Copyright © 2011-2019 Guy M. Allard
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
27 Test a Stomp 1.1+ duplicate header shovel.
28 The Stomp 1.0 specification level is silent on the subject of duplicate
29 headers. For STOMP 1.1+ this client package is strictly compliant: if user
30 logic passes duplicates, they are sent to the broker.
31 The STOMP 1.1 and 1.2 specifications:
32 a) differ slightly in specified broker behavior
33 b) allow quite a bit of variance in broker behavoir.
36 func TestShovelDupeHeaders(t
*testing
.T
) {
37 for _
, sp
:= range oneOnePlusProtos
{
40 ch
= headersProtocol(ch
, sp
)
41 conn
, e
= Connect(n
, ch
)
43 t
.Fatalf("TestShovelDupeHeaders CONNECT expected no error, got [%v]\n", e
)
48 d
:= tdest("/queue/subunsub.shovel.01")
49 sh
:= Headers
{HK_DESTINATION
, d
}
50 sh
= sh
.AddHeaders(tsdhHeaders
)
53 sbh
:= Headers
{HK_DESTINATION
, d
, HK_ID
, d
}
54 sc
, e
= conn
.Subscribe(sbh
)
56 t
.Fatalf("TestShovelDupeHeaders Expected no subscribe error, got [%v]\n", e
)
59 t
.Fatalf("TestShovelDupeHeaders Expected subscribe channel, got [nil]\n")
66 case md
= <-conn
.MessageData
:
67 t
.Fatalf("TestShovelDupeHeaders read channel error: expected [nil], got: [%v]\n",
73 t
.Fatalf("TestShovelDupeHeaders Expected no message data error, got [%v]\n",
77 //log.Printf("TestShovelDupeHeaders SDHT01: %s <%v>\n", conn.Protocol(),
79 rd
:= rm
.Headers
.Value(HK_DESTINATION
)
81 t
.Fatalf("TestShovelDupeHeaders Expected destination [%v], got [%v]\n",
84 rs
:= rm
.Headers
.Value(HK_SUBSCRIPTION
)
86 t
.Fatalf("TestShovelDupeHeaders Expected subscription [%v], got [%v]\n",
90 // Broker behavior can differ WRT repeated header entries
91 // they receive. Here we try to adjust to observed broker behavior
92 // with the brokers used in local testing.
93 // Also note that the wording of the 1.1 and 1.2 specs is slightly
94 // different WRT repeated header entries.
100 if !rm
.Headers
.ContainsKV("dupkey1", "value0") {
101 t
.Fatalf("TestShovelDupeHeaders AMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
104 if !rm
.Headers
.ContainsKV("dupkey1", "value0") {
105 t
.Fatalf("TestShovelDupeHeaders RMQ Expected true for [%v], [%v]\n", "dupkey1", "value0")
108 if !rm
.Headers
.ContainsKV("dupkey1", "value0") {
109 t
.Fatalf("TestShovelDupeHeaders APOLLO Expected true for [%v], [%v]\n", "dupkey1", "value0")
111 e
= checkDupeHeaders(rm
.Headers
, wantedDupeVAll
)
113 t
.Fatalf("TestShovelDupeHeaders APOLLO Expected dupe headers, but something is missing: %v %v\n",
114 rm
.Headers
, wantedDupeVAll
)
119 if !rm
.Headers
.ContainsKV("dupkey1", "value2") {
120 t
.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value2")
122 } else { // This is SPL_12
123 if !rm
.Headers
.ContainsKV("dupkey1", "value0") {
124 t
.Fatalf("TestShovelDupeHeaders MAIN Expected true for [%v], [%v]\n", "dupkey1", "value0")
132 uh
:= Headers
{HK_ID
, rs
, HK_DESTINATION
, d
}
133 e
= conn
.Unsubscribe(uh
)
135 t
.Fatalf("TestShovelDupeHeaders Expected no unsubscribe error, got [%v]\n",
139 checkReceived(t
, conn
, false)
140 e
= conn
.Disconnect(empty_headers
)
141 checkDisconnectError(t
, e
)