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