blob: f46f5495da064048a308c3e9bbef837dce31b741 [file] [log] [blame]
Jens Geyer5f9bdff2014-11-18 21:57:03 +01001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * 'License'); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20package tests
21
22import (
John Boiles57852792018-01-05 14:37:05 -080023 "context"
Jens Geyer5f9bdff2014-11-18 21:57:03 +010024 "errors"
Jens Geyer5f9bdff2014-11-18 21:57:03 +010025 "time"
Yuxuan 'fishy' Wangb71f11e2021-03-22 15:01:00 -070026
27 "github.com/apache/thrift/lib/go/test/gopath/src/thrifttest"
28 "github.com/apache/thrift/lib/go/thrift"
Jens Geyer5f9bdff2014-11-18 21:57:03 +010029)
30
31type SecondServiceHandler struct {
32}
33
34func NewSecondServiceHandler() *SecondServiceHandler {
35 return &SecondServiceHandler{}
36}
37
taozlec0d384a2017-07-17 18:40:42 +020038func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010039 return nil
40}
41
taozlec0d384a2017-07-17 18:40:42 +020042func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010043 return thing, nil
44}
45
46type ThriftTestHandler struct {
47}
48
49func NewThriftTestHandler() *ThriftTestHandler {
50 return &ThriftTestHandler{}
51}
52
taozlec0d384a2017-07-17 18:40:42 +020053func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010054 return nil
55}
56
taozlec0d384a2017-07-17 18:40:42 +020057func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010058 return thing, nil
59}
60
taozlec0d384a2017-07-17 18:40:42 +020061func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090062 return thing, nil
63}
64
taozlec0d384a2017-07-17 18:40:42 +020065func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010066 return thing, nil
67}
68
taozlec0d384a2017-07-17 18:40:42 +020069func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010070 return thing, nil
71}
72
taozlec0d384a2017-07-17 18:40:42 +020073func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010074 return thing, nil
75}
76
taozlec0d384a2017-07-17 18:40:42 +020077func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010078 return thing, nil
79}
80
taozlec0d384a2017-07-17 18:40:42 +020081func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
Jens Geyer8bcfdd92014-12-14 03:14:26 +010082 return thing, nil
83}
84
Yuxuan 'fishy' Wange8353cb2022-10-28 10:29:25 -070085func (p *ThriftTestHandler) TestUuid(ctx context.Context, thing thrift.Tuuid) (r thrift.Tuuid, err error) {
86 return thing, nil
87}
88
taozlec0d384a2017-07-17 18:40:42 +020089func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010090 return thing, nil
91}
92
taozlec0d384a2017-07-17 18:40:42 +020093func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010094 return thing, nil
95}
96
taozlec0d384a2017-07-17 18:40:42 +020097func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010098 return thing, nil
99}
100
taozlec0d384a2017-07-17 18:40:42 +0200101func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100102 return thing, nil
103}
104
taozlec0d384a2017-07-17 18:40:42 +0200105func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100106 return thing, nil
107}
108
taozlec0d384a2017-07-17 18:40:42 +0200109func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100110 return thing, nil
111}
112
taozlec0d384a2017-07-17 18:40:42 +0200113func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100114 return thing, nil
115}
116
taozlec0d384a2017-07-17 18:40:42 +0200117func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100118 return thing, nil
119}
120
taozlec0d384a2017-07-17 18:40:42 +0200121func (p *ThriftTestHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100122 r = make(map[int32]map[int32]int32)
123 pos := make(map[int32]int32)
124 neg := make(map[int32]int32)
125
126 for i := int32(1); i < 5; i++ {
127 pos[i] = i
128 neg[-i] = -i
129 }
130 r[4] = pos
131 r[-4] = neg
132
133 return r, nil
134}
135
taozlec0d384a2017-07-17 18:40:42 +0200136func (p *ThriftTestHandler) TestInsanity(ctx context.Context, argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100137 hello := thrifttest.NewXtruct()
138 hello.StringThing = "Hello2"
139 hello.ByteThing = 2
140 hello.I32Thing = 2
141 hello.I64Thing = 2
142
143 goodbye := thrifttest.NewXtruct()
144 goodbye.StringThing = "Goodbye4"
145 goodbye.ByteThing = 4
146 goodbye.I32Thing = 4
147 goodbye.I64Thing = 4
148
149 crazy := thrifttest.NewInsanity()
150 crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
151 crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
152 crazy.UserMap[thrifttest.Numberz_FIVE] = 5
153 crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
154
155 first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
156 second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
157
158 first_map[thrifttest.Numberz_TWO] = crazy
159 first_map[thrifttest.Numberz_THREE] = crazy
160
161 looney := thrifttest.NewInsanity()
162 second_map[thrifttest.Numberz_SIX] = looney
163
164 var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
165 insane[1] = first_map
166 insane[2] = second_map
167
168 return insane, nil
169}
170
taozlec0d384a2017-07-17 18:40:42 +0200171func (p *ThriftTestHandler) TestMulti(ctx context.Context, arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 thrifttest.Numberz, arg5 thrifttest.UserId) (r *thrifttest.Xtruct, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100172 r = thrifttest.NewXtruct()
173 r.StringThing = "Hello2"
174 r.ByteThing = arg0
175 r.I32Thing = arg1
176 r.I64Thing = arg2
177 return r, nil
178}
179
taozlec0d384a2017-07-17 18:40:42 +0200180func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100181 if arg == "Xception" {
182 x := thrifttest.NewXception()
183 x.ErrorCode = 1001
184 x.Message = arg
185 return x
186 } else if arg == "TException" {
Yuxuan 'fishy' Wangd8312302020-12-22 09:53:58 -0800187 return thrift.WrapTException(errors.New(arg))
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100188 } else {
189 return nil
190 }
191}
192
taozlec0d384a2017-07-17 18:40:42 +0200193func (p *ThriftTestHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100194 if arg0 == "Xception" {
195 x := thrifttest.NewXception()
196 x.ErrorCode = 1001
197 x.Message = "This is an Xception"
198 return nil, x
199 } else if arg0 == "Xception2" {
200 x2 := thrifttest.NewXception2()
201 x2.ErrorCode = 2002
202 x2.StructThing = thrifttest.NewXtruct()
203 x2.StructThing.StringThing = "This is an Xception2"
204 return nil, x2
205 }
206
207 res := thrifttest.NewXtruct()
208 res.StringThing = arg1
209 return res, nil
210}
211
taozlec0d384a2017-07-17 18:40:42 +0200212func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100213 time.Sleep(time.Second * time.Duration(secondsToSleep))
214 return nil
215}