Removing unecessary files from Thrift Vendor folder.

This commit is contained in:
Renan DelValle 2019-02-13 12:53:27 -08:00
parent 0737ab34b1
commit 973e5e86dd
No known key found for this signature in database
GPG key ID: C240AD6D6F443EC9
42 changed files with 0 additions and 4001 deletions

View file

@ -1,45 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
SUBDIRS = .
if WITH_TESTS
SUBDIRS += test
endif
install:
@echo '##############################################################'
@echo '##############################################################'
@echo 'The Go client library should be installed via "go get", please see /lib/go/README.md'
@echo '##############################################################'
@echo '##############################################################'
check-local:
GOPATH=`pwd` $(GO) test -race ./thrift
clean-local:
$(RM) -rf pkg
all-local:
GOPATH=`pwd` $(GO) build ./thrift
EXTRA_DIST = \
thrift \
coding_standards.md \
README.md

View file

@ -1,83 +0,0 @@
Thrift Go Software Library
License
=======
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Using Thrift with Go
====================
Thrift supports Go 1.7+
In following Go conventions, we recommend you use the 'go' tool to install
Thrift for go.
$ go get github.com/apache/thrift/lib/go/thrift/...
Will retrieve and install the most recent version of the package.
A note about optional fields
============================
The thrift-to-Go compiler tries to represent thrift IDL structs as Go structs.
We must be able to distinguish between optional fields that are set to their
default value and optional values which are actually unset, so the generated
code represents optional fields via pointers.
This is generally intuitive and works well much of the time, but Go does not
have a syntax for creating a pointer to a constant in a single expression. That
is, given a struct like
struct SomeIDLType {
OptionalField *int32
}
, the following will not compile:
x := &SomeIDLType{
OptionalField: &(3),
}
(Nor is there any other syntax that's built in to the language)
As such, we provide some helpers that do just this under lib/go/thrift/. E.g.,
x := &SomeIDLType{
OptionalField: thrift.Int32Ptr(3),
}
And so on. The code generator also creates analogous helpers for user-defined
typedefs and enums.
Adding custom tags to generated Thrift structs
==============================================
You can add tags to the auto-generated thrift structs using the following format:
struct foo {
1: required string Bar (go.tag = "some_tag:\"some_tag_value\"")
}
which will generate:
type Foo struct {
Bar string `thrift:"bar,1,required" some_tag:"some_tag_value"`
}

View file

@ -1 +0,0 @@
Please follow [General Coding Standards](/doc/coding_standards.md)

View file

@ -1,24 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# Make sure that thrift produce compilable code for binary key
struct testStruct {
1: required map<binary,string> bin_to_string
}

View file

@ -1,27 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct InnerStruct {
1: required string id
}
struct TestStruct {
1: required string id
2: required InnerStruct inner
}

View file

@ -1,35 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Contains some contributions under the Thrift Software License.
* Please see doc/old-thrift-license.txt in the Thrift distribution for
* details.
*/
struct TestStruct
{
1: map<string, string> m,
2: list<string> l,
3: set<string> s,
4: i32 i
}
service ErrorTest
{
TestStruct testStruct(1: TestStruct thing)
string testString(1: string s)
}

View file

@ -1,24 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct tagged {
1: string string_thing,
2: i64 int_thing (go.tag = "json:\"int_thing,string\""),
3: optional i64 optional_int_thing
}

View file

@ -1,26 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct IgnoreInitialismsTest {
1: i64 id,
2: i64 my_id,
3: i64 num_cpu,
4: i64 num_gpu,
5: i64 my_ID,
}

View file

@ -1,67 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
include "ThriftTest.thrift"
include "NamespacedTest.thrift"
const ThriftTest.UserId USERID = 42
const NamespacedTest.UserId USERID1 = 41
const ThriftTest.MapType MAPCONSTANT = {'hello':{}, 'goodnight':{}}
const i32 TWO = NamespacedTest.Stuff.TWO
const i32 THREE = NamespacedTest.THREE
struct testStruct {
1: list<ThriftTest.Numberz> listNumbers
}
struct TestStruct2 {
1: testStruct blah,
2: ThriftTest.UserId id,
3: NamespacedTest.Stuff stuff,
}
service testService extends ThriftTest.SecondService {
ThriftTest.CrazyNesting getCrazyNesting(
1: ThriftTest.StructA a,
2: ThriftTest.Numberz numbers
) throws(1: ThriftTest.Xception err1),
void getSomeValue_DO_NOT_CALL(),
}
service ExtendedService extends testService {
void extendedMethod(),
NamespacedTest.StuffStruct extendedMethod2(),
}
service Extended2Service extends NamespacedTest.NamespacedService {
void extendedMethod3(),
}
typedef map<ThriftTest.UserId, map<NamespacedTest.UserId, list<TestStruct2> > > ComplexMapType
struct ComplexMapStruct {
1: ComplexMapType complex,
}
service ComplexMapService {
ComplexMapStruct transformMap(1: ComplexMapStruct input),
}

View file

@ -1,24 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct InitialismsTest {
1: string user_id,
2: string server_url,
3: string id,
}

View file

@ -1,111 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift$(COMPILER_EXTRAFLAG)
THRIFTTEST = $(top_srcdir)/test/ThriftTest.thrift
# Thrift for GO has problems with complex map keys: THRIFT-2063
gopath: $(THRIFT) $(THRIFTTEST) \
IncludesTest.thrift \
NamespacedTest.thrift \
MultiplexedProtocolTest.thrift \
OnewayTest.thrift \
OptionalFieldsTest.thrift \
RequiredFieldTest.thrift \
ServicesTest.thrift \
GoTagTest.thrift \
TypedefFieldTest.thrift \
RefAnnotationFieldsTest.thrift \
UnionDefaultValueTest.thrift \
UnionBinaryTest.thrift \
ErrorTest.thrift \
NamesTest.thrift \
InitialismsTest.thrift \
DontExportRWTest.thrift \
dontexportrwtest/compile_test.go \
IgnoreInitialismsTest.thrift
mkdir -p gopath/src
grep -v list.*map.*list.*map $(THRIFTTEST) | grep -v 'set<Insanity>' > ThriftTest.thrift
$(THRIFT) $(THRIFTARGS) -r IncludesTest.thrift
$(THRIFT) $(THRIFTARGS) BinaryKeyTest.thrift
$(THRIFT) $(THRIFTARGS) MultiplexedProtocolTest.thrift
$(THRIFT) $(THRIFTARGS) OnewayTest.thrift
$(THRIFT) $(THRIFTARGS) OptionalFieldsTest.thrift
$(THRIFT) $(THRIFTARGS) RequiredFieldTest.thrift
$(THRIFT) $(THRIFTARGS) ServicesTest.thrift
$(THRIFT) $(THRIFTARGS) GoTagTest.thrift
$(THRIFT) $(THRIFTARGS) TypedefFieldTest.thrift
$(THRIFT) $(THRIFTARGS) RefAnnotationFieldsTest.thrift
$(THRIFT) $(THRIFTARGS) UnionDefaultValueTest.thrift
$(THRIFT) $(THRIFTARGS) UnionBinaryTest.thrift
$(THRIFT) $(THRIFTARGS) ErrorTest.thrift
$(THRIFT) $(THRIFTARGS) NamesTest.thrift
$(THRIFT) $(THRIFTARGS) InitialismsTest.thrift
$(THRIFT) $(THRIFTARGS),read_write_private DontExportRWTest.thrift
$(THRIFT) $(THRIFTARGS),ignore_initialisms IgnoreInitialismsTest.thrift
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock || true
sed -i 's/\"context\"/\"golang.org\/x\/net\/context\"/g' gopath/src/github.com/golang/mock/gomock/controller.go || true
GOPATH=`pwd`/gopath $(GO) get github.com/golang/mock/gomock
ln -nfs ../../../thrift gopath/src/thrift
ln -nfs ../../tests gopath/src/tests
cp -r ./dontexportrwtest gopath/src
touch gopath
check: gopath
GOPATH=`pwd`/gopath $(GO) build \
includestest \
binarykeytest \
servicestest \
typedeffieldtest \
refannotationfieldstest \
errortest \
namestest \
initialismstest \
dontexportrwtest \
ignoreinitialismstest \
unionbinarytest
GOPATH=`pwd`/gopath $(GO) test thrift tests dontexportrwtest
clean-local:
$(RM) -r gopath ThriftTest.thrift gen-go
client: stubs
$(GO) run TestClient.go
EXTRA_DIST = \
dontexportrwtest \
tests \
BinaryKeyTest.thrift \
GoTagTest.thrift \
IncludesTest.thrift \
MultiplexedProtocolTest.thrift \
NamespacedTest.thrift \
OnewayTest.thrift \
OptionalFieldsTest.thrift \
RequiredFieldTest.thrift \
RefAnnotationFieldsTest.thrift \
UnionDefaultValueTest.thrift \
UnionBinaryTest.thrift \
ServicesTest.thrift \
TypedefFieldTest.thrift \
ErrorTest.thrift \
NamesTest.thrift \
InitialismsTest.thrift \
DontExportRWTest.thrift \
IgnoreInitialismsTest.thrift

View file

@ -1,27 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
service First {
i64 returnOne();
}
service Second {
i64 returnTwo();
}

View file

@ -1,32 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct NamesTest {
1: required string type
}
service NameCollisionOne
{
void blahBlah()
}
service NameCollisionTwo
{
void blahBlah()
}

View file

@ -1,40 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
include "ThriftTest.thrift"
namespace go lib.go.test.namespacedtest
enum Stuff {
ONE = 1,
TWO = 2,
}
const i32 THREE = 3;
typedef i64 UserId
struct StuffStruct {
2: Stuff stuff,
}
service NamespacedService {
ThriftTest.UserId getUserID(),
}

View file

@ -1,24 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
service OneWay {
oneway void hi(1: i64 i, 2: string s)
void emptyfunc()
i64 echo_int(1: i64 param)
}

View file

@ -1,50 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct structA {
1: required i64 sa_i
}
struct all_optional {
1: optional string s = "DEFAULT",
2: optional i64 i = 42,
3: optional bool b = false,
4: optional string s2,
5: optional i64 i2,
6: optional bool b2,
7: optional structA aa,
9: optional list<i64> l,
10: optional list<i64> l2 = [1, 2],
11: optional map<i64, i64> m,
12: optional map<i64, i64> m2 = {1:2, 3:4},
13: optional binary bin,
14: optional binary bin2 = "asdf",
}
struct structB {
1: required structA required_struct_thing
2: optional structA optional_struct_thing
}
struct structC {
1: string s,
2: required i32 i,
3: optional bool b,
4: required string s2,
}

View file

@ -1,58 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct structA {
1: required i64 sa_i
}
struct all_referenced {
1: optional string s = "DEFAULT" (cpp.ref = ""),
2: optional i64 i = 42 (cpp.ref = ""),
3: optional bool b = false (cpp.ref = ""),
4: optional string s2 (cpp.ref = ""),
5: optional i64 i2 (cpp.ref = ""),
6: optional bool b2 (cpp.ref = ""),
7: optional structA aa (cpp.ref = ""),
9: optional list<i64> l (cpp.ref = ""),
10: optional list<i64> l2 = [1, 2] (cpp.ref = ""),
11: optional map<i64, i64> m (cpp.ref = ""),
12: optional map<i64, i64> m2 = {1:2, 3:4} (cpp.ref = ""),
13: optional binary bin (cpp.ref = ""),
14: optional binary bin2 = "asdf" (cpp.ref = ""),
15: required string ref_s = "DEFAULT" (cpp.ref = ""),
16: required i64 ref_i = 42 (cpp.ref = ""),
17: required bool ref_b = false (cpp.ref = ""),
18: required string ref_s2 (cpp.ref = ""),
19: required i64 ref_i2 (cpp.ref = ""),
20: required bool ref_b2 (cpp.ref = ""),
21: required structA ref_aa (cpp.ref = ""),
22: required list<i64> ref_l (cpp.ref = ""),
23: required list<i64> ref_l2 = [1, 2] (cpp.ref = ""),
24: required map<i64, i64> ref_m (cpp.ref = ""),
25: required map<i64, i64> ref_m2 = {1:2, 3:4} (cpp.ref = ""),
26: required binary ref_bin (cpp.ref = ""),
27: required binary ref_bin2 = "asdf" (cpp.ref = ""),
}
struct structB {
1: required structA required_struct_thing
2: optional structA optional_struct_thing
}

View file

@ -1,7 +0,0 @@
struct RequiredField {
1: required string name
}
struct OtherThing {
1: required i16 value
}

View file

@ -1,111 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# We are only testing that generated code compiles, no correctness checking is done
exception moderate_disaster {
1: i32 errorCode,
2: string message
}
exception total_disaster {
1: string message
2: optional bool president_was_woken_up = false
}
struct struct_a {
1: required i64 whatever
}
service a_serv {
void voidfunc(),
void void_with_1ex() throws(1: moderate_disaster err1)
void void_with_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
string stringfunc()
string stringfunc_1ex() throws(1: moderate_disaster err1)
string stringfunc_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
i64 i64func()
i64 i64func_1ex() throws(1: moderate_disaster err1)
i64 i64func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
list<string> list_of_strings_func()
list<string> list_of_strings_func_1ex() throws(1: moderate_disaster err1)
list<string> list_of_strings_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
map<i64,string> map_func()
map<i64,string> map_func_1ex() throws(1: moderate_disaster err1)
map<i64,string> map_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
struct_a struct_a_func()
struct_a struct_a_func_1ex() throws(1: moderate_disaster err1)
struct_a struct_a_func_2ex() throws(1: moderate_disaster err1, 2:total_disaster err2)
void voidfunc_1int(1: i64 i),
void void_with_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
void void_with_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
string stringfunc_1int(1: i64 i)
string stringfunc_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
string stringfunc_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
i64 i64func_1int(1: i64 i)
i64 i64func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
i64 i64func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
list<string> list_of_strings_func_1int(1: i64 i)
list<string> list_of_strings_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
list<string> list_of_strings_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
map<i64,string> map_func_1int(1: i64 i)
map<i64,string> map_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
map<i64,string> map_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
struct_a struct_a_func_1int(1: i64 i)
struct_a struct_a_func_1ex_1int(1: i64 i) throws(1: moderate_disaster err1)
struct_a struct_a_func_2ex_1int(1: i64 i) throws(1: moderate_disaster err1, 2:total_disaster err2)
void voidfunc_1int_1s(1: i64 i, 2: string s),
void void_with_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
void void_with_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
string stringfunc_1int_1s(1: i64 i, 2: string s)
string stringfunc_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
string stringfunc_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
i64 i64func_1int_1s(1: i64 i, 2: string s)
i64 i64func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
i64 i64func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
list<string> list_of_strings_func_1int_1s(1: i64 i, 2: string s)
list<string> list_of_strings_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
list<string> list_of_strings_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
map<i64,string> map_func_1int_1s(1: i64 i, 2: string s)
map<i64,string> map_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
map<i64,string> map_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
struct_a struct_a_func_1int_1s(1: i64 i, 2: string s)
struct_a struct_a_func_1ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1)
struct_a struct_a_func_2ex_1int_1s(1: i64 i, 2: string s) throws(1: moderate_disaster err1, 2:total_disaster err2)
struct_a struct_a_func_1struct_a(1: struct_a st)
}

