blob: 50fe7184f2bb5d6eb7862bc3730ad050fb480560 [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 (
23 "errors"
24 "thrift"
25 "thrifttest"
26 "time"
27)
28
29type SecondServiceHandler struct {
30}
31
32func NewSecondServiceHandler() *SecondServiceHandler {
33 return &SecondServiceHandler{}
34}
35
36func (p *SecondServiceHandler) BlahBlah() (err error) {
37 return nil
38}
39
40func (p *SecondServiceHandler) SecondtestString(thing string) (r string, err error) {
41 return thing, nil
42}
43
44type ThriftTestHandler struct {
45}
46
47func NewThriftTestHandler() *ThriftTestHandler {
48 return &ThriftTestHandler{}
49}
50
51func (p *ThriftTestHandler) TestVoid() (err error) {
52 return nil
53}
54
55func (p *ThriftTestHandler) TestString(thing string) (r string, err error) {
56 return thing, nil
57}
58
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090059func (p *ThriftTestHandler) TestBool(thing bool) (r bool, err error) {
60 return thing, nil
61}
62
Jens Geyer5f9bdff2014-11-18 21:57:03 +010063func (p *ThriftTestHandler) TestByte(thing int8) (r int8, err error) {
64 return thing, nil
65}
66
67func (p *ThriftTestHandler) TestI32(thing int32) (r int32, err error) {
68 return thing, nil
69}
70
71func (p *ThriftTestHandler) TestI64(thing int64) (r int64, err error) {
72 return thing, nil
73}
74
75func (p *ThriftTestHandler) TestDouble(thing float64) (r float64, err error) {
76 return thing, nil
77}
78
Jens Geyer8bcfdd92014-12-14 03:14:26 +010079func (p *ThriftTestHandler) TestBinary(thing []byte) (r []byte, err error) {
80 return thing, nil
81}
82
Jens Geyer5f9bdff2014-11-18 21:57:03 +010083func (p *ThriftTestHandler) TestStruct(thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
84 return thing, nil
85}
86
87func (p *ThriftTestHandler) TestNest(thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
88 return thing, nil
89}
90
91func (p *ThriftTestHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
92 return thing, nil
93}
94
95func (p *ThriftTestHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
96 return thing, nil
97}
98
99func (p *ThriftTestHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) {
100 return thing, nil
101}
102
103func (p *ThriftTestHandler) TestList(thing []int32) (r []int32, err error) {
104 return thing, nil
105}
106
107func (p *ThriftTestHandler) TestEnum(thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
108 return thing, nil
109}
110
111func (p *ThriftTestHandler) TestTypedef(thing thrifttest.UserId) (r thrifttest.UserId, err error) {
112 return thing, nil
113}
114
115func (p *ThriftTestHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
116 r = make(map[int32]map[int32]int32)
117 pos := make(map[int32]int32)
118 neg := make(map[int32]int32)
119
120 for i := int32(1); i < 5; i++ {
121 pos[i] = i
122 neg[-i] = -i
123 }
124 r[4] = pos
125 r[-4] = neg
126
127 return r, nil
128}
129
130func (p *ThriftTestHandler) TestInsanity(argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
131 hello := thrifttest.NewXtruct()
132 hello.StringThing = "Hello2"
133 hello.ByteThing = 2
134 hello.I32Thing = 2
135 hello.I64Thing = 2
136
137 goodbye := thrifttest.NewXtruct()
138 goodbye.StringThing = "Goodbye4"
139 goodbye.ByteThing = 4
140 goodbye.I32Thing = 4
141 goodbye.I64Thing = 4
142
143 crazy := thrifttest.NewInsanity()
144 crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
145 crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
146 crazy.UserMap[thrifttest.Numberz_FIVE] = 5
147 crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
148
149 first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
150 second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
151
152 first_map[thrifttest.Numberz_TWO] = crazy
153 first_map[thrifttest.Numberz_THREE] = crazy
154
155 looney := thrifttest.NewInsanity()
156 second_map[thrifttest.Numberz_SIX] = looney
157
158 var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
159 insane[1] = first_map
160 insane[2] = second_map
161
162 return insane, nil
163}
164
165func (p *ThriftTestHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 thrifttest.Numberz, arg5 thrifttest.UserId) (r *thrifttest.Xtruct, err error) {
166 r = thrifttest.NewXtruct()
167 r.StringThing = "Hello2"
168 r.ByteThing = arg0
169 r.I32Thing = arg1
170 r.I64Thing = arg2
171 return r, nil
172}
173
174func (p *ThriftTestHandler) TestException(arg string) (err error) {
175 if arg == "Xception" {
176 x := thrifttest.NewXception()
177 x.ErrorCode = 1001
178 x.Message = arg
179 return x
180 } else if arg == "TException" {
181 return thrift.TException(errors.New(arg))
182 } else {
183 return nil
184 }
185}
186
187func (p *ThriftTestHandler) TestMultiException(arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
188 if arg0 == "Xception" {
189 x := thrifttest.NewXception()
190 x.ErrorCode = 1001
191 x.Message = "This is an Xception"
192 return nil, x
193 } else if arg0 == "Xception2" {
194 x2 := thrifttest.NewXception2()
195 x2.ErrorCode = 2002
196 x2.StructThing = thrifttest.NewXtruct()
197 x2.StructThing.StringThing = "This is an Xception2"
198 return nil, x2
199 }
200
201 res := thrifttest.NewXtruct()
202 res.StringThing = arg1
203 return res, nil
204}
205
206func (p *ThriftTestHandler) TestOneway(secondsToSleep int32) (err error) {
207 time.Sleep(time.Second * time.Duration(secondsToSleep))
208 return nil
209}