2 // Copyright © 2011-2019 Guy M. Allard
4 // Licensed under the Apache License, Veridon 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 permisidons and
14 // limitations under the License.
32 func TestAckErrors(t
*testing
.T
) {
35 conn
, e
= Connect(n
, ch
)
37 t
.Fatalf("TestAckErrors CONNECT expected nil, got %v\n", e
)
40 for _
, tv
:= range terrList
{
41 conn
.protocol
= tv
.proto
// Fake it
42 e
= conn
.Ack(tv
.headers
)
44 t
.Fatalf("ACK -%s- expected error [%v], got [%v]\n",
45 tv
.proto
, tv
.errval
, e
)
48 checkReceived(t
, conn
, false)
49 e
= conn
.Disconnect(empty_headers
)
50 checkDisconnectError(t
, e
)
55 Test Ack Same Connection.
57 func TestAckSameConn(t
*testing
.T
) {
58 for _
, sp
:= range Protocols() {
61 ch
= headersProtocol(ch
, sp
)
62 conn
, e
= Connect(n
, ch
)
64 t
.Fatalf("TestAckSameConn CONNECT expected nil, got %v\n", e
)
68 wh
:= Headers
{HK_DESTINATION
,
69 tdest(TEST_TDESTPREF
+ "acksc1-" + conn
.Protocol())}
71 sbh
:= wh
.Add(HK_ACK
, AckModeClient
)
72 id
:= TEST_TDESTPREF
+ "acksc1.chkprotocol-" + conn
.Protocol()
73 sbh
= sbh
.Add(HK_ID
, id
) // Always use an 'id'
74 ms
:= "acksc1 message 1"
77 sc
, e
= conn
.Subscribe(sbh
)
79 t
.Fatalf("TestAckSameConn SUBSCRIBE expected [nil], got: [%v]\n", e
)
85 // For RabbitMQ and STOMP 1.0, do not add current-time header, where the
86 // value contains ':' characters.
87 switch conn
.Protocol() {
89 if os
.Getenv("STOMP_RMQ") == "" {
90 sh
= sh
.Add("current-time", time
.Now().String()) // The added header value has ':' characters
93 sh
= sh
.Add("current-time", time
.Now().String()) // The added header value has ':' characters
97 t
.Fatalf("TestAckSameConn SEND expected [nil], got: [%v]\n", e
)
103 case md
= <-conn
.MessageData
:
104 t
.Fatalf("TestAckSameConn read channel error: expected [nil], got: [%v] msg: [%v] err: [%v]\n",
105 md
.Message
.Command
, md
.Message
, md
.Error
)
108 t
.Fatalf("TestAckSameConn read error: expected [nil], got: [%v]\n",
111 if ms
!= md
.Message
.BodyString() {
112 t
.Fatalf("TestAckSameConn message error: expected: [%v], got: [%v] Message: [%q]\n",
113 ms
, md
.Message
.BodyString(), md
.Message
)
117 if conn
.Protocol() == SPL_12
{
118 ah
= ah
.Add(HK_ID
, md
.Message
.Headers
.Value(HK_ACK
))
120 ah
= ah
.Add(HK_MESSAGE_ID
, md
.Message
.Headers
.Value(HK_MESSAGE_ID
))
123 if conn
.Protocol() == SPL_11
{
124 ah
= ah
.Add(HK_SUBSCRIPTION
, id
) // Always use subscription for 1.1
129 t
.Fatalf("ACK expected [nil], got: [%v]\n", e
)
131 // Make sure Apollo Jira issue APLO-88 stays fixed.
134 t
.Fatalf("TestAckSameConn RECEIVE not expected, got: [%v]\n", md
)
139 uh
:= wh
.Add(HK_ID
, id
)
140 e
= conn
.Unsubscribe(uh
)
142 t
.Fatalf("TestAckSameConn UNSUBSCRIBE expected [nil], got: [%v]\n", e
)
146 checkReceived(t
, conn
, false)
147 e
= conn
.Disconnect(empty_headers
)
148 checkDisconnectError(t
, e
)
154 Test Ack Different Connection.
156 func TestAckDiffConn(t
*testing
.T
) {
158 for _
, sp
:= range Protocols() {
161 ch
= headersProtocol(ch
, sp
)
162 conn
, e
= Connect(n
, ch
)
164 t
.Fatalf("TestAckDiffConn CONNECT expected nil, got %v\n", e
)
168 wh
:= Headers
{HK_DESTINATION
,
169 tdest(TEST_TDESTPREF
+ "ackdc1-" + conn
.Protocol())}
170 ms
:= "ackdc1 message 1"
173 // For RabbitMQ and STOMP 1.0, do not add current-time header, where the
174 // value contains ':' characters.
175 switch conn
.Protocol() {
177 if os
.Getenv("STOMP_RMQ") == "" {
178 sh
= sh
.Add("current-time", time
.Now().String()) // The added header value has ':' characters
181 sh
= sh
.Add("current-time", time
.Now().String()) // The added header value has ':' characters
183 e
= conn
.Send(sh
, ms
)
185 t
.Fatalf("TestAckDiffConn SEND expected [nil], got: [%v]\n", e
)
188 checkReceived(t
, conn
, false)
189 e
= conn
.Disconnect(empty_headers
)
190 checkDisconnectError(t
, e
)
195 ch
= headersProtocol(ch
, sp
)
196 conn
, e
= Connect(n
, ch
) // Reconnect
198 t
.Fatalf("TestAckDiffConn Second Connect, expected no error, got:<%v>\n", e
)
202 sbh
:= wh
.Add(HK_ACK
, AckModeClient
)
203 id
:= "ackdc1.chkprotocol-" + conn
.Protocol()
204 sbh
= sbh
.Add(HK_ID
, id
) // Always use an 'id'
206 log
.Printf("SUB Headers: [%q]\n", sbh
)
207 sc
, e
= conn
.Subscribe(sbh
)
209 t
.Fatalf("TestAckDiffConn SUBSCRIBE expected [nil], got: [%v]\n", e
)
214 case md
= <-conn
.MessageData
:
215 t
.Fatalf("TestAckDiffConn read channel error: expected [nil], got: [%v], msg: [%v], err: [%v]\n",
216 md
.Message
.Command
, md
.Message
, md
.Error
)
219 t
.Fatalf("read error: expected [nil], got: [%v]\n", md
.Error
)
221 if ms
!= md
.Message
.BodyString() {
222 t
.Fatalf("TestAckDiffConn message error: expected: [%v], got: [%v] Message: [%q]\n",
223 ms
, md
.Message
.BodyString(), md
.Message
)
227 if conn
.Protocol() == SPL_12
{
228 ah
= ah
.Add(HK_ID
, md
.Message
.Headers
.Value(HK_ACK
))
230 ah
= ah
.Add(HK_MESSAGE_ID
, md
.Message
.Headers
.Value(HK_MESSAGE_ID
))
233 if conn
.Protocol() == SPL_11
{
234 ah
= ah
.Add(HK_SUBSCRIPTION
, id
) // Always use subscription for 1.1
239 t
.Fatalf("TestAckDiffConn ACK expected [nil], got: [%v]\n", e
)
241 // Make sure Apollo Jira issue APLO-88 stays fixed.
244 t
.Fatalf("TestAckDiffConn RECEIVE not expected, got: [%v]\n", md
)
248 uh
:= wh
.Add(HK_ID
, id
)
249 e
= conn
.Unsubscribe(uh
)
251 t
.Fatalf("TestAckDiffConn UNSUBSCRIBE expected [nil], got: [%v]\n", e
)
254 checkReceived(t
, conn
, false)
255 e
= conn
.Disconnect(empty_headers
)
256 checkDisconnectError(t
, e
)