2 // Copyright © 2011-2018 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
) {
81 for _
, p
:= range Protocols() {
83 //log.Printf("Protocol: %s\n", p)
84 //log.Printf("MapLen: %d\n", len(usemap))
85 for _
, v
:= range usemap
{
88 // RMQ and STOMP Level 1.0 :
89 // Headers are encoded (as if the STOMP protocol were 1.1
91 // MAYBEDO: Report issue. (Is this a bug or a feature?)
93 if p
== SPL_10
&& os
.Getenv("STOMP_RMQ") != "" {
99 ch
= headersProtocol(ch
, p
)
100 conn
, e
= Connect(n
, ch
)
102 t
.Fatalf("TestCodecSendRecvCodec CONNECT expected nil, got %v\n", e
)
105 d
:= tdest("/queue/gostomp.codec.sendrecv.1.protocol." + p
)
106 ms
:= "msg.codec.sendrecv.1.protocol." + p
+ " - a message"
107 wh
:= Headers
{HK_DESTINATION
, d
}
109 //log.Printf("TestData: %+v\n", v)
111 for i
:= range v
.sk
{
112 sh
= sh
.Add(v
.sk
[i
], v
.sv
[i
])
115 //log.Printf("Send Headers: %v\n", sh)
116 e
= conn
.Send(sh
, ms
)
118 t
.Fatalf("TestCodecSendRecvCodec Send failed: %v protocol:%s\n",
121 // Check for ERROR frame
122 time
.Sleep(1e9
/ 8) // Wait one eigth
123 // Poll for adhoc ERROR from server
125 case vx
:= <-conn
.MessageData
:
126 t
.Fatalf("TestCodecSendRecvCodec Send Error: [%v] protocol:%s\n",
132 sbh
:= wh
.Add(HK_ID
, v
.sid
)
133 //log.Printf("Subscribe Headers: %v\n", sbh)
134 sc
, e
= conn
.Subscribe(sbh
)
136 t
.Fatalf("TestCodecSendRecvCodec Subscribe failed: %v protocol:%s\n",
140 t
.Fatalf("TestCodecSendRecvCodec Subscribe sub chan is nil protocol:%s\n",
144 checkReceivedMD(t
, conn
, sc
, "codec_test_"+p
) // Receive
146 b
:= md
.Message
.BodyString()
148 t
.Fatalf("TestCodecSendRecvCodec Receive expected: [%v] got: [%v] protocol:%s\n",
152 //log.Printf("Unsubscribe Headers: %v\n", sbh)
153 e
= conn
.Unsubscribe(sbh
)
155 t
.Fatalf("TestCodecSendRecvCodec Unsubscribe failed: %v protocol:%s\n",
159 log
.Printf("Receive Headers: %v\n", md
.Message
.Headers
)
160 log
.Printf("Check map: %v\n", v
.rv
)
161 for key
, value
:= range v
.rv
{
162 log
.Printf("Want Key: [%v] Value: [%v] \n", key
, value
)
163 hv
, ok
= md
.Message
.Headers
.Contains(key
)
165 t
.Fatalf("TestCodecSendRecvCodec Header key expected: [%v] got: [%v] protocol:%s\n",
169 t
.Fatalf("TestCodecSendRecvCodec Header value expected: [%v] got: [%v] protocol:%s\n",
174 checkReceived(t
, conn
, false)
175 e
= conn
.Disconnect(empty_headers
)
176 checkDisconnectError(t
, e
)