View file

@ -1,39 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# We are only testing that generated code compiles, no correctness checking is done
enum Details {
Everything = 0
StateOnly = 1
StateAndOptions = 2
SomethingElse = 3
}
typedef list< Details> DetailsWanted
struct BaseRequest {
1 : optional string RequestID
}
struct GetMyDetails {
1 : required BaseRequest base_
2 : required string ObjectID
3 : optional DetailsWanted DetailsWanted
}

View file

@ -1,25 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
# See https://issues.apache.org/jira/browse/THRIFT-4573
union Sample {
1: map<string, string> u1,
2: binary u2,
3: list<string> u3
}

View file

@ -1,34 +0,0 @@
#
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
#
struct Option1 {
}
struct Option2 {
1: optional string name
}
union Descendant {
1: Option1 option1
2: Option2 option2
}
struct TestStruct {
1: optional Descendant descendant = { "option1": {}}
}

View file

@ -1,37 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package dontexportrwtest
import (
"testing"
)
// Make sure that thrift generates non-exported read/write methods if
// read_write_private option is specified
func TestReadWriteMethodsArePrivate(t *testing.T) {
// This will only compile if read/write methods exist
s := NewTestStruct()
_ = s.read
_ = s.write
is := NewInnerStruct()
_ = is.read
_ = is.write
}

View file

@ -1,31 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"binarykeytest"
"testing"
)
func TestBinaryMapKeyGeneratesString(t *testing.T) {
s := binarykeytest.NewTestStruct()
//This will only compile if BinToString has type of map[string]string
s.BinToString = make(map[string]string)
}

View file

