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.
25 Test transaction errors.
27 func TestTransErrors(t
*testing
.T
) {
28 for pi
, sp
:= range Protocols() {
31 ch
= headersProtocol(ch
, sp
)
32 conn
, e
= Connect(n
, ch
)
34 t
.Fatalf("TestTransErrors[%d/%s] CONNECT expected OK, got: %v\n", pi
,
37 for ti
, tv
:= range transBasicList
{
42 e
= conn
.Commit(tv
.th
)
46 t
.Fatalf("TestTransErrors[%d/%s] %s BAD DATA[%d]\n", pi
,
50 t
.Fatalf("TestTransErrors[%d/%s] %s expected error[%d], got %v\n", pi
,
54 t
.Fatalf("TestTransErrors[%d/%s] %s expected[%d]: %v, got %v\n", pi
,
55 sp
, tv
.action
, ti
, tv
.te
, e
)
58 checkReceived(t
, conn
, false)
59 e
= conn
.Disconnect(empty_headers
)
60 checkDisconnectError(t
, e
)
66 Test transaction send and commit.
68 func TestTransSendCommit(t
*testing
.T
) {
70 for pi
, sp
:= range Protocols() {
73 ch
= headersProtocol(ch
, sp
)
74 conn
, _
= Connect(n
, ch
)
76 t
.Fatalf("TestTransSendCommit[%d/%s] CONNECT expected OK, got: %v\n",
81 for ti
, tv
:= range transSendCommitList
{
83 e
= conn
.Begin(Headers
{HK_TRANSACTION
, tv
.tid
})
85 t
.Fatalf("TestTransSendCommit BEGIN[%d][%d] expected [%v], got: [%v]\n",
89 qn
:= tdest("/queue/" + tv
.tid
+ ".1")
90 log
.Println("TSCQN:", qn
)
91 sh
:= Headers
{HK_DESTINATION
, qn
,
92 HK_TRANSACTION
, tv
.tid
}
95 t
.Fatalf("TestTransSendCommit SEND[%d][%d] expected [%v], got: [%v]\n",
99 e
= conn
.Commit(Headers
{HK_TRANSACTION
, tv
.tid
})
101 t
.Fatalf("TestTransSendCommit COMMIT[%d][%d] expected [%v], got: [%v]\n",
106 checkReceived(t
, conn
, false)
107 e
= conn
.Disconnect(empty_headers
)
108 checkDisconnectError(t
, e
)
114 Test transaction send then abort.
117 func TestTransSendAbort(t
*testing
.T
) {
119 for pi
, sp
:= range Protocols() {
122 ch
= headersProtocol(ch
, sp
)
123 conn
, _
= Connect(n
, ch
)
125 t
.Fatalf("TestTransSendAbort[%d/%s] CONNECT expected OK, got: %v\n",
129 for ti
, tv
:= range transSendAbortList
{
131 e
= conn
.Begin(Headers
{HK_TRANSACTION
, tv
.tid
})
133 t
.Fatalf("TestTransSendAbort BEGIN[%d][%d] expected [%v], got: [%v]\n",
137 sh
:= Headers
{HK_DESTINATION
, tdest("/queue/" + tv
.tid
+ ".1"),
138 HK_TRANSACTION
, tv
.tid
}
139 e
= conn
.Send(sh
, tm
)
141 t
.Fatalf("TestTransSendAbort SEND[%d][%d] expected [%v], got: [%v]\n",
145 e
= conn
.Abort(Headers
{HK_TRANSACTION
, tv
.tid
})
147 t
.Fatalf("TestTransSendAbort COMMIT[%d][%d] expected [%v], got: [%v]\n",
152 checkReceived(t
, conn
, false)
153 e
= conn
.Disconnect(empty_headers
)
154 checkDisconnectError(t
, e
)