blob: 6542fac584d0ec6205bab22b2c2e7f13862b6441 [file] [log] [blame]
taozlec0d384a2017-07-17 18:40:42 +02001// +build !go1.7
2
Jens Geyer5f9bdff2014-11-18 21:57:03 +01003/*
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * 'License'); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
19 * under the License.
20 */
21
22package tests
23
24import (
25 "errors"
26 "thrift"
27 "thrifttest"
28 "time"
taozlec0d384a2017-07-17 18:40:42 +020029
30 "golang.org/x/net/context"
Jens Geyer5f9bdff2014-11-18 21:57:03 +010031)
32
33type SecondServiceHandler struct {
34}
35
36func NewSecondServiceHandler() *SecondServiceHandler {
37 return &SecondServiceHandler{}
38}
39
taozlec0d384a2017-07-17 18:40:42 +020040func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010041 return nil
42}
43
taozlec0d384a2017-07-17 18:40:42 +020044func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010045 return thing, nil
46}
47
48type ThriftTestHandler struct {
49}
50
51func NewThriftTestHandler() *ThriftTestHandler {
52 return &ThriftTestHandler{}
53}
54
taozlec0d384a2017-07-17 18:40:42 +020055func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010056 return nil
57}
58
taozlec0d384a2017-07-17 18:40:42 +020059func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010060 return thing, nil
61}
62
taozlec0d384a2017-07-17 18:40:42 +020063func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
Nobuaki Sukegawaa649e742015-09-21 13:53:25 +090064 return thing, nil
65}
66
taozlec0d384a2017-07-17 18:40:42 +020067func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010068 return thing, nil
69}
70
taozlec0d384a2017-07-17 18:40:42 +020071func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010072 return thing, nil
73}
74
taozlec0d384a2017-07-17 18:40:42 +020075func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010076 return thing, nil
77}
78
taozlec0d384a2017-07-17 18:40:42 +020079func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010080 return thing, nil
81}
82
taozlec0d384a2017-07-17 18:40:42 +020083func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
Jens Geyer8bcfdd92014-12-14 03:14:26 +010084 return thing, nil
85}
86
taozlec0d384a2017-07-17 18:40:42 +020087func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010088 return thing, nil
89}
90
taozlec0d384a2017-07-17 18:40:42 +020091func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010092 return thing, nil
93}
94
taozlec0d384a2017-07-17 18:40:42 +020095func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +010096 return thing, nil
97}
98
taozlec0d384a2017-07-17 18:40:42 +020099func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100100 return thing, nil
101}
102
taozlec0d384a2017-07-17 18:40:42 +0200103func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100104 return thing, nil
105}
106
taozlec0d384a2017-07-17 18:40:42 +0200107func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100108 return thing, nil
109}
110
taozlec0d384a2017-07-17 18:40:42 +0200111func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100112 return thing, nil
113}
114
taozlec0d384a2017-07-17 18:40:42 +0200115func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100116 return thing, nil
117}
118
taozlec0d384a2017-07-17 18:40:42 +0200119func (p *ThriftTestHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100120 r = make(map[int32]map[int32]int32)
121 pos := make(map[int32]int32)
122 neg := make(map[int32]int32)
123
124 for i := int32(1); i < 5; i++ {
125 pos[i] = i
126 neg[-i] = -i
127 }
128 r[4] = pos
129 r[-4] = neg
130
131 return r, nil
132}
133
taozlec0d384a2017-07-17 18:40:42 +0200134func (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 +0100135 hello := thrifttest.NewXtruct()
136 hello.StringThing = "Hello2"
137 hello.ByteThing = 2
138 hello.I32Thing = 2
139 hello.I64Thing = 2
140
141 goodbye := thrifttest.NewXtruct()
142 goodbye.StringThing = "Goodbye4"
143 goodbye.ByteThing = 4
144 goodbye.I32Thing = 4
145 goodbye.I64Thing = 4
146
147 crazy := thrifttest.NewInsanity()
148 crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
149 crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
150 crazy.UserMap[thrifttest.Numberz_FIVE] = 5
151 crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
152
153 first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
154 second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
155
156 first_map[thrifttest.Numberz_TWO] = crazy
157 first_map[thrifttest.Numberz_THREE] = crazy
158
159 looney := thrifttest.NewInsanity()
160 second_map[thrifttest.Numberz_SIX] = looney
161
162 var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
163 insane[1] = first_map
164 insane[2] = second_map
165
166 return insane, nil
167}
168
taozlec0d384a2017-07-17 18:40:42 +0200169func (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 +0100170 r = thrifttest.NewXtruct()
171 r.StringThing = "Hello2"
172 r.ByteThing = arg0
173 r.I32Thing = arg1
174 r.I64Thing = arg2
175 return r, nil
176}
177
taozlec0d384a2017-07-17 18:40:42 +0200178func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100179 if arg == "Xception" {
180 x := thrifttest.NewXception()
181 x.ErrorCode = 1001
182 x.Message = arg
183 return x
184 } else if arg == "TException" {
185 return thrift.TException(errors.New(arg))
186 } else {
187 return nil
188 }
189}
190
taozlec0d384a2017-07-17 18:40:42 +0200191func (p *ThriftTestHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100192 if arg0 == "Xception" {
193 x := thrifttest.NewXception()
194 x.ErrorCode = 1001
195 x.Message = "This is an Xception"
196 return nil, x
197 } else if arg0 == "Xception2" {
198 x2 := thrifttest.NewXception2()
199 x2.ErrorCode = 2002
200 x2.StructThing = thrifttest.NewXtruct()
201 x2.StructThing.StringThing = "This is an Xception2"
202 return nil, x2
203 }
204
205 res := thrifttest.NewXtruct()
206 res.StringThing = arg1
207 return res, nil
208}
209
taozlec0d384a2017-07-17 18:40:42 +0200210func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
Jens Geyer5f9bdff2014-11-18 21:57:03 +0100211 time.Sleep(time.Second * time.Duration(secondsToSleep))
212 return nil
213}