@ -1,873 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
"errors"
"errortest"
"testing"
"thrift"
"github.com/golang/mock/gomock"
)
// TestCase: Comprehensive call and reply workflow in the client.
// Setup mock to fail at a certain position. Return true if position exists otherwise false.
func prepareClientCallReply(protocol *MockTProtocol, failAt int, failWith error) bool {
var err error = nil
if failAt == 0 {
err = failWith
}
last := protocol.EXPECT().WriteMessageBegin("testStruct", thrift.CALL, int32(1)).Return(err)
if failAt == 0 {
return true
}
if failAt == 1 {
err = failWith
}
last = protocol.EXPECT().WriteStructBegin("testStruct_args").Return(err).After(last)
if failAt == 1 {
return true
}
if failAt == 2 {
err = failWith
}
last = protocol.EXPECT().WriteFieldBegin("thing", thrift.TType(thrift.STRUCT), int16(1)).Return(err).After(last)
if failAt == 2 {
return true
}
if failAt == 3 {
err = failWith
}
last = protocol.EXPECT().WriteStructBegin("TestStruct").Return(err).After(last)
if failAt == 3 {
return true
}
if failAt == 4 {
err = failWith
}
last = protocol.EXPECT().WriteFieldBegin("m", thrift.TType(thrift.MAP), int16(1)).Return(err).After(last)
if failAt == 4 {
return true
}
if failAt == 5 {
err = failWith
}
last = protocol.EXPECT().WriteMapBegin(thrift.TType(thrift.STRING), thrift.TType(thrift.STRING), 0).Return(err).After(last)
if failAt == 5 {
return true
}
if failAt == 6 {
err = failWith
}
last = protocol.EXPECT().WriteMapEnd().Return(err).After(last)
if failAt == 6 {
return true
}
if failAt == 7 {
err = failWith
}
last = protocol.EXPECT().WriteFieldEnd().Return(err).After(last)
if failAt == 7 {
return true
}
if failAt == 8 {
err = failWith
}
last = protocol.EXPECT().WriteFieldBegin("l", thrift.TType(thrift.LIST), int16(2)).Return(err).After(last)
if failAt == 8 {
return true
}
if failAt == 9 {
err = failWith
}
last = protocol.EXPECT().WriteListBegin(thrift.TType(thrift.STRING), 0).Return(err).After(last)
if failAt == 9 {
return true
}
if failAt == 10 {
err = failWith
}
last = protocol.EXPECT().WriteListEnd().Return(err).After(last)
if failAt == 10 {
return true
}
if failAt == 11 {
err = failWith
}
last = protocol.EXPECT().WriteFieldEnd().Return(err).After(last)
if failAt == 11 {
return true
}
if failAt == 12 {
err = failWith
}
last = protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.SET), int16(3)).Return(err).After(last)
if failAt == 12 {
return true
}
if failAt == 13 {
err = failWith
}
last = protocol.EXPECT().WriteSetBegin(thrift.TType(thrift.STRING), 0).Return(err).After(last)
if failAt == 13 {
return true
}
if failAt == 14 {
err = failWith
}
last = protocol.EXPECT().WriteSetEnd().Return(err).After(last)
if failAt == 14 {
return true
}
if failAt == 15 {
err = failWith
}
last = protocol.EXPECT().WriteFieldEnd().Return(err).After(last)
if failAt == 15 {
return true
}
if failAt == 16 {
err = failWith
}
last = protocol.EXPECT().WriteFieldBegin("i", thrift.TType(thrift.I32), int16(4)).Return(err).After(last)
if failAt == 16 {
return true
}
if failAt == 17 {
err = failWith
}
last = protocol.EXPECT().WriteI32(int32(3)).Return(err).After(last)
if failAt == 17 {
return true
}
if failAt == 18 {
err = failWith
}
last = protocol.EXPECT().WriteFieldEnd().Return(err).After(last)
if failAt == 18 {
return true
}
if failAt == 19 {
err = failWith
}
last = protocol.EXPECT().WriteFieldStop().Return(err).After(last)
if failAt == 19 {
return true
}
if failAt == 20 {
err = failWith
}
last = protocol.EXPECT().WriteStructEnd().Return(err).After(last)
if failAt == 20 {
return true
}
if failAt == 21 {
err = failWith
}
last = protocol.EXPECT().WriteFieldEnd().Return(err).After(last)
if failAt == 21 {
return true
}
if failAt == 22 {
err = failWith
}
last = protocol.EXPECT().WriteFieldStop().Return(err).After(last)
if failAt == 22 {
return true
}
if failAt == 23 {
err = failWith
}
last = protocol.EXPECT().WriteStructEnd().Return(err).After(last)
if failAt == 23 {
return true
}
if failAt == 24 {
err = failWith
}
last = protocol.EXPECT().WriteMessageEnd().Return(err).After(last)
if failAt == 24 {
return true
}
if failAt == 25 {
err = failWith
}
last = protocol.EXPECT().Flush(context.Background()).Return(err).After(last)
if failAt == 25 {
return true
}
if failAt == 26 {
err = failWith
}
last = protocol.EXPECT().ReadMessageBegin().Return("testStruct", thrift.REPLY, int32(1), err).After(last)
if failAt == 26 {
return true
}
if failAt == 27 {
err = failWith
}
last = protocol.EXPECT().ReadStructBegin().Return("testStruct_args", err).After(last)
if failAt == 27 {
return true
}
if failAt == 28 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STRUCT), int16(0), err).After(last)
if failAt == 28 {
return true
}
if failAt == 29 {
err = failWith
}
last = protocol.EXPECT().ReadStructBegin().Return("TestStruct", err).After(last)
if failAt == 29 {
return true
}
if failAt == 30 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("m", thrift.TType(thrift.MAP), int16(1), err).After(last)
if failAt == 30 {
return true
}
if failAt == 31 {
err = failWith
}
last = protocol.EXPECT().ReadMapBegin().Return(thrift.TType(thrift.STRING), thrift.TType(thrift.STRING), 0, err).After(last)
if failAt == 31 {
return true
}
if failAt == 32 {
err = failWith
}
last = protocol.EXPECT().ReadMapEnd().Return(err).After(last)
if failAt == 32 {
return true
}
if failAt == 33 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 33 {
return true
}
if failAt == 34 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("l", thrift.TType(thrift.LIST), int16(2), err).After(last)
if failAt == 34 {
return true
}
if failAt == 35 {
err = failWith
}
last = protocol.EXPECT().ReadListBegin().Return(thrift.TType(thrift.STRING), 0, err).After(last)
if failAt == 35 {
return true
}
if failAt == 36 {
err = failWith
}
last = protocol.EXPECT().ReadListEnd().Return(err).After(last)
if failAt == 36 {
return true
}
if failAt == 37 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 37 {
return true
}
if failAt == 38 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("s", thrift.TType(thrift.SET), int16(3), err).After(last)
if failAt == 38 {
return true
}
if failAt == 39 {
err = failWith
}
last = protocol.EXPECT().ReadSetBegin().Return(thrift.TType(thrift.STRING), 0, err).After(last)
if failAt == 39 {
return true
}
if failAt == 40 {
err = failWith
}
last = protocol.EXPECT().ReadSetEnd().Return(err).After(last)
if failAt == 40 {
return true
}
if failAt == 41 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 41 {
return true
}
if failAt == 42 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("i", thrift.TType(thrift.I32), int16(4), err).After(last)
if failAt == 42 {
return true
}
if failAt == 43 {
err = failWith
}
last = protocol.EXPECT().ReadI32().Return(int32(3), err).After(last)
if failAt == 43 {
return true
}
if failAt == 44 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 44 {
return true
}
if failAt == 45 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(5), err).After(last)
if failAt == 45 {
return true
}
if failAt == 46 {
err = failWith
}
last = protocol.EXPECT().ReadStructEnd().Return(err).After(last)
if failAt == 46 {
return true
}
if failAt == 47 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 47 {
return true
}
if failAt == 48 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(1), err).After(last)
if failAt == 48 {
return true
}
if failAt == 49 {
err = failWith
}
last = protocol.EXPECT().ReadStructEnd().Return(err).After(last)
if failAt == 49 {
return true
}
if failAt == 50 {
err = failWith
}
last = protocol.EXPECT().ReadMessageEnd().Return(err).After(last)
if failAt == 50 {
return true
}
return false
}
// TestCase: Comprehensive call and reply workflow in the client.
// Expecting TTransportError on fail.
func TestClientReportTTransportErrors(t *testing.T) {
mockCtrl := gomock.NewController(t)
thing := errortest.NewTestStruct()
thing.M = make(map[string]string)
thing.L = make([]string, 0)
thing.S = make([]string, 0)
thing.I = 3
err := thrift.NewTTransportException(thrift.TIMED_OUT, "test")
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
if !prepareClientCallReply(protocol, i, err) {
return
}
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
err2, ok := retErr.(thrift.TTransportException)
if !ok {
t.Fatal("Expected a TTrasportException")
}
if err2.TypeId() != thrift.TIMED_OUT {
t.Fatal("Expected TIMED_OUT error")
}
}
}
// TestCase: Comprehensive call and reply workflow in the client.
// Expecting TTransportError on fail.
// Similar to TestClientReportTTransportErrors, but using legacy client constructor.
func TestClientReportTTransportErrorsLegacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
thing := errortest.NewTestStruct()
thing.M = make(map[string]string)
thing.L = make([]string, 0)
thing.S = make([]string, 0)
thing.I = 3
err := thrift.NewTTransportException(thrift.TIMED_OUT, "test")
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
if !prepareClientCallReply(protocol, i, err) {
return
}
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
err2, ok := retErr.(thrift.TTransportException)
if !ok {
t.Fatal("Expected a TTrasportException")
}
if err2.TypeId() != thrift.TIMED_OUT {
t.Fatal("Expected TIMED_OUT error")
}
}
}
// TestCase: Comprehensive call and reply workflow in the client.
// Expecting TTProtocolErrors on fail.
func TestClientReportTProtocolErrors(t *testing.T) {
mockCtrl := gomock.NewController(t)
thing := errortest.NewTestStruct()
thing.M = make(map[string]string)
thing.L = make([]string, 0)
thing.S = make([]string, 0)
thing.I = 3
err := thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, errors.New("test"))
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
if !prepareClientCallReply(protocol, i, err) {
return
}
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
err2, ok := retErr.(thrift.TProtocolException)
if !ok {
t.Fatal("Expected a TProtocolException")
}
if err2.TypeId() != thrift.INVALID_DATA {
t.Fatal("Expected INVALID_DATA error")
}
}
}
// TestCase: Comprehensive call and reply workflow in the client.
// Expecting TTProtocolErrors on fail.
// Similar to TestClientReportTProtocolErrors, but using legacy client constructor.
func TestClientReportTProtocolErrorsLegacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
thing := errortest.NewTestStruct()
thing.M = make(map[string]string)
thing.L = make([]string, 0)
thing.S = make([]string, 0)
thing.I = 3
err := thrift.NewTProtocolExceptionWithType(thrift.INVALID_DATA, errors.New("test"))
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
if !prepareClientCallReply(protocol, i, err) {
return
}
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, retErr := client.TestStruct(defaultCtx, thing)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
err2, ok := retErr.(thrift.TProtocolException)
if !ok {
t.Fatal("Expected a TProtocolException")
}
if err2.TypeId() != thrift.INVALID_DATA {
t.Fatal("Expected INVALID_DATA error")
}
}
}
// TestCase: call and reply with exception workflow in the client.
// Setup mock to fail at a certain position. Return true if position exists otherwise false.
func prepareClientCallException(protocol *MockTProtocol, failAt int, failWith error) bool {
var err error = nil
// No need to test failure in this block, because it is covered in other test cases
last := protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1))
last = protocol.EXPECT().WriteStructBegin("testString_args").After(last)
last = protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)).After(last)
last = protocol.EXPECT().WriteString("test").After(last)
last = protocol.EXPECT().WriteFieldEnd().After(last)
last = protocol.EXPECT().WriteFieldStop().After(last)
last = protocol.EXPECT().WriteStructEnd().After(last)
last = protocol.EXPECT().WriteMessageEnd().After(last)
last = protocol.EXPECT().Flush(context.Background()).After(last)
// Reading the exception, might fail.
if failAt == 0 {
err = failWith
}
last = protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.EXCEPTION, int32(1), err).After(last)
if failAt == 0 {
return true
}
if failAt == 1 {
err = failWith
}
last = protocol.EXPECT().ReadStructBegin().Return("TApplicationException", err).After(last)
if failAt == 1 {
return true
}
if failAt == 2 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("message", thrift.TType(thrift.STRING), int16(1), err).After(last)
if failAt == 2 {
return true
}
if failAt == 3 {
err = failWith
}
last = protocol.EXPECT().ReadString().Return("test", err).After(last)
if failAt == 3 {
return true
}
if failAt == 4 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 4 {
return true
}
if failAt == 5 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("type", thrift.TType(thrift.I32), int16(2), err).After(last)
if failAt == 5 {
return true
}
if failAt == 6 {
err = failWith
}
last = protocol.EXPECT().ReadI32().Return(int32(thrift.PROTOCOL_ERROR), err).After(last)
if failAt == 6 {
return true
}
if failAt == 7 {
err = failWith
}
last = protocol.EXPECT().ReadFieldEnd().Return(err).After(last)
if failAt == 7 {
return true
}
if failAt == 8 {
err = failWith
}
last = protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(2), err).After(last)
if failAt == 8 {
return true
}
if failAt == 9 {
err = failWith
}
last = protocol.EXPECT().ReadStructEnd().Return(err).After(last)
if failAt == 9 {
return true
}
if failAt == 10 {
err = failWith
}
last = protocol.EXPECT().ReadMessageEnd().Return(err).After(last)
if failAt == 10 {
return true
}
return false
}
// TestCase: call and reply with exception workflow in the client.
func TestClientCallException(t *testing.T) {
mockCtrl := gomock.NewController(t)
err := thrift.NewTTransportException(thrift.TIMED_OUT, "test")
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
willComplete := !prepareClientCallException(protocol, i, err)
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, retErr := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
if !willComplete {
err2, ok := retErr.(thrift.TTransportException)
if !ok {
t.Fatal("Expected a TTransportException")
}
if err2.TypeId() != thrift.TIMED_OUT {
t.Fatal("Expected TIMED_OUT error")
}
} else {
err2, ok := retErr.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected a TApplicationException")
}
if err2.TypeId() != thrift.PROTOCOL_ERROR {
t.Fatal("Expected PROTOCOL_ERROR error")
}
break
}
}
}
// TestCase: call and reply with exception workflow in the client.
// Similar to TestClientCallException, but using legacy client constructor.
func TestClientCallExceptionLegacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
err := thrift.NewTTransportException(thrift.TIMED_OUT, "test")
for i := 0; ; i++ {
protocol := NewMockTProtocol(mockCtrl)
willComplete := !prepareClientCallException(protocol, i, err)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, retErr := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
if !willComplete {
err2, ok := retErr.(thrift.TTransportException)
if !ok {
t.Fatal("Expected a TTransportException")
}
if err2.TypeId() != thrift.TIMED_OUT {
t.Fatal("Expected TIMED_OUT error")
}
} else {
err2, ok := retErr.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected a TApplicationException")
}
if err2.TypeId() != thrift.PROTOCOL_ERROR {
t.Fatal("Expected PROTOCOL_ERROR error")
}
break
}
}
}
// TestCase: Mismatching sequence id has been received in the client.
func TestClientSeqIdMismatch(t *testing.T) {
mockCtrl := gomock.NewController(t)
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.BAD_SEQUENCE_ID {
t.Fatal("Expected BAD_SEQUENCE_ID error")
}
}
// TestCase: Mismatching sequence id has been received in the client.
// Similar to TestClientSeqIdMismatch, but using legacy client constructor.
func TestClientSeqIdMismatchLegeacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.BAD_SEQUENCE_ID {
t.Fatal("Expected BAD_SEQUENCE_ID error")
}
}
// TestCase: Wrong method name has been received in the client.
func TestClientWrongMethodName(t *testing.T) {
mockCtrl := gomock.NewController(t)
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.WRONG_METHOD_NAME {
t.Fatal("Expected WRONG_METHOD_NAME error")
}
}
// TestCase: Wrong method name has been received in the client.
// Similar to TestClientWrongMethodName, but using legacy client constructor.
func TestClientWrongMethodNameLegacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.WRONG_METHOD_NAME {
t.Fatal("Expected WRONG_METHOD_NAME error")
}
}
// TestCase: Wrong message type has been received in the client.
func TestClientWrongMessageType(t *testing.T) {
mockCtrl := gomock.NewController(t)
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
client := errortest.NewErrorTestClient(thrift.NewTStandardClient(protocol, protocol))
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.INVALID_MESSAGE_TYPE_EXCEPTION {
t.Fatal("Expected INVALID_MESSAGE_TYPE_EXCEPTION error")
}
}
// TestCase: Wrong message type has been received in the client.
// Similar to TestClientWrongMessageType, but using legacy client constructor.
func TestClientWrongMessageTypeLegacy(t *testing.T) {
mockCtrl := gomock.NewController(t)
transport := thrift.NewTMemoryBuffer()
protocol := NewMockTProtocol(mockCtrl)
gomock.InOrder(
protocol.EXPECT().WriteMessageBegin("testString", thrift.CALL, int32(1)),
protocol.EXPECT().WriteStructBegin("testString_args"),
protocol.EXPECT().WriteFieldBegin("s", thrift.TType(thrift.STRING), int16(1)),
protocol.EXPECT().WriteString("test"),
protocol.EXPECT().WriteFieldEnd(),
protocol.EXPECT().WriteFieldStop(),
protocol.EXPECT().WriteStructEnd(),
protocol.EXPECT().WriteMessageEnd(),
protocol.EXPECT().Flush(context.Background()),
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
)
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
_, err := client.TestString(defaultCtx, "test")
mockCtrl.Finish()
appErr, ok := err.(thrift.TApplicationException)
if !ok {
t.Fatal("Expected TApplicationException")
}
if appErr.TypeId() != thrift.INVALID_MESSAGE_TYPE_EXCEPTION {
t.Fatal("Expected INVALID_MESSAGE_TYPE_EXCEPTION error")
}
}

