2 // Copyright © 2011-2017 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.
24 Test transaction errors.
26 func TestTransErrors(t
*testing
.T
) {
27 for pi
, sp
:= range Protocols() {
30 ch
= headersProtocol(ch
, sp
)
31 conn
, e
= Connect(n
, ch
)
33 t
.Fatalf("TestTransErrors[%d/%s] CONNECT expected OK, got: %v\n", pi
,
36 for ti
, tv
:= range transBasicList
{
41 e
= conn
.Commit(tv
.th
)
45 t
.Fatalf("TestTransErrors[%d/%s] %s BAD DATA[%d]\n", pi
,
49 t
.Fatalf("TestTransErrors[%d/%s] %s expected error[%d], got %v\n", pi
,
53 t
.Fatalf("TestTransErrors[%d/%s] %s expected[%d]: %v, got %v\n", pi
,
54 sp
, tv
.action
, ti
, tv
.te
, e
)
57 checkReceived(t
, conn
)
58 e
= conn
.Disconnect(empty_headers
)
59 checkDisconnectError(t
, e
)
65 Test transaction send and commit.
67 func TestTransSendCommit(t
*testing
.T
) {
69 for pi
, sp
:= range Protocols() {
72 ch
= headersProtocol(ch
, sp
)
73 conn
, _
= Connect(n
, ch
)
75 t
.Fatalf("TestTransSendCommit[%d/%s] CONNECT expected OK, got: %v\n",
80 for ti
, tv
:= range transSendCommitList
{
82 e
= conn
.Begin(Headers
{HK_TRANSACTION
, tv
.tid
})
84 t
.Fatalf("TestTransSendCommit BEGIN[%d][%d] expected [%v], got: [%v]\n",
88 sh
:= Headers
{HK_DESTINATION
, tdest("/queue/" + tv
.tid
+ ".1"),
89 HK_TRANSACTION
, tv
.tid
}
92 t
.Fatalf("TestTransSendCommit SEND[%d][%d] expected [%v], got: [%v]\n",
96 e
= conn
.Commit(Headers
{HK_TRANSACTION
, tv
.tid
})
98 t
.Fatalf("TestTransSendCommit COMMIT[%d][%d] expected [%v], got: [%v]\n",
103 checkReceived(t
, conn
)
104 e
= conn
.Disconnect(empty_headers
)
105 checkDisconnectError(t
, e
)
111 Test transaction send then abort.
114 func TestTransSendAbort(t
*testing
.T
) {
116 for pi
, sp
:= range Protocols() {
119 ch
= headersProtocol(ch
, sp
)
120 conn
, _
= Connect(n
, ch
)
122 t
.Fatalf("TestTransSendAbort[%d/%s] CONNECT expected OK, got: %v\n",
126 for ti
, tv
:= range transSendAbortList
{
128 e
= conn
.Begin(Headers
{HK_TRANSACTION
, tv
.tid
})
130 t
.Fatalf("TestTransSendAbort BEGIN[%d][%d] expected [%v], got: [%v]\n",
134 sh
:= Headers
{HK_DESTINATION
, tdest("/queue/" + tv
.tid
+ ".1"),
135 HK_TRANSACTION
, tv
.tid
}
136 e
= conn
.Send(sh
, tm
)
138 t
.Fatalf("TestTransSendAbort SEND[%d][%d] expected [%v], got: [%v]\n",
142 e
= conn
.Abort(Headers
{HK_TRANSACTION
, tv
.tid
})
144 t
.Fatalf("TestTransSendAbort COMMIT[%d][%d] expected [%v], got: [%v]\n",
149 checkReceived(t
, conn
)
150 e
= conn
.Disconnect(empty_headers
)
151 checkDisconnectError(t
, e
)