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.
28 // Test STOMP 1.1 Header Codec - Basic Encode.
29 func TestCodecEncodeBasic(t
*testing
.T
) {
30 for _
, _
= range Protocols() {
31 for _
, ede
:= range tdList
{
32 ev
:= encode(ede
.decoded
)
33 if ede
.encoded
!= ev
{
34 t
.Fatalf("TestCodecEncodeBasic ENCODE ERROR: expected: [%v] got: [%v]",
42 Test STOMP 1.1 Header Codec - Basic Decode.
44 func TestCodecDecodeBasic(t
*testing
.T
) {
45 for _
, _
= range Protocols() {
46 for _
, ede
:= range tdList
{
47 dv
:= decode(ede
.encoded
)
48 if ede
.decoded
!= dv
{
49 t
.Fatalf("TestCodecDecodeBasic DECODE ERROR: expected: [%v] got: [%v]",
56 func BenchmarkCodecEncode(b
*testing
.B
) {
57 for _
, _
= range Protocols() {
58 for i
:= 0; i
< len(tdList
); i
++ {
59 for n
:= 0; n
< b
.N
; n
++ {
60 _
= encode(tdList
[i
].decoded
)
66 func BenchmarkCodecDecode(b
*testing
.B
) {
67 for _
, _
= range Protocols() {
68 for i
:= 0; i
< len(tdList
); i
++ {
69 for n
:= 0; n
< b
.N
; n
++ {
70 _
= decode(tdList
[i
].encoded
)
77 Test STOMP 1.1 Send / Receive - no codec error.
79 func TestCodecSendRecvCodec(t
*testing
.T
) {
80 if os
.Getenv("STOMP_ARTEMIS") != "" {
84 for _
, p
:= range Protocols() {
86 //log.Printf("Protocol: %s\n", p)
87 //log.Printf("MapLen: %d\n", len(usemap))
88 for _
, v
:= range usemap
{
91 // RMQ and STOMP Level 1.0 :
92 // Headers are encoded (as if the STOMP protocol were 1.1
94 // MAYBEDO: Report issue. (Is this a bug or a feature?)
96 if p
== SPL_10
&& os
.Getenv("STOMP_RMQ") != "" {
102 ch
= headersProtocol(ch
, p
)
103 conn
, e
= Connect(n
, ch
)
105 t
.Fatalf("TestCodecSendRecvCodec CONNECT expected nil, got %v\n", e
)
108 d
:= tdest("/queue/gostomp.codec.sendrecv.1.protocol." + p
)
109 ms
:= "msg.codec.sendrecv.1.protocol." + p
+ " - a message"
110 wh
:= Headers
{HK_DESTINATION
, d
}
112 //log.Printf("TestData: %+v\n", v)
114 for i
:= range v
.sk
{
115 sh
= sh
.Add(v
.sk
[i
], v
.sv
[i
])
118 //log.Printf("Send Headers: %v\n", sh)
119 e
= conn
.Send(sh
, ms
)
121 t
.Fatalf("TestCodecSendRecvCodec Send failed: %v protocol:%s\n",
124 // Check for ERROR frame
125 time
.Sleep(1e9
/ 8) // Wait one eigth
126 // Poll for adhoc ERROR from server
128 case vx
:= <-conn
.MessageData
:
129 t
.Fatalf("TestCodecSendRecvCodec Send Error: [%v] protocol:%s\n",
135 sbh
:= wh
.Add(HK_ID
, v
.sid
)
136 //log.Printf("Subscribe Headers: %v\n", sbh)
137 sc
, e
= conn
.Subscribe(sbh
)
139 t
.Fatalf("TestCodecSendRecvCodec Subscribe failed: %v protocol:%s\n",
143 t
.Fatalf("TestCodecSendRecvCodec Subscribe sub chan is nil protocol:%s\n",
147 checkReceivedMD(t
, conn
, sc
, "codec_test_"+p
) // Receive
149 b
:= md
.Message
.BodyString()
151 t
.Fatalf("TestCodecSendRecvCodec Receive expected: [%v] got: [%v] protocol:%s\n",
155 //log.Printf("Unsubscribe Headers: %v\n", sbh)
156 e
= conn
.Unsubscribe(sbh
)
158 t
.Fatalf("TestCodecSendRecvCodec Unsubscribe failed: %v protocol:%s\n",
162 log
.Printf("Receive Headers: %v\n", md
.Message
.Headers
)
163 log
.Printf("Check map: %v\n", v
.rv
)
164 for key
, value
:= range v
.rv
{
165 log
.Printf("Want Key: [%v] Value: [%v] \n", key
, value
)
166 hv
, ok
= md
.Message
.Headers
.Contains(key
)
168 t
.Fatalf("TestCodecSendRecvCodec Header key expected: [%v] got: [%v] protocol:%s\n",
172 t
.Fatalf("TestCodecSendRecvCodec Header value expected: [%v] got: [%v] protocol:%s\n",
177 checkReceived(t
, conn
, false)
178 e
= conn
.Disconnect(empty_headers
)
179 checkDisconnectError(t
, e
)