View file

@ -1,26 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
)
var defaultCtx = context.Background()

View file

@ -1,79 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"encoding"
"encoding/json"
"testing"
"thrifttest"
)
func TestEnumIsTextMarshaller(t *testing.T) {
one := thrifttest.Numberz_ONE
var tm encoding.TextMarshaler = one
b, err := tm.MarshalText()
if err != nil {
t.Fatalf("Unexpected error from MarshalText: %s", err)
}
if string(b) != one.String() {
t.Errorf("MarshalText(%s) = %s, expected = %s", one, b, one)
}
}
func TestEnumIsTextUnmarshaller(t *testing.T) {
var tm encoding.TextUnmarshaler = thrifttest.NumberzPtr(thrifttest.Numberz_TWO)
err := tm.UnmarshalText([]byte("TWO"))
if err != nil {
t.Fatalf("Unexpected error from UnmarshalText(TWO): %s", err)
}
if *(tm.(*thrifttest.Numberz)) != thrifttest.Numberz_TWO {
t.Errorf("UnmarshalText(TWO) = %s", tm)
}
err = tm.UnmarshalText([]byte("NAN"))
if err == nil {
t.Errorf("Error from UnmarshalText(NAN)")
}
}
func TestJSONMarshalUnmarshal(t *testing.T) {
s1 := thrifttest.StructB{
Aa: &thrifttest.StructA{S: "Aa"},
Ab: &thrifttest.StructA{S: "Ab"},
}
b, err := json.Marshal(s1)
if err != nil {
t.Fatalf("Unexpected error from json.Marshal: %s", err)
}
s2 := thrifttest.StructB{}
err = json.Unmarshal(b, &s2)
if err != nil {
t.Fatalf("Unexpected error from json.Unmarshal: %s", err)
}
if *s1.Aa != *s2.Aa || *s1.Ab != *s2.Ab {
t.Logf("s1 = %+v", s1)
t.Logf("s2 = %+v", s2)
t.Errorf("json: Unmarshal(Marshal(s)) != s")
}
}

View file

@ -1,53 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"gotagtest"
"reflect"
"testing"
)
func TestDefaultTag(t *testing.T) {
s := gotagtest.Tagged{}
st := reflect.TypeOf(s)
field, ok := st.FieldByName("StringThing")
if !ok || field.Tag.Get("json") != "string_thing" {
t.Error("Unexpected default tag value")
}
}
func TestCustomTag(t *testing.T) {
s := gotagtest.Tagged{}
st := reflect.TypeOf(s)
field, ok := st.FieldByName("IntThing")
if !ok || field.Tag.Get("json") != "int_thing,string" {
t.Error("Unexpected custom tag value")
}
}
func TestOptionalTag(t *testing.T) {
s := gotagtest.Tagged{}
st := reflect.TypeOf(s)
field, ok := st.FieldByName("OptionalIntThing")
if !ok || field.Tag.Get("json") != "optional_int_thing,omitempty" {
t.Error("Unexpected default tag value for optional field")
}
}

View file

@ -1,51 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"ignoreinitialismstest"
"reflect"
"testing"
)
func TestIgnoreInitialismsFlagIsHonoured(t *testing.T) {
s := ignoreinitialismstest.IgnoreInitialismsTest{}
st := reflect.TypeOf(s)
_, ok := st.FieldByName("Id")
if !ok {
t.Error("Id attribute is missing!")
}
_, ok = st.FieldByName("MyId")
if !ok {
t.Error("MyId attribute is missing!")
}
_, ok = st.FieldByName("NumCpu")
if !ok {
t.Error("NumCpu attribute is missing!")
}
_, ok = st.FieldByName("NumGpu")
if !ok {
t.Error("NumGpu attribute is missing!")
}
_, ok = st.FieldByName("My_ID")
if !ok {
t.Error("My_ID attribute is missing!")
}
}

View file

@ -1,43 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"initialismstest"
"reflect"
"testing"
)
func TestThatCommonInitialismsAreFixed(t *testing.T) {
s := initialismstest.InitialismsTest{}
st := reflect.TypeOf(s)
_, ok := st.FieldByName("UserID")
if !ok {
t.Error("UserID attribute is missing!")
}
_, ok = st.FieldByName("ServerURL")
if !ok {
t.Error("ServerURL attribute is missing!")
}
_, ok = st.FieldByName("ID")
if !ok {
t.Error("ID attribute is missing!")
}
}

View file

@ -1,197 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
"multiplexedprotocoltest"
"net"
"testing"
"thrift"
"time"
)
func FindAvailableTCPServerPort() net.Addr {
if l, err := net.Listen("tcp", "127.0.0.1:0"); err != nil {
panic("Could not find available server port")
} else {
defer l.Close()
return l.Addr()
}
}
type FirstImpl struct{}
func (f *FirstImpl) ReturnOne(ctx context.Context) (r int64, err error) {
return 1, nil
}
type SecondImpl struct{}
func (s *SecondImpl) ReturnTwo(ctx context.Context) (r int64, err error) {
return 2, nil
}
func createTransport(addr net.Addr) (thrift.TTransport, error) {
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport := thrift.NewTFramedTransport(socket)
err := transport.Open()
if err != nil {
return nil, err
}
return transport, nil
}
func TestMultiplexedProtocolFirst(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTTransportFactory()
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
t.Fatal("Unable to create server socket", err)
}
server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
processor.RegisterProcessor("FirstService", firstProcessor)
secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
processor.RegisterProcessor("SecondService", secondProcessor)
defer server.Stop()
go server.Serve()
time.Sleep(10 * time.Millisecond)
transport, err := createTransport(addr)
if err != nil {
t.Fatal(err)
}
defer transport.Close()
protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolTransport(transport), "FirstService")
client := multiplexedprotocoltest.NewFirstClient(thrift.NewTStandardClient(protocol, protocol))
ret, err := client.ReturnOne(defaultCtx)
if err != nil {
t.Fatal("Unable to call first server:", err)
} else if ret != 1 {
t.Fatal("Unexpected result from server: ", ret)
}
}
func TestMultiplexedProtocolSecond(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTTransportFactory()
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
t.Fatal("Unable to create server socket", err)
}
server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
processor.RegisterProcessor("FirstService", firstProcessor)
secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
processor.RegisterProcessor("SecondService", secondProcessor)
defer server.Stop()
go server.Serve()
time.Sleep(10 * time.Millisecond)
transport, err := createTransport(addr)
if err != nil {
t.Fatal(err)
}
defer transport.Close()
protocol := thrift.NewTMultiplexedProtocol(thrift.NewTBinaryProtocolTransport(transport), "SecondService")
client := multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
ret, err := client.ReturnTwo(defaultCtx)
if err != nil {
t.Fatal("Unable to call second server:", err)
} else if ret != 2 {
t.Fatal("Unexpected result from server: ", ret)
}
}
func TestMultiplexedProtocolLegacy(t *testing.T) {
processor := thrift.NewTMultiplexedProcessor()
protocolFactory := thrift.NewTBinaryProtocolFactoryDefault()
transportFactory := thrift.NewTTransportFactory()
transportFactory = thrift.NewTFramedTransportFactory(transportFactory)
addr := FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
t.Fatal("Unable to create server socket", err)
}
server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
firstProcessor := multiplexedprotocoltest.NewFirstProcessor(&FirstImpl{})
processor.RegisterProcessor("FirstService", firstProcessor)
secondProcessor := multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{})
processor.RegisterProcessor("SecondService", secondProcessor)
defer server.Stop()
go server.Serve()
time.Sleep(10 * time.Millisecond)
transport, err := createTransport(addr)
if err != nil {
t.Error(err)
return
}
defer transport.Close()
protocol := thrift.NewTBinaryProtocolTransport(transport)
client := multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
ret, err := client.ReturnTwo(defaultCtx)
//expect error since default processor is not registered
if err == nil {
t.Fatal("Expecting error")
}
//register default processor and call again
processor.RegisterDefault(multiplexedprotocoltest.NewSecondProcessor(&SecondImpl{}))
transport, err = createTransport(addr)
if err != nil {
t.Error(err)
return
}
defer transport.Close()
protocol = thrift.NewTBinaryProtocolTransport(transport)
client = multiplexedprotocoltest.NewSecondClient(thrift.NewTStandardClient(protocol, protocol))
ret, err = client.ReturnTwo(defaultCtx)
if err != nil {
t.Fatal("Unable to call legacy server:", err)
}
if ret != 2 {
t.Fatal("Unexpected result from server: ", ret)
}
}

View file

@ -1,35 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"namestest"
"reflect"
"testing"
)
func TestThatAttributeNameSubstituionDoesNotOccur(t *testing.T) {
s := namestest.NamesTest{}
st := reflect.TypeOf(s)
_, ok := st.FieldByName("Type")
if !ok {
t.Error("Type attribute is missing!")
}
}

View file

@ -1,91 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
"fmt"
"net"
"onewaytest"
"testing"
"thrift"
"time"
)
func findPort() net.Addr {
if l, err := net.Listen("tcp", "127.0.0.1:0"); err != nil {
panic("Could not find available server port")
} else {
defer l.Close()
return l.Addr()
}
}
type impl struct{}
func (i *impl) Hi(ctx context.Context, in int64, s string) (err error) { fmt.Println("Hi!"); return }
func (i *impl) Emptyfunc(ctx context.Context) (err error) { return }
func (i *impl) EchoInt(ctx context.Context, param int64) (r int64, err error) { return param, nil }
const TIMEOUT = time.Second
var addr net.Addr
var server *thrift.TSimpleServer
var client *onewaytest.OneWayClient
func TestInitOneway(t *testing.T) {
var err error
addr = findPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
t.Fatal("Unable to create server socket", err)
}
processor := onewaytest.NewOneWayProcessor(&impl{})
server = thrift.NewTSimpleServer2(processor, serverTransport)
go server.Serve()
time.Sleep(10 * time.Millisecond)
}
func TestInitOnewayClient(t *testing.T) {
transport := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
protocol := thrift.NewTBinaryProtocolTransport(transport)
client = onewaytest.NewOneWayClient(thrift.NewTStandardClient(protocol, protocol))
err := transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
}
}
func TestCallOnewayServer(t *testing.T) {
//call oneway function
err := client.Hi(defaultCtx, 1, "")
if err != nil {
t.Fatal("Unexpected error: ", err)
}
//There is no way to detect protocol problems with single oneway call so we call it second time
i, err := client.EchoInt(defaultCtx, 42)
if err != nil {
t.Fatal("Unexpected error: ", err)
}
if i != 42 {
t.Fatal("Unexpected returned value: ", i)
}
}

View file

@ -1,280 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"bytes"
gomock "github.com/golang/mock/gomock"
"optionalfieldstest"
"testing"
"thrift"
)
func TestIsSetReturnFalseOnCreation(t *testing.T) {
ao := optionalfieldstest.NewAllOptional()
if ao.IsSetS() {
t.Errorf("Optional field S is set on initialization")
}
if ao.IsSetI() {
t.Errorf("Optional field I is set on initialization")
}
if ao.IsSetB() {
t.Errorf("Optional field B is set on initialization")
}
if ao.IsSetS2() {
t.Errorf("Optional field S2 is set on initialization")
}
if ao.IsSetI2() {
t.Errorf("Optional field I2 is set on initialization")
}
if ao.IsSetB2() {
t.Errorf("Optional field B2 is set on initialization")
}
if ao.IsSetAa() {
t.Errorf("Optional field Aa is set on initialization")
}
if ao.IsSetL() {
t.Errorf("Optional field L is set on initialization")
}
if ao.IsSetL2() {
t.Errorf("Optional field L2 is set on initialization")
}
if ao.IsSetM() {
t.Errorf("Optional field M is set on initialization")
}
if ao.IsSetM2() {
t.Errorf("Optional field M2 is set on initialization")
}
if ao.IsSetBin() {
t.Errorf("Optional field Bin is set on initialization")
}
if ao.IsSetBin2() {
t.Errorf("Optional field Bin2 is set on initialization")
}
}
func TestDefaultValuesOnCreation(t *testing.T) {
ao := optionalfieldstest.NewAllOptional()
if ao.GetS() != "DEFAULT" {
t.Errorf("Unexpected default value %#v for field S", ao.GetS())
}
if ao.GetI() != 42 {
t.Errorf("Unexpected default value %#v for field I", ao.GetI())
}
if ao.GetB() != false {
t.Errorf("Unexpected default value %#v for field B", ao.GetB())
}
if ao.GetS2() != "" {
t.Errorf("Unexpected default value %#v for field S2", ao.GetS2())
}
if ao.GetI2() != 0 {
t.Errorf("Unexpected default value %#v for field I2", ao.GetI2())
}
if ao.GetB2() != false {
t.Errorf("Unexpected default value %#v for field B2", ao.GetB2())
}
if l := ao.GetL(); len(l) != 0 {
t.Errorf("Unexpected default value %#v for field L", l)
}
if l := ao.GetL2(); len(l) != 2 || l[0] != 1 || l[1] != 2 {
t.Errorf("Unexpected default value %#v for field L2", l)
}
//FIXME: should we return empty map here?
if m := ao.GetM(); m != nil {
t.Errorf("Unexpected default value %#v for field M", m)
}
if m := ao.GetM2(); len(m) != 2 || m[1] != 2 || m[3] != 4 {
t.Errorf("Unexpected default value %#v for field M2", m)
}
if bv := ao.GetBin(); bv != nil {
t.Errorf("Unexpected default value %#v for field Bin", bv)
}
if bv := ao.GetBin2(); !bytes.Equal(bv, []byte("asdf")) {
t.Errorf("Unexpected default value %#v for field Bin2", bv)
}
}
func TestInitialValuesOnCreation(t *testing.T) {
ao := optionalfieldstest.NewAllOptional()
if ao.S != "DEFAULT" {
t.Errorf("Unexpected initial value %#v for field S", ao.S)
}
if ao.I != 42 {
t.Errorf("Unexpected initial value %#v for field I", ao.I)
}
if ao.B != false {
t.Errorf("Unexpected initial value %#v for field B", ao.B)
}
if ao.S2 != nil {
t.Errorf("Unexpected initial value %#v for field S2", ao.S2)
}
if ao.I2 != nil {
t.Errorf("Unexpected initial value %#v for field I2", ao.I2)
}
if ao.B2 != nil {
t.Errorf("Unexpected initial value %#v for field B2", ao.B2)
}
if ao.L != nil || len(ao.L) != 0 {
t.Errorf("Unexpected initial value %#v for field L", ao.L)
}
if ao.L2 != nil {
t.Errorf("Unexpected initial value %#v for field L2", ao.L2)
}
if ao.M != nil {
t.Errorf("Unexpected initial value %#v for field M", ao.M)
}
if ao.M2 != nil {
t.Errorf("Unexpected initial value %#v for field M2", ao.M2)
}
if ao.Bin != nil || len(ao.Bin) != 0 {
t.Errorf("Unexpected initial value %#v for field Bin", ao.Bin)
}
if !bytes.Equal(ao.Bin2, []byte("asdf")) {
t.Errorf("Unexpected initial value %#v for field Bin2", ao.Bin2)
}
}
func TestIsSetReturnTrueAfterUpdate(t *testing.T) {
ao := optionalfieldstest.NewAllOptional()
ao.S = "somevalue"
ao.I = 123
ao.B = true
ao.Aa = optionalfieldstest.NewStructA()
if !ao.IsSetS() {
t.Errorf("Field S should be set")
}
if !ao.IsSetI() {
t.Errorf("Field I should be set")
}
if !ao.IsSetB() {
t.Errorf("Field B should be set")
}
if !ao.IsSetAa() {
t.Errorf("Field aa should be set")
}
}
func TestListNotEmpty(t *testing.T) {
ao := optionalfieldstest.NewAllOptional()
ao.L = []int64{1, 2, 3}
if !ao.IsSetL() {
t.Errorf("Field L should be set")
}
}
//Make sure that optional fields are not being serialized
func TestNoOptionalUnsetFieldsOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.Write(proto)
}
func TestNoSetToDefaultFieldsOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.I = 42
ao.Write(proto)
}
//Make sure that only one field is being serialized when set to non-default
func TestOneISetFieldOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldBegin("i", thrift.TType(thrift.I64), int16(2)).Return(nil),
proto.EXPECT().WriteI64(int64(123)).Return(nil),
proto.EXPECT().WriteFieldEnd().Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.I = 123
ao.Write(proto)
}
func TestOneLSetFieldOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldBegin("l", thrift.TType(thrift.LIST), int16(9)).Return(nil),
proto.EXPECT().WriteListBegin(thrift.TType(thrift.I64), 2).Return(nil),
proto.EXPECT().WriteI64(int64(1)).Return(nil),
proto.EXPECT().WriteI64(int64(2)).Return(nil),
proto.EXPECT().WriteListEnd().Return(nil),
proto.EXPECT().WriteFieldEnd().Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.L = []int64{1, 2}
ao.Write(proto)
}
func TestOneBinSetFieldOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldBegin("bin", thrift.TType(thrift.STRING), int16(13)).Return(nil),
proto.EXPECT().WriteBinary([]byte("somebytestring")).Return(nil),
proto.EXPECT().WriteFieldEnd().Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.Bin = []byte("somebytestring")
ao.Write(proto)
}
func TestOneEmptyBinSetFieldOnWire(t *testing.T) {
mockCtrl := gomock.NewController(t)
defer mockCtrl.Finish()
proto := NewMockTProtocol(mockCtrl)
gomock.InOrder(
proto.EXPECT().WriteStructBegin("all_optional").Return(nil),
proto.EXPECT().WriteFieldBegin("bin", thrift.TType(thrift.STRING), int16(13)).Return(nil),
proto.EXPECT().WriteBinary([]byte{}).Return(nil),
proto.EXPECT().WriteFieldEnd().Return(nil),
proto.EXPECT().WriteFieldStop().Return(nil),
proto.EXPECT().WriteStructEnd().Return(nil),
)
ao := optionalfieldstest.NewAllOptional()
ao.Bin = []byte{}
ao.Write(proto)
}

View file

@ -1,513 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
// Automatically generated by MockGen. DO NOT EDIT!
// Source: thrift (interfaces: TProtocol)
package tests
import (
"context"
thrift "thrift"
gomock "github.com/golang/mock/gomock"
)
// Mock of TProtocol interface
type MockTProtocol struct {
ctrl *gomock.Controller
recorder *_MockTProtocolRecorder
}
// Recorder for MockTProtocol (not exported)
type _MockTProtocolRecorder struct {
mock *MockTProtocol
}
func NewMockTProtocol(ctrl *gomock.Controller) *MockTProtocol {
mock := &MockTProtocol{ctrl: ctrl}
mock.recorder = &_MockTProtocolRecorder{mock}
return mock
}
func (_m *MockTProtocol) EXPECT() *_MockTProtocolRecorder {
return _m.recorder
}
func (_m *MockTProtocol) Flush(ctx context.Context) error {
ret := _m.ctrl.Call(_m, "Flush")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) Flush(ctx context.Context) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Flush")
}
func (_m *MockTProtocol) ReadBinary() ([]byte, error) {
ret := _m.ctrl.Call(_m, "ReadBinary")
ret0, _ := ret[0].([]byte)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadBinary() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadBinary")
}
func (_m *MockTProtocol) ReadBool() (bool, error) {
ret := _m.ctrl.Call(_m, "ReadBool")
ret0, _ := ret[0].(bool)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadBool() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadBool")
}
func (_m *MockTProtocol) ReadByte() (int8, error) {
ret := _m.ctrl.Call(_m, "ReadByte")
ret0, _ := ret[0].(int8)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadByte() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadByte")
}
func (_m *MockTProtocol) ReadDouble() (float64, error) {
ret := _m.ctrl.Call(_m, "ReadDouble")
ret0, _ := ret[0].(float64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadDouble() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadDouble")
}
func (_m *MockTProtocol) ReadFieldBegin() (string, thrift.TType, int16, error) {
ret := _m.ctrl.Call(_m, "ReadFieldBegin")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(thrift.TType)
ret2, _ := ret[2].(int16)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
}
func (_mr *_MockTProtocolRecorder) ReadFieldBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadFieldBegin")
}
func (_m *MockTProtocol) ReadFieldEnd() error {
ret := _m.ctrl.Call(_m, "ReadFieldEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadFieldEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadFieldEnd")
}
func (_m *MockTProtocol) ReadI16() (int16, error) {
ret := _m.ctrl.Call(_m, "ReadI16")
ret0, _ := ret[0].(int16)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadI16() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI16")
}
func (_m *MockTProtocol) ReadI32() (int32, error) {
ret := _m.ctrl.Call(_m, "ReadI32")
ret0, _ := ret[0].(int32)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadI32() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI32")
}
func (_m *MockTProtocol) ReadI64() (int64, error) {
ret := _m.ctrl.Call(_m, "ReadI64")
ret0, _ := ret[0].(int64)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadI64() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadI64")
}
func (_m *MockTProtocol) ReadListBegin() (thrift.TType, int, error) {
ret := _m.ctrl.Call(_m, "ReadListBegin")
ret0, _ := ret[0].(thrift.TType)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
func (_mr *_MockTProtocolRecorder) ReadListBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadListBegin")
}
func (_m *MockTProtocol) ReadListEnd() error {
ret := _m.ctrl.Call(_m, "ReadListEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadListEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadListEnd")
}
func (_m *MockTProtocol) ReadMapBegin() (thrift.TType, thrift.TType, int, error) {
ret := _m.ctrl.Call(_m, "ReadMapBegin")
ret0, _ := ret[0].(thrift.TType)
ret1, _ := ret[1].(thrift.TType)
ret2, _ := ret[2].(int)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
}
func (_mr *_MockTProtocolRecorder) ReadMapBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMapBegin")
}
func (_m *MockTProtocol) ReadMapEnd() error {
ret := _m.ctrl.Call(_m, "ReadMapEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadMapEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMapEnd")
}
func (_m *MockTProtocol) ReadMessageBegin() (string, thrift.TMessageType, int32, error) {
ret := _m.ctrl.Call(_m, "ReadMessageBegin")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(thrift.TMessageType)
ret2, _ := ret[2].(int32)
ret3, _ := ret[3].(error)
return ret0, ret1, ret2, ret3
}
func (_mr *_MockTProtocolRecorder) ReadMessageBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMessageBegin")
}
func (_m *MockTProtocol) ReadMessageEnd() error {
ret := _m.ctrl.Call(_m, "ReadMessageEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadMessageEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadMessageEnd")
}
func (_m *MockTProtocol) ReadSetBegin() (thrift.TType, int, error) {
ret := _m.ctrl.Call(_m, "ReadSetBegin")
ret0, _ := ret[0].(thrift.TType)
ret1, _ := ret[1].(int)
ret2, _ := ret[2].(error)
return ret0, ret1, ret2
}
func (_mr *_MockTProtocolRecorder) ReadSetBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadSetBegin")
}
func (_m *MockTProtocol) ReadSetEnd() error {
ret := _m.ctrl.Call(_m, "ReadSetEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadSetEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadSetEnd")
}
func (_m *MockTProtocol) ReadString() (string, error) {
ret := _m.ctrl.Call(_m, "ReadString")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadString() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadString")
}
func (_m *MockTProtocol) ReadStructBegin() (string, error) {
ret := _m.ctrl.Call(_m, "ReadStructBegin")
ret0, _ := ret[0].(string)
ret1, _ := ret[1].(error)
return ret0, ret1
}
func (_mr *_MockTProtocolRecorder) ReadStructBegin() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadStructBegin")
}
func (_m *MockTProtocol) ReadStructEnd() error {
ret := _m.ctrl.Call(_m, "ReadStructEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) ReadStructEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "ReadStructEnd")
}
func (_m *MockTProtocol) Skip(_param0 thrift.TType) error {
ret := _m.ctrl.Call(_m, "Skip", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) Skip(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Skip", arg0)
}
func (_m *MockTProtocol) Transport() thrift.TTransport {
ret := _m.ctrl.Call(_m, "Transport")
ret0, _ := ret[0].(thrift.TTransport)
return ret0
}
func (_mr *_MockTProtocolRecorder) Transport() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "Transport")
}
func (_m *MockTProtocol) WriteBinary(_param0 []byte) error {
ret := _m.ctrl.Call(_m, "WriteBinary", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteBinary(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteBinary", arg0)
}
func (_m *MockTProtocol) WriteBool(_param0 bool) error {
ret := _m.ctrl.Call(_m, "WriteBool", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteBool(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteBool", arg0)
}
func (_m *MockTProtocol) WriteByte(_param0 int8) error {
ret := _m.ctrl.Call(_m, "WriteByte", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteByte(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteByte", arg0)
}
func (_m *MockTProtocol) WriteDouble(_param0 float64) error {
ret := _m.ctrl.Call(_m, "WriteDouble", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteDouble(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteDouble", arg0)
}
func (_m *MockTProtocol) WriteFieldBegin(_param0 string, _param1 thrift.TType, _param2 int16) error {
ret := _m.ctrl.Call(_m, "WriteFieldBegin", _param0, _param1, _param2)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteFieldBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldBegin", arg0, arg1, arg2)
}
func (_m *MockTProtocol) WriteFieldEnd() error {
ret := _m.ctrl.Call(_m, "WriteFieldEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteFieldEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldEnd")
}
func (_m *MockTProtocol) WriteFieldStop() error {
ret := _m.ctrl.Call(_m, "WriteFieldStop")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteFieldStop() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteFieldStop")
}
func (_m *MockTProtocol) WriteI16(_param0 int16) error {
ret := _m.ctrl.Call(_m, "WriteI16", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteI16(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI16", arg0)
}
func (_m *MockTProtocol) WriteI32(_param0 int32) error {
ret := _m.ctrl.Call(_m, "WriteI32", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteI32(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI32", arg0)
}
func (_m *MockTProtocol) WriteI64(_param0 int64) error {
ret := _m.ctrl.Call(_m, "WriteI64", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteI64(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteI64", arg0)
}
func (_m *MockTProtocol) WriteListBegin(_param0 thrift.TType, _param1 int) error {
ret := _m.ctrl.Call(_m, "WriteListBegin", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteListBegin(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteListBegin", arg0, arg1)
}
func (_m *MockTProtocol) WriteListEnd() error {
ret := _m.ctrl.Call(_m, "WriteListEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteListEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteListEnd")
}
func (_m *MockTProtocol) WriteMapBegin(_param0 thrift.TType, _param1 thrift.TType, _param2 int) error {
ret := _m.ctrl.Call(_m, "WriteMapBegin", _param0, _param1, _param2)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteMapBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMapBegin", arg0, arg1, arg2)
}
func (_m *MockTProtocol) WriteMapEnd() error {
ret := _m.ctrl.Call(_m, "WriteMapEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteMapEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMapEnd")
}
func (_m *MockTProtocol) WriteMessageBegin(_param0 string, _param1 thrift.TMessageType, _param2 int32) error {
ret := _m.ctrl.Call(_m, "WriteMessageBegin", _param0, _param1, _param2)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteMessageBegin(arg0, arg1, arg2 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMessageBegin", arg0, arg1, arg2)
}
func (_m *MockTProtocol) WriteMessageEnd() error {
ret := _m.ctrl.Call(_m, "WriteMessageEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteMessageEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteMessageEnd")
}
func (_m *MockTProtocol) WriteSetBegin(_param0 thrift.TType, _param1 int) error {
ret := _m.ctrl.Call(_m, "WriteSetBegin", _param0, _param1)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteSetBegin(arg0, arg1 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteSetBegin", arg0, arg1)
}
func (_m *MockTProtocol) WriteSetEnd() error {
ret := _m.ctrl.Call(_m, "WriteSetEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteSetEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteSetEnd")
}
func (_m *MockTProtocol) WriteString(_param0 string) error {
ret := _m.ctrl.Call(_m, "WriteString", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteString(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteString", arg0)
}
func (_m *MockTProtocol) WriteStructBegin(_param0 string) error {
ret := _m.ctrl.Call(_m, "WriteStructBegin", _param0)
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteStructBegin(arg0 interface{}) *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteStructBegin", arg0)
}
func (_m *MockTProtocol) WriteStructEnd() error {
ret := _m.ctrl.Call(_m, "WriteStructEnd")
ret0, _ := ret[0].(error)
return ret0
}
func (_mr *_MockTProtocolRecorder) WriteStructEnd() *gomock.Call {
return _mr.mock.ctrl.RecordCall(_mr.mock, "WriteStructEnd")
}

View file

@ -1,97 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"testing"
"thrift"
"thrifttest"
)
func RunSocketTestSuite(t *testing.T, protocolFactory thrift.TProtocolFactory,
transportFactory thrift.TTransportFactory) {
// server
var err error
addr = FindAvailableTCPServerPort()
serverTransport, err := thrift.NewTServerSocketTimeout(addr.String(), TIMEOUT)
if err != nil {
t.Fatal("Unable to create server socket", err)
}
processor := thrifttest.NewThriftTestProcessor(NewThriftTestHandler())
server = thrift.NewTSimpleServer4(processor, serverTransport, transportFactory, protocolFactory)
server.Listen()
go server.Serve()
// client
var transport thrift.TTransport = thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
transport, err = transportFactory.GetTransport(transport)
if err != nil {
t.Fatal(err)
}
var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
thriftTestClient := thrifttest.NewThriftTestClient(thrift.NewTStandardClient(protocol, protocol))
err = transport.Open()
if err != nil {
t.Fatal("Unable to open client socket", err)
}
driver := NewThriftTestDriver(t, thriftTestClient)
driver.Start()
}
// Run test suite using TJSONProtocol
func TestTJSONProtocol(t *testing.T) {
RunSocketTestSuite(t,
thrift.NewTJSONProtocolFactory(),
thrift.NewTTransportFactory())
RunSocketTestSuite(t,
thrift.NewTJSONProtocolFactory(),
thrift.NewTBufferedTransportFactory(8912))
RunSocketTestSuite(t,
thrift.NewTJSONProtocolFactory(),
thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
}
// Run test suite using TBinaryProtocol
func TestTBinaryProtocol(t *testing.T) {
RunSocketTestSuite(t,
thrift.NewTBinaryProtocolFactoryDefault(),
thrift.NewTTransportFactory())
RunSocketTestSuite(t,
thrift.NewTBinaryProtocolFactoryDefault(),
thrift.NewTBufferedTransportFactory(8912))
RunSocketTestSuite(t,
thrift.NewTBinaryProtocolFactoryDefault(),
thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
}
// Run test suite using TCompactBinaryProtocol
func TestTCompactProtocol(t *testing.T) {
RunSocketTestSuite(t,
thrift.NewTCompactProtocolFactory(),
thrift.NewTTransportFactory())
RunSocketTestSuite(t,
thrift.NewTCompactProtocolFactory(),
thrift.NewTBufferedTransportFactory(8912))
RunSocketTestSuite(t,
thrift.NewTCompactProtocolFactory(),
thrift.NewTFramedTransportFactory(thrift.NewTTransportFactory()))
}

View file

@ -1,130 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
"github.com/golang/mock/gomock"
"optionalfieldstest"
"requiredfieldtest"
"testing"
"thrift"
)
func TestRequiredField_SucecssWhenSet(t *testing.T) {
// create a new RequiredField instance with the required field set
source := &requiredfieldtest.RequiredField{Name: "this is a test"}
sourceData, err := thrift.NewTSerializer().Write(context.Background(), source)
if err != nil {
t.Fatalf("failed to serialize %T: %v", source, err)
}
d := thrift.NewTDeserializer()
err = d.Read(&requiredfieldtest.RequiredField{}, sourceData)
if err != nil {
t.Fatalf("Did not expect an error when trying to deserialize the requiredfieldtest.RequiredField: %v", err)
}
}
func TestRequiredField_ErrorWhenMissing(t *testing.T) {
// create a new OtherThing instance, without setting the required field
source := &requiredfieldtest.OtherThing{}
sourceData, err := thrift.NewTSerializer().Write(context.Background(), source)
if err != nil {
t.Fatalf("failed to serialize %T: %v", source, err)
}
// attempt to deserialize into a different type (which should fail)
d := thrift.NewTDeserializer()
err = d.Read(&requiredfieldtest.RequiredField{}, sourceData)
if err == nil {
t.Fatal("Expected an error when trying to deserialize an object which is missing a required field")
}
}
func TestStructReadRequiredFields(t *testing.T) {
mockCtrl := gomock.NewController(t)
protocol := NewMockTProtocol(mockCtrl)
testStruct := optionalfieldstest.NewStructC()
// None of required fields are set
gomock.InOrder(
protocol.EXPECT().ReadStructBegin().Return("StructC", nil),
protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(1), nil),
protocol.EXPECT().ReadStructEnd().Return(nil),
)
err := testStruct.Read(protocol)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
if err == nil {
t.Fatal("Expected read to fail")
}
err2, ok := err.(thrift.TProtocolException)
if !ok {
t.Fatal("Expected a TProtocolException")
}
if err2.TypeId() != thrift.INVALID_DATA {
t.Fatal("Expected INVALID_DATA TProtocolException")
}
// One of the required fields is set
gomock.InOrder(
protocol.EXPECT().ReadStructBegin().Return("StructC", nil),
protocol.EXPECT().ReadFieldBegin().Return("I", thrift.TType(thrift.I32), int16(2), nil),
protocol.EXPECT().ReadI32().Return(int32(1), nil),
protocol.EXPECT().ReadFieldEnd().Return(nil),
protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(1), nil),
protocol.EXPECT().ReadStructEnd().Return(nil),
)
err = testStruct.Read(protocol)
mockCtrl.Finish()
mockCtrl = gomock.NewController(t)
if err == nil {
t.Fatal("Expected read to fail")
}
err2, ok = err.(thrift.TProtocolException)
if !ok {
t.Fatal("Expected a TProtocolException")
}
if err2.TypeId() != thrift.INVALID_DATA {
t.Fatal("Expected INVALID_DATA TProtocolException")
}
// Both of the required fields are set
gomock.InOrder(
protocol.EXPECT().ReadStructBegin().Return("StructC", nil),
protocol.EXPECT().ReadFieldBegin().Return("i", thrift.TType(thrift.I32), int16(2), nil),
protocol.EXPECT().ReadI32().Return(int32(1), nil),
protocol.EXPECT().ReadFieldEnd().Return(nil),
protocol.EXPECT().ReadFieldBegin().Return("s2", thrift.TType(thrift.STRING), int16(4), nil),
protocol.EXPECT().ReadString().Return("test", nil),
protocol.EXPECT().ReadFieldEnd().Return(nil),
protocol.EXPECT().ReadFieldBegin().Return("_", thrift.TType(thrift.STOP), int16(1), nil),
protocol.EXPECT().ReadStructEnd().Return(nil),
)
err = testStruct.Read(protocol)
mockCtrl.Finish()
if err != nil {
t.Fatal("Expected read to succeed")
}
}

View file

@ -1,36 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
st "servicestest"
)
//this function is never called, it will fail to compile if check is failed
func staticCheckStructArgsResults() {
//Check that struct args and results are passed by reference
var sa *st.StructA = &st.StructA{}
var iface st.AServ
var err error
sa, err = iface.StructAFunc_1structA(defaultCtx, sa)
_ = err
_ = sa
}

View file

@ -1,236 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"reflect"
"testing"
"thrifttest"
)
type ThriftTestDriver struct {
client thrifttest.ThriftTest
t *testing.T
}
func NewThriftTestDriver(t *testing.T, client thrifttest.ThriftTest) *ThriftTestDriver {
return &ThriftTestDriver{client, t}
}
func (p *ThriftTestDriver) Start() {
client := p.client
t := p.t
if client.TestVoid(defaultCtx) != nil {
t.Fatal("TestVoid failed")
}
if r, err := client.TestString(defaultCtx, "Test"); r != "Test" || err != nil {
t.Fatal("TestString with simple text failed")
}
if r, err := client.TestString(defaultCtx, ""); r != "" || err != nil {
t.Fatal("TestString with empty text failed")
}
stringTest := "Afrikaans, Alemannisch, Aragonés, العربية, مصرى, " +
"Asturianu, Aymar aru, Azərbaycan, Башҡорт, Boarisch, Žemaitėška, " +
"Беларуская, Беларуская (тарашкевіца), Български, Bamanankan, " +
"বাংলা, Brezhoneg, Bosanski, Català, Mìng-dĕ̤ng-ngṳ̄, Нохчийн, " +
"Cebuano, ᏣᎳᎩ, Česky, Словѣ́ньскъ / ⰔⰎⰑⰂⰡⰐⰠⰔⰍⰟ, Чӑвашла, Cymraeg, " +
"Dansk, Zazaki, ދިވެހިބަސް, Ελληνικά, Emiliàn e rumagnòl, English, " +
"Esperanto, Español, Eesti, Euskara, فارسی, Suomi, Võro, Føroyskt, " +
"Français, Arpetan, Furlan, Frysk, Gaeilge, 贛語, Gàidhlig, Galego, " +
"Avañe'ẽ, ગુજરાતી, Gaelg, עברית, हिन्दी, Fiji Hindi, Hrvatski, " +
"Kreyòl ayisyen, Magyar, Հայերեն, Interlingua, Bahasa Indonesia, " +
"Ilokano, Ido, Íslenska, Italiano, 日本語, Lojban, Basa Jawa, " +
"ქართული, Kongo, Kalaallisut, ಕನ್ನಡ, 한국어, Къарачай-Малкъар, " +
"Ripoarisch, Kurdî, Коми, Kernewek, Кыргызча, Latina, Ladino, " +
"Lëtzebuergesch, Limburgs, Lingála, ລາວ, Lietuvių, Latviešu, Basa " +
"Banyumasan, Malagasy, Македонски, മലയാളം, मराठी, مازِرونی, Bahasa " +
"Melayu, Nnapulitano, Nedersaksisch, नेपाल भाषा, Nederlands, " +
"Norsk (nynorsk), Norsk (bokmål), Nouormand, Diné bizaad, " +
"Occitan, Иронау, Papiamentu, Deitsch, Polski, پنجابی, پښتو, " +
"Norfuk / Pitkern, Português, Runa Simi, Rumantsch, Romani, Română, " +
"Русский, Саха тыла, Sardu, Sicilianu, Scots, Sámegiella, Simple " +
"English, Slovenčina, Slovenščina, Српски / Srpski, Seeltersk, " +
"Svenska, Kiswahili, தமிழ், తెలుగు, Тоҷикӣ, ไทย, Türkmençe, Tagalog, " +
"Türkçe, Татарча/Tatarça, Українська, اردو, Tiếng Việt, Volapük, " +
"Walon, Winaray, 吴语, isiXhosa, ייִדיש, Yorùbá, Zeêuws, 中文, " +
"Bân-lâm-gú, 粵語"
if r, err := client.TestString(defaultCtx, stringTest); r != stringTest || err != nil {
t.Fatal("TestString with all languages failed")
}
specialCharacters := "quote: \" backslash:" +
" backspace: \b formfeed: \f newline: \n return: \r tab: " +
" now-all-of-them-together: '\\\b\n\r\t'" +
" now-a-bunch-of-junk: !@#$%&()(&%$#{}{}<><><" +
" char-to-test-json-parsing: ]] \"]] \\\" }}}{ [[[ "
if r, err := client.TestString(defaultCtx, specialCharacters); r != specialCharacters || err != nil {
t.Fatal("TestString with specialCharacters failed")
}
if r, err := client.TestByte(defaultCtx, 1); r != 1 || err != nil {
t.Fatal("TestByte(1) failed")
}
if r, err := client.TestByte(defaultCtx, 0); r != 0 || err != nil {
t.Fatal("TestByte(0) failed")
}
if r, err := client.TestByte(defaultCtx, -1); r != -1 || err != nil {
t.Fatal("TestByte(-1) failed")
}
if r, err := client.TestByte(defaultCtx, -127); r != -127 || err != nil {
t.Fatal("TestByte(-127) failed")
}
if r, err := client.TestI32(defaultCtx, -1); r != -1 || err != nil {
t.Fatal("TestI32(-1) failed")
}
if r, err := client.TestI32(defaultCtx, 1); r != 1 || err != nil {
t.Fatal("TestI32(1) failed")
}
if r, err := client.TestI64(defaultCtx, -5); r != -5 || err != nil {
t.Fatal("TestI64(-5) failed")
}
if r, err := client.TestI64(defaultCtx, 5); r != 5 || err != nil {
t.Fatal("TestI64(5) failed")
}
if r, err := client.TestI64(defaultCtx, -34359738368); r != -34359738368 || err != nil {
t.Fatal("TestI64(-34359738368) failed")
}
if r, err := client.TestDouble(defaultCtx, -5.2098523); r != -5.2098523 || err != nil {
t.Fatal("TestDouble(-5.2098523) failed")
}
if r, err := client.TestDouble(defaultCtx, -7.012052175215044); r != -7.012052175215044 || err != nil {
t.Fatal("TestDouble(-7.012052175215044) failed")
}
// TODO: add testBinary() call
out := thrifttest.NewXtruct()
out.StringThing = "Zero"
out.ByteThing = 1
out.I32Thing = -3
out.I64Thing = 1000000
if r, err := client.TestStruct(defaultCtx, out); !reflect.DeepEqual(r, out) || err != nil {
t.Fatal("TestStruct failed")
}
out2 := thrifttest.NewXtruct2()
out2.ByteThing = 1
out2.StructThing = out
out2.I32Thing = 5
if r, err := client.TestNest(defaultCtx, out2); !reflect.DeepEqual(r, out2) || err != nil {
t.Fatal("TestNest failed")
}
mapout := make(map[int32]int32)
for i := int32(0); i < 5; i++ {
mapout[i] = i - 10
}
if r, err := client.TestMap(defaultCtx, mapout); !reflect.DeepEqual(r, mapout) || err != nil {
t.Fatal("TestMap failed")
}
mapTestInput := map[string]string{
"a": "123", "a b": "with spaces ", "same": "same", "0": "numeric key",
"longValue": stringTest, stringTest: "long key",
}
if r, err := client.TestStringMap(defaultCtx, mapTestInput); !reflect.DeepEqual(r, mapTestInput) || err != nil {
t.Fatal("TestStringMap failed")
}
setTestInput := []int32{1, 2, 3}
if r, err := client.TestSet(defaultCtx, setTestInput); !reflect.DeepEqual(r, setTestInput) || err != nil {
t.Fatal("TestSet failed")
}
listTest := []int32{1, 2, 3}
if r, err := client.TestList(defaultCtx, listTest); !reflect.DeepEqual(r, listTest) || err != nil {
t.Fatal("TestList failed")
}
if r, err := client.TestEnum(defaultCtx, thrifttest.Numberz_ONE); r != thrifttest.Numberz_ONE || err != nil {
t.Fatal("TestEnum failed")
}
if r, err := client.TestTypedef(defaultCtx, 69); r != 69 || err != nil {
t.Fatal("TestTypedef failed")
}
mapMapTest := map[int32]map[int32]int32{
4: {1: 1, 2: 2, 3: 3, 4: 4},
-4: {-4: -4, -3: -3, -2: -2, -1: -1},
}
if r, err := client.TestMapMap(defaultCtx, 1); !reflect.DeepEqual(r, mapMapTest) || err != nil {
t.Fatal("TestMapMap failed")
}
crazyX1 := thrifttest.NewXtruct()
crazyX1.StringThing = "Goodbye4"
crazyX1.ByteThing = 4
crazyX1.I32Thing = 4
crazyX1.I64Thing = 4
crazyX2 := thrifttest.NewXtruct()
crazyX2.StringThing = "Hello2"
crazyX2.ByteThing = 2
crazyX2.I32Thing = 2
crazyX2.I64Thing = 2
crazy := thrifttest.NewInsanity()
crazy.UserMap = map[thrifttest.Numberz]thrifttest.UserId{5: 5, 8: 8}
crazy.Xtructs = []*thrifttest.Xtruct{crazyX1, crazyX2}
crazyEmpty := thrifttest.NewInsanity()
crazyEmpty.UserMap = map[thrifttest.Numberz]thrifttest.UserId{}
crazyEmpty.Xtructs = []*thrifttest.Xtruct{}
insanity := map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity{
1: {thrifttest.Numberz_TWO: crazy, thrifttest.Numberz_THREE: crazy},
2: {thrifttest.Numberz_SIX: crazyEmpty},
}
if r, err := client.TestInsanity(defaultCtx, crazy); !reflect.DeepEqual(r, insanity) || err != nil {
t.Fatal("TestInsanity failed")
}
if err := client.TestException(defaultCtx, "TException"); err == nil {
t.Fatal("TestException TException failed")
}
if err, ok := client.TestException(defaultCtx, "Xception").(*thrifttest.Xception); ok == false || err == nil {
t.Fatal("TestException Xception failed")
} else if err.ErrorCode != 1001 || err.Message != "Xception" {
t.Fatal("TestException Xception failed")
}
if err := client.TestException(defaultCtx, "no Exception"); err != nil {
t.Fatal("TestException no Exception failed")
}
if err := client.TestOneway(defaultCtx, 0); err != nil {
t.Fatal("TestOneway failed")
}
}

View file

@ -1,210 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* 'License'); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* 'AS IS' BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"context"
"errors"
"thrift"
"thrifttest"
"time"
)
type SecondServiceHandler struct {
}
func NewSecondServiceHandler() *SecondServiceHandler {
return &SecondServiceHandler{}
}
func (p *SecondServiceHandler) BlahBlah(ctx context.Context) (err error) {
return nil
}
func (p *SecondServiceHandler) SecondtestString(ctx context.Context, thing string) (r string, err error) {
return thing, nil
}
type ThriftTestHandler struct {
}
func NewThriftTestHandler() *ThriftTestHandler {
return &ThriftTestHandler{}
}
func (p *ThriftTestHandler) TestVoid(ctx context.Context) (err error) {
return nil
}
func (p *ThriftTestHandler) TestString(ctx context.Context, thing string) (r string, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestBool(ctx context.Context, thing bool) (r bool, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestByte(ctx context.Context, thing int8) (r int8, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestI32(ctx context.Context, thing int32) (r int32, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestI64(ctx context.Context, thing int64) (r int64, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestDouble(ctx context.Context, thing float64) (r float64, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestBinary(ctx context.Context, thing []byte) (r []byte, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestStruct(ctx context.Context, thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestNest(ctx context.Context, thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestMap(ctx context.Context, thing map[int32]int32) (r map[int32]int32, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestStringMap(ctx context.Context, thing map[string]string) (r map[string]string, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestSet(ctx context.Context, thing []int32) (r []int32, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestList(ctx context.Context, thing []int32) (r []int32, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestEnum(ctx context.Context, thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestTypedef(ctx context.Context, thing thrifttest.UserId) (r thrifttest.UserId, err error) {
return thing, nil
}
func (p *ThriftTestHandler) TestMapMap(ctx context.Context, hello int32) (r map[int32]map[int32]int32, err error) {
r = make(map[int32]map[int32]int32)
pos := make(map[int32]int32)
neg := make(map[int32]int32)
for i := int32(1); i < 5; i++ {
pos[i] = i
neg[-i] = -i
}
r[4] = pos
r[-4] = neg
return r, nil
}
func (p *ThriftTestHandler) TestInsanity(ctx context.Context, argument *thrifttest.Insanity) (r map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity, err error) {
hello := thrifttest.NewXtruct()
hello.StringThing = "Hello2"
hello.ByteThing = 2
hello.I32Thing = 2
hello.I64Thing = 2
goodbye := thrifttest.NewXtruct()
goodbye.StringThing = "Goodbye4"
goodbye.ByteThing = 4
goodbye.I32Thing = 4
goodbye.I64Thing = 4
crazy := thrifttest.NewInsanity()
crazy.UserMap = make(map[thrifttest.Numberz]thrifttest.UserId)
crazy.UserMap[thrifttest.Numberz_EIGHT] = 8
crazy.UserMap[thrifttest.Numberz_FIVE] = 5
crazy.Xtructs = []*thrifttest.Xtruct{goodbye, hello}
first_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
second_map := make(map[thrifttest.Numberz]*thrifttest.Insanity)
first_map[thrifttest.Numberz_TWO] = crazy
first_map[thrifttest.Numberz_THREE] = crazy
looney := thrifttest.NewInsanity()
second_map[thrifttest.Numberz_SIX] = looney
var insane = make(map[thrifttest.UserId]map[thrifttest.Numberz]*thrifttest.Insanity)
insane[1] = first_map
insane[2] = second_map
return insane, nil
}
func (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) {
r = thrifttest.NewXtruct()
r.StringThing = "Hello2"
r.ByteThing = arg0
r.I32Thing = arg1
r.I64Thing = arg2
return r, nil
}
func (p *ThriftTestHandler) TestException(ctx context.Context, arg string) (err error) {
if arg == "Xception" {
x := thrifttest.NewXception()
x.ErrorCode = 1001
x.Message = arg
return x
} else if arg == "TException" {
return thrift.TException(errors.New(arg))
} else {
return nil
}
}
func (p *ThriftTestHandler) TestMultiException(ctx context.Context, arg0 string, arg1 string) (r *thrifttest.Xtruct, err error) {
if arg0 == "Xception" {
x := thrifttest.NewXception()
x.ErrorCode = 1001
x.Message = "This is an Xception"
return nil, x
} else if arg0 == "Xception2" {
x2 := thrifttest.NewXception2()
x2.ErrorCode = 2002
x2.StructThing = thrifttest.NewXtruct()
x2.StructThing.StringThing = "This is an Xception2"
return nil, x2
}
res := thrifttest.NewXtruct()
res.StringThing = arg1
return res, nil
}
func (p *ThriftTestHandler) TestOneway(ctx context.Context, secondsToSleep int32) (err error) {
time.Sleep(time.Second * time.Duration(secondsToSleep))
return nil
}

View file

@ -1,36 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"testing"
"unionbinarytest"
)
// See https://issues.apache.org/jira/browse/THRIFT-4573
func TestUnionBinary(t *testing.T) {
s := unionbinarytest.NewSample()
s.U1 = map[string]string{}
s.U2 = []byte{}
if n := s.CountSetFieldsSample(); n != 2 {
t.Errorf("Expected 2 set fields, got %d!", n)
}
}

View file

@ -1,33 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package tests
import (
"testing"
"uniondefaultvaluetest"
)
func TestUnionDefaultValue(t *testing.T) {
s := uniondefaultvaluetest.NewTestStruct()
d := s.GetDescendant()
if d == nil {
t.Error("Default Union value not set!")
}
}