Moving from govendor to dep, updated dependencies (#48)
* Moving from govendor to dep. * Making the pull request template more friendly. * Fixing akward space in PR template. * goimports run on whole project using ` goimports -w $(find . -type f -name '*.go' -not -path "./vendor/*" -not -path "./gen-go/*")` source of command: https://gist.github.com/bgentry/fd1ffef7dbde01857f66
This commit is contained in:
parent
9631aa3aab
commit
8d445c1c77
2186 changed files with 400410 additions and 352 deletions
42
vendor/git.apache.org/thrift.git/lib/go/Makefile.am
generated
vendored
Normal file
42
vendor/git.apache.org/thrift.git/lib/go/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
#
|
||||
# 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:
|
||||
$(GO) test ./thrift
|
||||
|
||||
all-local:
|
||||
$(GO) build ./thrift
|
||||
|
||||
EXTRA_DIST = \
|
||||
thrift \
|
||||
coding_standards.md \
|
||||
README.md
|
81
vendor/git.apache.org/thrift.git/lib/go/README.md
generated
vendored
Normal file
81
vendor/git.apache.org/thrift.git/lib/go/README.md
generated
vendored
Normal file
|
@ -0,0 +1,81 @@
|
|||
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
|
||||
====================
|
||||
|
||||
In following Go conventions, we recommend you use the 'go' tool to install
|
||||
Thrift for go.
|
||||
|
||||
$ go get git.apache.org/thrift.git/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"`
|
||||
}
|
1
vendor/git.apache.org/thrift.git/lib/go/coding_standards.md
generated
vendored
Normal file
1
vendor/git.apache.org/thrift.git/lib/go/coding_standards.md
generated
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
Please follow [General Coding Standards](/doc/coding_standards.md)
|
24
vendor/git.apache.org/thrift.git/lib/go/test/BinaryKeyTest.thrift
generated
vendored
Normal file
24
vendor/git.apache.org/thrift.git/lib/go/test/BinaryKeyTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# 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
|
||||
}
|
||||
|
27
vendor/git.apache.org/thrift.git/lib/go/test/DontExportRWTest.thrift
generated
vendored
Normal file
27
vendor/git.apache.org/thrift.git/lib/go/test/DontExportRWTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# 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
|
||||
}
|
35
vendor/git.apache.org/thrift.git/lib/go/test/ErrorTest.thrift
generated
vendored
Normal file
35
vendor/git.apache.org/thrift.git/lib/go/test/ErrorTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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)
|
||||
}
|
24
vendor/git.apache.org/thrift.git/lib/go/test/GoTagTest.thrift
generated
vendored
Normal file
24
vendor/git.apache.org/thrift.git/lib/go/test/GoTagTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# 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
|
||||
}
|
26
vendor/git.apache.org/thrift.git/lib/go/test/IgnoreInitialismsTest.thrift
generated
vendored
Normal file
26
vendor/git.apache.org/thrift.git/lib/go/test/IgnoreInitialismsTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,26 @@
|
|||
#
|
||||
# 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,
|
||||
}
|
67
vendor/git.apache.org/thrift.git/lib/go/test/IncludesTest.thrift
generated
vendored
Normal file
67
vendor/git.apache.org/thrift.git/lib/go/test/IncludesTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,67 @@
|
|||
#
|
||||
# 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),
|
||||
}
|
||||
|
24
vendor/git.apache.org/thrift.git/lib/go/test/InitialismsTest.thrift
generated
vendored
Normal file
24
vendor/git.apache.org/thrift.git/lib/go/test/InitialismsTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# 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,
|
||||
}
|
103
vendor/git.apache.org/thrift.git/lib/go/test/Makefile.am
generated
vendored
Normal file
103
vendor/git.apache.org/thrift.git/lib/go/test/Makefile.am
generated
vendored
Normal file
|
@ -0,0 +1,103 @@
|
|||
#
|
||||
# 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.
|
||||
#
|
||||
|
||||
THRIFT = $(top_builddir)/compiler/cpp/thrift
|
||||
THRIFTARGS = -out gopath/src/ --gen go:thrift_import=thrift
|
||||
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 \
|
||||
ServicesTest.thrift \
|
||||
GoTagTest.thrift \
|
||||
TypedefFieldTest.thrift \
|
||||
RefAnnotationFieldsTest.thrift \
|
||||
UnionDefaultValueTest.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) ServicesTest.thrift
|
||||
$(THRIFT) $(THRIFTARGS) GoTagTest.thrift
|
||||
$(THRIFT) $(THRIFTARGS) TypedefFieldTest.thrift
|
||||
$(THRIFT) $(THRIFTARGS) RefAnnotationFieldsTest.thrift
|
||||
$(THRIFT) $(THRIFTARGS) UnionDefaultValueTest.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
|
||||
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
|
||||
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 \
|
||||
RefAnnotationFieldsTest.thrift \
|
||||
UnionDefaultValueTest.thrift \
|
||||
ServicesTest.thrift \
|
||||
TypedefFieldTest.thrift \
|
||||
ErrorTest.thrift \
|
||||
NamesTest.thrift \
|
||||
InitialismsTest.thrift \
|
||||
DontExportRWTest.thrift \
|
||||
IgnoreInitialismsTest.thrift
|
27
vendor/git.apache.org/thrift.git/lib/go/test/MultiplexedProtocolTest.thrift
generated
vendored
Normal file
27
vendor/git.apache.org/thrift.git/lib/go/test/MultiplexedProtocolTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,27 @@
|
|||
#
|
||||
# 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();
|
||||
}
|
||||
|
32
vendor/git.apache.org/thrift.git/lib/go/test/NamesTest.thrift
generated
vendored
Normal file
32
vendor/git.apache.org/thrift.git/lib/go/test/NamesTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,32 @@
|
|||
#
|
||||
# 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()
|
||||
}
|
40
vendor/git.apache.org/thrift.git/lib/go/test/NamespacedTest.thrift
generated
vendored
Normal file
40
vendor/git.apache.org/thrift.git/lib/go/test/NamespacedTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
#
|
||||
# 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(),
|
||||
}
|
||||
|
24
vendor/git.apache.org/thrift.git/lib/go/test/OnewayTest.thrift
generated
vendored
Normal file
24
vendor/git.apache.org/thrift.git/lib/go/test/OnewayTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,24 @@
|
|||
#
|
||||
# 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)
|
||||
}
|
50
vendor/git.apache.org/thrift.git/lib/go/test/OptionalFieldsTest.thrift
generated
vendored
Normal file
50
vendor/git.apache.org/thrift.git/lib/go/test/OptionalFieldsTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
#
|
||||
# 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,
|
||||
}
|
58
vendor/git.apache.org/thrift.git/lib/go/test/RefAnnotationFieldsTest.thrift
generated
vendored
Normal file
58
vendor/git.apache.org/thrift.git/lib/go/test/RefAnnotationFieldsTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,58 @@
|
|||
#
|
||||
# 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
|
||||
}
|
111
vendor/git.apache.org/thrift.git/lib/go/test/ServicesTest.thrift
generated
vendored
Normal file
111
vendor/git.apache.org/thrift.git/lib/go/test/ServicesTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,111 @@
|
|||
#
|
||||
# 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)
|
||||
|
||||
}
|
39
vendor/git.apache.org/thrift.git/lib/go/test/TypedefFieldTest.thrift
generated
vendored
Normal file
39
vendor/git.apache.org/thrift.git/lib/go/test/TypedefFieldTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
#
|
||||
# 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
|
||||
}
|
34
vendor/git.apache.org/thrift.git/lib/go/test/UnionDefaultValueTest.thrift
generated
vendored
Normal file
34
vendor/git.apache.org/thrift.git/lib/go/test/UnionDefaultValueTest.thrift
generated
vendored
Normal file
|
@ -0,0 +1,34 @@
|
|||
#
|
||||
# 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": {}}
|
||||
}
|
38
vendor/git.apache.org/thrift.git/lib/go/test/dontexportrwtest/compile_test.go
generated
vendored
Normal file
38
vendor/git.apache.org/thrift.git/lib/go/test/dontexportrwtest/compile_test.go
generated
vendored
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*
|
||||
* 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 (
|
||||
"fmt"
|
||||
"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()
|
||||
fmt.Sprintf("%v", s.read)
|
||||
fmt.Sprintf("%v", s.write)
|
||||
|
||||
is := NewInnerStruct()
|
||||
fmt.Sprintf("%v", is.read)
|
||||
fmt.Sprintf("%v", is.write)
|
||||
}
|
31
vendor/git.apache.org/thrift.git/lib/go/test/tests/binary_key_test.go
generated
vendored
Normal file
31
vendor/git.apache.org/thrift.git/lib/go/test/tests/binary_key_test.go
generated
vendored
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
* 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)
|
||||
}
|
680
vendor/git.apache.org/thrift.git/lib/go/test/tests/client_error_test.go
generated
vendored
Normal file
680
vendor/git.apache.org/thrift.git/lib/go/test/tests/client_error_test.go
generated
vendored
Normal file
|
@ -0,0 +1,680 @@
|
|||
/*
|
||||
* 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 (
|
||||
"github.com/golang/mock/gomock"
|
||||
"errors"
|
||||
"errortest"
|
||||
"testing"
|
||||
"thrift"
|
||||
)
|
||||
|
||||
// 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().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)
|
||||
transport := thrift.NewTMemoryBuffer()
|
||||
|
||||
thing := errortest.NewTestStruct()
|
||||
thing.M = make(map[string]string)
|
||||
thing.L = make([]string, 0)
|
||||
thing.S = make(map[string]struct{})
|
||||
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(thing)
|
||||
mockCtrl.Finish()
|
||||
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)
|
||||
transport := thrift.NewTMemoryBuffer()
|
||||
|
||||
thing := errortest.NewTestStruct()
|
||||
thing.M = make(map[string]string)
|
||||
thing.L = make([]string, 0)
|
||||
thing.S = make(map[string]struct{})
|
||||
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(thing)
|
||||
mockCtrl.Finish()
|
||||
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().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)
|
||||
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("test")
|
||||
mockCtrl.Finish()
|
||||
|
||||
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)
|
||||
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(),
|
||||
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.REPLY, int32(2), nil),
|
||||
)
|
||||
|
||||
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
|
||||
_, err := client.TestString("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)
|
||||
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(),
|
||||
protocol.EXPECT().ReadMessageBegin().Return("unknown", thrift.REPLY, int32(1), nil),
|
||||
)
|
||||
|
||||
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
|
||||
_, err := client.TestString("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)
|
||||
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(),
|
||||
protocol.EXPECT().ReadMessageBegin().Return("testString", thrift.INVALID_TMESSAGE_TYPE, int32(1), nil),
|
||||
)
|
||||
|
||||
client := errortest.NewErrorTestClientProtocol(transport, protocol, protocol)
|
||||
_, err := client.TestString("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")
|
||||
}
|
||||
}
|
79
vendor/git.apache.org/thrift.git/lib/go/test/tests/encoding_json_test.go
generated
vendored
Normal file
79
vendor/git.apache.org/thrift.git/lib/go/test/tests/encoding_json_test.go
generated
vendored
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* 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")
|
||||
}
|
||||
}
|
53
vendor/git.apache.org/thrift.git/lib/go/test/tests/gotag_test.go
generated
vendored
Normal file
53
vendor/git.apache.org/thrift.git/lib/go/test/tests/gotag_test.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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")
|
||||
}
|
||||
}
|
51
vendor/git.apache.org/thrift.git/lib/go/test/tests/ignoreinitialisms_test.go
generated
vendored
Normal file
51
vendor/git.apache.org/thrift.git/lib/go/test/tests/ignoreinitialisms_test.go
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
/*
|
||||
* 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!")
|
||||
}
|
||||
}
|
43
vendor/git.apache.org/thrift.git/lib/go/test/tests/initialisms_test.go
generated
vendored
Normal file
43
vendor/git.apache.org/thrift.git/lib/go/test/tests/initialisms_test.go
generated
vendored
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* 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!")
|
||||
}
|
||||
}
|
159
vendor/git.apache.org/thrift.git/lib/go/test/tests/multiplexed_protocol_test.go
generated
vendored
Normal file
159
vendor/git.apache.org/thrift.git/lib/go/test/tests/multiplexed_protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,159 @@
|
|||
/*
|
||||
* 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 (
|
||||
"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() (r int64, err error) {
|
||||
return 1, nil
|
||||
}
|
||||
|
||||
type SecondImpl struct{}
|
||||
|
||||
func (s *SecondImpl) ReturnTwo() (r int64, err error) {
|
||||
return 2, nil
|
||||
}
|
||||
|
||||
var processor = thrift.NewTMultiplexedProcessor()
|
||||
|
||||
func TestInitTwoServers(t *testing.T) {
|
||||
var err error
|
||||
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)
|
||||
|
||||
go server.Serve()
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
}
|
||||
|
||||
var firstClient *multiplexedprotocoltest.FirstClient
|
||||
|
||||
func TestInitClient1(t *testing.T) {
|
||||
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
|
||||
transport := thrift.NewTFramedTransport(socket)
|
||||
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
|
||||
protocol = thrift.NewTMultiplexedProtocol(protocol, "FirstService")
|
||||
firstClient = multiplexedprotocoltest.NewFirstClientProtocol(transport, protocol, protocol)
|
||||
err := transport.Open()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to open client socket", err)
|
||||
}
|
||||
}
|
||||
|
||||
var secondClient *multiplexedprotocoltest.SecondClient
|
||||
|
||||
func TestInitClient2(t *testing.T) {
|
||||
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
|
||||
transport := thrift.NewTFramedTransport(socket)
|
||||
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
|
||||
protocol = thrift.NewTMultiplexedProtocol(protocol, "SecondService")
|
||||
secondClient = multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
|
||||
err := transport.Open()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to open client socket", err)
|
||||
}
|
||||
}
|
||||
|
||||
//create client without service prefix
|
||||
func createLegacyClient(t *testing.T) *multiplexedprotocoltest.SecondClient {
|
||||
socket := thrift.NewTSocketFromAddrTimeout(addr, TIMEOUT)
|
||||
transport := thrift.NewTFramedTransport(socket)
|
||||
var protocol thrift.TProtocol = thrift.NewTBinaryProtocolTransport(transport)
|
||||
legacyClient := multiplexedprotocoltest.NewSecondClientProtocol(transport, protocol, protocol)
|
||||
err := transport.Open()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to open client socket", err)
|
||||
}
|
||||
return legacyClient
|
||||
}
|
||||
|
||||
func TestCallFirst(t *testing.T) {
|
||||
ret, err := firstClient.ReturnOne()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to call first server:", err)
|
||||
}
|
||||
if ret != 1 {
|
||||
t.Fatal("Unexpected result from server: ", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallSecond(t *testing.T) {
|
||||
ret, err := secondClient.ReturnTwo()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to call second server:", err)
|
||||
}
|
||||
if ret != 2 {
|
||||
t.Fatal("Unexpected result from server: ", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCallLegacy(t *testing.T) {
|
||||
legacyClient := createLegacyClient(t)
|
||||
ret, err := legacyClient.ReturnTwo()
|
||||
//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{}))
|
||||
legacyClient = createLegacyClient(t)
|
||||
ret, err = legacyClient.ReturnTwo()
|
||||
if err != nil {
|
||||
t.Fatal("Unable to call legacy server:", err)
|
||||
}
|
||||
if ret != 2 {
|
||||
t.Fatal("Unexpected result from server: ", ret)
|
||||
}
|
||||
}
|
||||
|
||||
func TestShutdownServerAndClients(t *testing.T) {
|
||||
firstClient.Transport.Close()
|
||||
secondClient.Transport.Close()
|
||||
server.Stop()
|
||||
}
|
35
vendor/git.apache.org/thrift.git/lib/go/test/tests/names_test.go
generated
vendored
Normal file
35
vendor/git.apache.org/thrift.git/lib/go/test/tests/names_test.go
generated
vendored
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*
|
||||
* 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!")
|
||||
}
|
||||
}
|
90
vendor/git.apache.org/thrift.git/lib/go/test/tests/one_way_test.go
generated
vendored
Normal file
90
vendor/git.apache.org/thrift.git/lib/go/test/tests/one_way_test.go
generated
vendored
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*
|
||||
* 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 (
|
||||
"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(in int64, s string) (err error) { fmt.Println("Hi!"); return }
|
||||
func (i *impl) Emptyfunc() (err error) { return }
|
||||
func (i *impl) EchoInt(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.NewOneWayClientProtocol(transport, 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(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(42)
|
||||
if err != nil {
|
||||
t.Fatal("Unexpected error: ", err)
|
||||
}
|
||||
if i != 42 {
|
||||
t.Fatal("Unexpected returned value: ", i)
|
||||
}
|
||||
}
|
280
vendor/git.apache.org/thrift.git/lib/go/test/tests/optional_fields_test.go
generated
vendored
Normal file
280
vendor/git.apache.org/thrift.git/lib/go/test/tests/optional_fields_test.go
generated
vendored
Normal file
|
@ -0,0 +1,280 @@
|
|||
/*
|
||||
* 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)
|
||||
}
|
511
vendor/git.apache.org/thrift.git/lib/go/test/tests/protocol_mock.go
generated
vendored
Normal file
511
vendor/git.apache.org/thrift.git/lib/go/test/tests/protocol_mock.go
generated
vendored
Normal file
|
@ -0,0 +1,511 @@
|
|||
/*
|
||||
* 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 (
|
||||
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() error {
|
||||
ret := _m.ctrl.Call(_m, "Flush")
|
||||
ret0, _ := ret[0].(error)
|
||||
return ret0
|
||||
}
|
||||
|
||||
func (_mr *_MockTProtocolRecorder) Flush() *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")
|
||||
}
|
94
vendor/git.apache.org/thrift.git/lib/go/test/tests/protocols_test.go
generated
vendored
Normal file
94
vendor/git.apache.org/thrift.git/lib/go/test/tests/protocols_test.go
generated
vendored
Normal file
|
@ -0,0 +1,94 @@
|
|||
/*
|
||||
* 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 = transportFactory.GetTransport(transport)
|
||||
var protocol thrift.TProtocol = protocolFactory.GetProtocol(transport)
|
||||
thriftTestClient := thrifttest.NewThriftTestClientProtocol(transport, 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()))
|
||||
}
|
95
vendor/git.apache.org/thrift.git/lib/go/test/tests/required_fields_test.go
generated
vendored
Normal file
95
vendor/git.apache.org/thrift.git/lib/go/test/tests/required_fields_test.go
generated
vendored
Normal file
|
@ -0,0 +1,95 @@
|
|||
/*
|
||||
* 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 (
|
||||
"github.com/golang/mock/gomock"
|
||||
"optionalfieldstest"
|
||||
"testing"
|
||||
"thrift"
|
||||
)
|
||||
|
||||
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()
|
||||
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()
|
||||
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")
|
||||
}
|
||||
}
|
36
vendor/git.apache.org/thrift.git/lib/go/test/tests/struct_args_rets_test.go
generated
vendored
Normal file
36
vendor/git.apache.org/thrift.git/lib/go/test/tests/struct_args_rets_test.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* 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(sa)
|
||||
_ = err
|
||||
_ = sa
|
||||
}
|
236
vendor/git.apache.org/thrift.git/lib/go/test/tests/thrifttest_driver.go
generated
vendored
Normal file
236
vendor/git.apache.org/thrift.git/lib/go/test/tests/thrifttest_driver.go
generated
vendored
Normal file
|
@ -0,0 +1,236 @@
|
|||
/*
|
||||
* 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() != nil {
|
||||
t.Fatal("TestVoid failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestString("Test"); r != "Test" || err != nil {
|
||||
t.Fatal("TestString with simple text failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestString(""); 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(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(specialCharacters); r != specialCharacters || err != nil {
|
||||
t.Fatal("TestString with specialCharacters failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestByte(1); r != 1 || err != nil {
|
||||
t.Fatal("TestByte(1) failed")
|
||||
}
|
||||
if r, err := client.TestByte(0); r != 0 || err != nil {
|
||||
t.Fatal("TestByte(0) failed")
|
||||
}
|
||||
if r, err := client.TestByte(-1); r != -1 || err != nil {
|
||||
t.Fatal("TestByte(-1) failed")
|
||||
}
|
||||
if r, err := client.TestByte(-127); r != -127 || err != nil {
|
||||
t.Fatal("TestByte(-127) failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestI32(-1); r != -1 || err != nil {
|
||||
t.Fatal("TestI32(-1) failed")
|
||||
}
|
||||
if r, err := client.TestI32(1); r != 1 || err != nil {
|
||||
t.Fatal("TestI32(1) failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestI64(-5); r != -5 || err != nil {
|
||||
t.Fatal("TestI64(-5) failed")
|
||||
}
|
||||
if r, err := client.TestI64(5); r != 5 || err != nil {
|
||||
t.Fatal("TestI64(5) failed")
|
||||
}
|
||||
if r, err := client.TestI64(-34359738368); r != -34359738368 || err != nil {
|
||||
t.Fatal("TestI64(-34359738368) failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestDouble(-5.2098523); r != -5.2098523 || err != nil {
|
||||
t.Fatal("TestDouble(-5.2098523) failed")
|
||||
}
|
||||
if r, err := client.TestDouble(-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(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(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(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(mapTestInput); !reflect.DeepEqual(r, mapTestInput) || err != nil {
|
||||
t.Fatal("TestStringMap failed")
|
||||
}
|
||||
|
||||
setTestInput := map[int32]struct{}{1: {}, 2: {}, 3: {}}
|
||||
if r, err := client.TestSet(setTestInput); !reflect.DeepEqual(r, setTestInput) || err != nil {
|
||||
t.Fatal("TestSet failed")
|
||||
}
|
||||
|
||||
listTest := []int32{1, 2, 3}
|
||||
if r, err := client.TestList(listTest); !reflect.DeepEqual(r, listTest) || err != nil {
|
||||
t.Fatal("TestList failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestEnum(thrifttest.Numberz_ONE); r != thrifttest.Numberz_ONE || err != nil {
|
||||
t.Fatal("TestEnum failed")
|
||||
}
|
||||
|
||||
if r, err := client.TestTypedef(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(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(crazy); !reflect.DeepEqual(r, insanity) || err != nil {
|
||||
t.Fatal("TestInsanity failed")
|
||||
}
|
||||
|
||||
if err := client.TestException("TException"); err == nil {
|
||||
t.Fatal("TestException TException failed")
|
||||
}
|
||||
|
||||
if err, ok := client.TestException("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("no Exception"); err != nil {
|
||||
t.Fatal("TestException no Exception failed")
|
||||
}
|
||||
|
||||
if err := client.TestOneway(0); err != nil {
|
||||
t.Fatal("TestOneway failed")
|
||||
}
|
||||
}
|
209
vendor/git.apache.org/thrift.git/lib/go/test/tests/thrifttest_handler.go
generated
vendored
Normal file
209
vendor/git.apache.org/thrift.git/lib/go/test/tests/thrifttest_handler.go
generated
vendored
Normal file
|
@ -0,0 +1,209 @@
|
|||
/*
|
||||
* 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 (
|
||||
"errors"
|
||||
"thrift"
|
||||
"thrifttest"
|
||||
"time"
|
||||
)
|
||||
|
||||
type SecondServiceHandler struct {
|
||||
}
|
||||
|
||||
func NewSecondServiceHandler() *SecondServiceHandler {
|
||||
return &SecondServiceHandler{}
|
||||
}
|
||||
|
||||
func (p *SecondServiceHandler) BlahBlah() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *SecondServiceHandler) SecondtestString(thing string) (r string, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
type ThriftTestHandler struct {
|
||||
}
|
||||
|
||||
func NewThriftTestHandler() *ThriftTestHandler {
|
||||
return &ThriftTestHandler{}
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestVoid() (err error) {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestString(thing string) (r string, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestBool(thing bool) (r bool, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestByte(thing int8) (r int8, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestI32(thing int32) (r int32, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestI64(thing int64) (r int64, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestDouble(thing float64) (r float64, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestBinary(thing []byte) (r []byte, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestStruct(thing *thrifttest.Xtruct) (r *thrifttest.Xtruct, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestNest(thing *thrifttest.Xtruct2) (r *thrifttest.Xtruct2, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestSet(thing map[int32]struct{}) (r map[int32]struct{}, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestList(thing []int32) (r []int32, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestEnum(thing thrifttest.Numberz) (r thrifttest.Numberz, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestTypedef(thing thrifttest.UserId) (r thrifttest.UserId, err error) {
|
||||
return thing, nil
|
||||
}
|
||||
|
||||
func (p *ThriftTestHandler) TestMapMap(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(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(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(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(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(secondsToSleep int32) (err error) {
|
||||
time.Sleep(time.Second * time.Duration(secondsToSleep))
|
||||
return nil
|
||||
}
|
33
vendor/git.apache.org/thrift.git/lib/go/test/tests/union_default_value_test.go
generated
vendored
Normal file
33
vendor/git.apache.org/thrift.git/lib/go/test/tests/union_default_value_test.go
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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!")
|
||||
}
|
||||
}
|
41
vendor/git.apache.org/thrift.git/lib/go/thrift/application_exception_test.go
generated
vendored
Normal file
41
vendor/git.apache.org/thrift.git/lib/go/thrift/application_exception_test.go
generated
vendored
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestTApplicationException(t *testing.T) {
|
||||
exc := NewTApplicationException(UNKNOWN_APPLICATION_EXCEPTION, "")
|
||||
if exc.Error() != "" {
|
||||
t.Fatalf("Expected empty string for exception but found '%s'", exc.Error())
|
||||
}
|
||||
if exc.TypeId() != UNKNOWN_APPLICATION_EXCEPTION {
|
||||
t.Fatalf("Expected type UNKNOWN for exception but found '%s'", exc.TypeId())
|
||||
}
|
||||
exc = NewTApplicationException(WRONG_METHOD_NAME, "junk_method")
|
||||
if exc.Error() != "junk_method" {
|
||||
t.Fatalf("Expected 'junk_method' for exception but found '%s'", exc.Error())
|
||||
}
|
||||
if exc.TypeId() != WRONG_METHOD_NAME {
|
||||
t.Fatalf("Expected type WRONG_METHOD_NAME for exception but found '%s'", exc.TypeId())
|
||||
}
|
||||
}
|
28
vendor/git.apache.org/thrift.git/lib/go/thrift/binary_protocol_test.go
generated
vendored
Normal file
28
vendor/git.apache.org/thrift.git/lib/go/thrift/binary_protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadWriteBinaryProtocol(t *testing.T) {
|
||||
ReadWriteProtocolTest(t, NewTBinaryProtocolFactoryDefault())
|
||||
}
|
29
vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport_test.go
generated
vendored
Normal file
29
vendor/git.apache.org/thrift.git/lib/go/thrift/buffered_transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestBufferedTransport(t *testing.T) {
|
||||
trans := NewTBufferedTransport(NewTMemoryBuffer(), 10240)
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
53
vendor/git.apache.org/thrift.git/lib/go/thrift/compact_protocol_test.go
generated
vendored
Normal file
53
vendor/git.apache.org/thrift.git/lib/go/thrift/compact_protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestReadWriteCompactProtocol(t *testing.T) {
|
||||
ReadWriteProtocolTest(t, NewTCompactProtocolFactory())
|
||||
transports := []TTransport{
|
||||
NewTMemoryBuffer(),
|
||||
NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 16384))),
|
||||
NewTFramedTransport(NewTMemoryBuffer()),
|
||||
}
|
||||
for _, trans := range transports {
|
||||
p := NewTCompactProtocol(trans);
|
||||
ReadWriteBool(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteByte(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteI16(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteI32(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteI64(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteDouble(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteString(t, p, trans);
|
||||
p = NewTCompactProtocol(trans);
|
||||
ReadWriteBinary(t, p, trans);
|
||||
trans.Close();
|
||||
}
|
||||
}
|
69
vendor/git.apache.org/thrift.git/lib/go/thrift/exception_test.go
generated
vendored
Normal file
69
vendor/git.apache.org/thrift.git/lib/go/thrift/exception_test.go
generated
vendored
Normal file
|
@ -0,0 +1,69 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestPrependError(t *testing.T) {
|
||||
err := NewTApplicationException(INTERNAL_ERROR, "original error")
|
||||
err2, ok := PrependError("Prepend: ", err).(TApplicationException)
|
||||
if !ok {
|
||||
t.Fatal("Couldn't cast error TApplicationException")
|
||||
}
|
||||
if err2.Error() != "Prepend: original error" {
|
||||
t.Fatal("Unexpected error string")
|
||||
}
|
||||
if err2.TypeId() != INTERNAL_ERROR {
|
||||
t.Fatal("Unexpected type error")
|
||||
}
|
||||
|
||||
err3 := NewTProtocolExceptionWithType(INVALID_DATA, errors.New("original error"))
|
||||
err4, ok := PrependError("Prepend: ", err3).(TProtocolException)
|
||||
if !ok {
|
||||
t.Fatal("Couldn't cast error TProtocolException")
|
||||
}
|
||||
if err4.Error() != "Prepend: original error" {
|
||||
t.Fatal("Unexpected error string")
|
||||
}
|
||||
if err4.TypeId() != INVALID_DATA {
|
||||
t.Fatal("Unexpected type error")
|
||||
}
|
||||
|
||||
err5 := NewTTransportException(TIMED_OUT, "original error")
|
||||
err6, ok := PrependError("Prepend: ", err5).(TTransportException)
|
||||
if !ok {
|
||||
t.Fatal("Couldn't cast error TTransportException")
|
||||
}
|
||||
if err6.Error() != "Prepend: original error" {
|
||||
t.Fatal("Unexpected error string")
|
||||
}
|
||||
if err6.TypeId() != TIMED_OUT {
|
||||
t.Fatal("Unexpected type error")
|
||||
}
|
||||
|
||||
err7 := errors.New("original error")
|
||||
err8 := PrependError("Prepend: ", err7)
|
||||
if err8.Error() != "Prepend: original error" {
|
||||
t.Fatal("Unexpected error string")
|
||||
}
|
||||
}
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport.go
generated
vendored
|
@ -48,7 +48,7 @@ func NewTFramedTransportFactory(factory TTransportFactory) TTransportFactory {
|
|||
}
|
||||
|
||||
func NewTFramedTransportFactoryMaxLength(factory TTransportFactory, maxLength uint32) TTransportFactory {
|
||||
return &tFramedTransportFactory{factory: factory, maxLength: maxLength}
|
||||
return &tFramedTransportFactory{factory: factory, maxLength: maxLength}
|
||||
}
|
||||
|
||||
func (p *tFramedTransportFactory) GetTransport(base TTransport) TTransport {
|
||||
|
@ -164,3 +164,4 @@ func (p *TFramedTransport) readFrameHeader() (uint32, error) {
|
|||
func (p *TFramedTransport) RemainingBytes() (num_bytes uint64) {
|
||||
return uint64(p.frameSize)
|
||||
}
|
||||
|
||||
|
|
29
vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport_test.go
generated
vendored
Normal file
29
vendor/git.apache.org/thrift.git/lib/go/thrift/framed_transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFramedTransport(t *testing.T) {
|
||||
trans := NewTFramedTransport(NewTMemoryBuffer())
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
106
vendor/git.apache.org/thrift.git/lib/go/thrift/http_client_test.go
generated
vendored
Normal file
106
vendor/git.apache.org/thrift.git/lib/go/thrift/http_client_test.go
generated
vendored
Normal file
|
@ -0,0 +1,106 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestHttpClient(t *testing.T) {
|
||||
l, addr := HttpClientSetupForTest(t)
|
||||
if l != nil {
|
||||
defer l.Close()
|
||||
}
|
||||
trans, err := NewTHttpPostClient("http://" + addr.String())
|
||||
if err != nil {
|
||||
l.Close()
|
||||
t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
|
||||
}
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
||||
|
||||
func TestHttpClientHeaders(t *testing.T) {
|
||||
l, addr := HttpClientSetupForTest(t)
|
||||
if l != nil {
|
||||
defer l.Close()
|
||||
}
|
||||
trans, err := NewTHttpPostClient("http://" + addr.String())
|
||||
if err != nil {
|
||||
l.Close()
|
||||
t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
|
||||
}
|
||||
TransportHeaderTest(t, trans, trans)
|
||||
}
|
||||
|
||||
func TestHttpCustomClient(t *testing.T) {
|
||||
l, addr := HttpClientSetupForTest(t)
|
||||
if l != nil {
|
||||
defer l.Close()
|
||||
}
|
||||
|
||||
httpTransport := &customHttpTransport{}
|
||||
|
||||
trans, err := NewTHttpPostClientWithOptions("http://"+addr.String(), THttpClientOptions{
|
||||
Client: &http.Client{
|
||||
Transport: httpTransport,
|
||||
},
|
||||
})
|
||||
if err != nil {
|
||||
l.Close()
|
||||
t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
|
||||
}
|
||||
TransportHeaderTest(t, trans, trans)
|
||||
|
||||
if !httpTransport.hit {
|
||||
t.Fatalf("Custom client was not used")
|
||||
}
|
||||
}
|
||||
|
||||
func TestHttpCustomClientPackageScope(t *testing.T) {
|
||||
l, addr := HttpClientSetupForTest(t)
|
||||
if l != nil {
|
||||
defer l.Close()
|
||||
}
|
||||
httpTransport := &customHttpTransport{}
|
||||
DefaultHttpClient = &http.Client{
|
||||
Transport: httpTransport,
|
||||
}
|
||||
|
||||
trans, err := NewTHttpPostClient("http://" + addr.String())
|
||||
if err != nil {
|
||||
l.Close()
|
||||
t.Fatalf("Unable to connect to %s: %s", addr.String(), err)
|
||||
}
|
||||
TransportHeaderTest(t, trans, trans)
|
||||
|
||||
if !httpTransport.hit {
|
||||
t.Fatalf("Custom client was not used")
|
||||
}
|
||||
}
|
||||
|
||||
type customHttpTransport struct {
|
||||
hit bool
|
||||
}
|
||||
|
||||
func (c *customHttpTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
c.hit = true
|
||||
return http.DefaultTransport.RoundTrip(req)
|
||||
}
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport.go
generated
vendored
|
@ -209,5 +209,6 @@ func (p *StreamTransport) WriteString(s string) (n int, err error) {
|
|||
|
||||
func (p *StreamTransport) RemainingBytes() (num_bytes uint64) {
|
||||
const maxSize = ^uint64(0)
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
}
|
||||
|
||||
|
|
52
vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport_test.go
generated
vendored
Normal file
52
vendor/git.apache.org/thrift.git/lib/go/thrift/iostream_transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,52 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestStreamTransport(t *testing.T) {
|
||||
trans := NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 1024)))
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
||||
|
||||
func TestStreamTransportOpenClose(t *testing.T) {
|
||||
trans := NewStreamTransportRW(bytes.NewBuffer(make([]byte, 0, 1024)))
|
||||
if !trans.IsOpen() {
|
||||
t.Fatal("StreamTransport should be already open")
|
||||
}
|
||||
if trans.Open() == nil {
|
||||
t.Fatal("StreamTransport should return error when open twice")
|
||||
}
|
||||
if trans.Close() != nil {
|
||||
t.Fatal("StreamTransport should not return error when closing open transport")
|
||||
}
|
||||
if trans.IsOpen() {
|
||||
t.Fatal("StreamTransport should not be open after close")
|
||||
}
|
||||
if trans.Close() == nil {
|
||||
t.Fatal("StreamTransport should return error when closing a non open transport")
|
||||
}
|
||||
if trans.Open() == nil {
|
||||
t.Fatal("StreamTransport should not be able to reopen")
|
||||
}
|
||||
}
|
649
vendor/git.apache.org/thrift.git/lib/go/thrift/json_protocol_test.go
generated
vendored
Normal file
649
vendor/git.apache.org/thrift.git/lib/go/thrift/json_protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,649 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteJSONProtocolBool(t *testing.T) {
|
||||
thetype := "boolean"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range BOOL_VALUES {
|
||||
if e := p.WriteBool(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
expected := ""
|
||||
if value {
|
||||
expected = "1"
|
||||
} else {
|
||||
expected = "0"
|
||||
}
|
||||
if s != expected {
|
||||
t.Fatalf("Bad value for %s %v: %s expected", thetype, value, s)
|
||||
}
|
||||
v := -1
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || (v != 0) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolBool(t *testing.T) {
|
||||
thetype := "boolean"
|
||||
for _, value := range BOOL_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
if value {
|
||||
trans.Write([]byte{'1'}) // not JSON_TRUE
|
||||
} else {
|
||||
trans.Write([]byte{'0'}) // not JSON_FALSE
|
||||
}
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadBool()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
vv := -1
|
||||
if err := json.Unmarshal([]byte(s), &vv); err != nil || (vv != 0) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, vv)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolByte(t *testing.T) {
|
||||
thetype := "byte"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range BYTE_VALUES {
|
||||
if e := p.WriteByte(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int8(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolByte(t *testing.T) {
|
||||
thetype := "byte"
|
||||
for _, value := range BYTE_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadByte()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolI16(t *testing.T) {
|
||||
thetype := "int16"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range INT16_VALUES {
|
||||
if e := p.WriteI16(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int16(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolI16(t *testing.T) {
|
||||
thetype := "int16"
|
||||
for _, value := range INT16_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI16()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolI32(t *testing.T) {
|
||||
thetype := "int32"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range INT32_VALUES {
|
||||
if e := p.WriteI32(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int32(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolI32(t *testing.T) {
|
||||
thetype := "int32"
|
||||
for _, value := range INT32_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI32()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolI64(t *testing.T) {
|
||||
thetype := "int64"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range INT64_VALUES {
|
||||
if e := p.WriteI64(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolI64(t *testing.T) {
|
||||
thetype := "int64"
|
||||
for _, value := range INT64_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(strconv.FormatInt(value, 10))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI64()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolDouble(t *testing.T) {
|
||||
thetype := "double"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if math.IsInf(value, 1) {
|
||||
if s != jsonQuote(JSON_INFINITY) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_INFINITY))
|
||||
}
|
||||
} else if math.IsInf(value, -1) {
|
||||
if s != jsonQuote(JSON_NEGATIVE_INFINITY) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_NEGATIVE_INFINITY))
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s != jsonQuote(JSON_NAN) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_NAN))
|
||||
}
|
||||
} else {
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := float64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolDouble(t *testing.T) {
|
||||
thetype := "double"
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
n := NewNumericFromDouble(value)
|
||||
trans.WriteString(n.String())
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadDouble()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if math.IsInf(value, 1) {
|
||||
if !math.IsInf(v, 1) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else if math.IsInf(value, -1) {
|
||||
if !math.IsInf(v, -1) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if !math.IsNaN(v) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else {
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolString(t *testing.T) {
|
||||
thetype := "string"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
for _, value := range STRING_VALUES {
|
||||
if e := p.WriteString(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s[0] != '"' || s[len(s)-1] != '"' {
|
||||
t.Fatalf("Bad value for %s '%v', wrote '%v', expected: %v", thetype, value, s, fmt.Sprint("\"", value, "\""))
|
||||
}
|
||||
v := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v); err != nil || *v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolString(t *testing.T) {
|
||||
thetype := "string"
|
||||
for _, value := range STRING_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(jsonQuote(value))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadString()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
v1 := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v1); err != nil || *v1 != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v1)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolBinary(t *testing.T) {
|
||||
thetype := "binary"
|
||||
value := protocol_bdata
|
||||
b64value := make([]byte, base64.StdEncoding.EncodedLen(len(protocol_bdata)))
|
||||
base64.StdEncoding.Encode(b64value, value)
|
||||
b64String := string(b64value)
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
if e := p.WriteBinary(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
expectedString := fmt.Sprint("\"", b64String, "\"")
|
||||
if s != expectedString {
|
||||
t.Fatalf("Bad value for %s %v\n wrote: \"%v\"\nexpected: \"%v\"", thetype, value, s, expectedString)
|
||||
}
|
||||
v1, err := p.ReadBinary()
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to read binary: %s", err.Error())
|
||||
}
|
||||
if len(v1) != len(value) {
|
||||
t.Fatalf("Invalid value for binary\nexpected: \"%v\"\n read: \"%v\"", value, v1)
|
||||
}
|
||||
for k, v := range value {
|
||||
if v1[k] != v {
|
||||
t.Fatalf("Invalid value for binary at %v\nexpected: \"%v\"\n read: \"%v\"", k, v, v1[k])
|
||||
}
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadJSONProtocolBinary(t *testing.T) {
|
||||
thetype := "binary"
|
||||
value := protocol_bdata
|
||||
b64value := make([]byte, base64.StdEncoding.EncodedLen(len(protocol_bdata)))
|
||||
base64.StdEncoding.Encode(b64value, value)
|
||||
b64String := string(b64value)
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
trans.WriteString(jsonQuote(b64String))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadBinary()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if len(v) != len(value) {
|
||||
t.Fatalf("Bad value for %s value length %v, wrote: %v, received length: %v", thetype, len(value), s, len(v))
|
||||
}
|
||||
for i := 0; i < len(v); i++ {
|
||||
if v[i] != value[i] {
|
||||
t.Fatalf("Bad value for %s at index %d value %v, wrote: %v, received: %v", thetype, i, value[i], s, v[i])
|
||||
}
|
||||
}
|
||||
v1 := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v1); err != nil || *v1 != b64String {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v1)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolList(t *testing.T) {
|
||||
thetype := "list"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
p.WriteListBegin(TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteListEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
str1 := new([]interface{})
|
||||
err := json.Unmarshal([]byte(str), str1)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
|
||||
}
|
||||
l := *str1
|
||||
if len(l) < 2 {
|
||||
t.Fatalf("List must be at least of length two to include metadata")
|
||||
}
|
||||
if l[0] != "dbl" {
|
||||
t.Fatal("Invalid type for list, expected: ", STRING, ", but was: ", l[0])
|
||||
}
|
||||
if int(l[1].(float64)) != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Invalid length for list, expected: ", len(DOUBLE_VALUES), ", but was: ", l[1])
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
s := l[k+2]
|
||||
if math.IsInf(value, 1) {
|
||||
if s.(string) != JSON_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_INFINITY), str)
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if s.(string) != JSON_NEGATIVE_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY), str)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s.(string) != JSON_NAN {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NAN), str)
|
||||
}
|
||||
} else {
|
||||
if s.(float64) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s'", thetype, value, s)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolSet(t *testing.T) {
|
||||
thetype := "set"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
p.WriteSetBegin(TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteSetEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
str1 := new([]interface{})
|
||||
err := json.Unmarshal([]byte(str), str1)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
|
||||
}
|
||||
l := *str1
|
||||
if len(l) < 2 {
|
||||
t.Fatalf("Set must be at least of length two to include metadata")
|
||||
}
|
||||
if l[0] != "dbl" {
|
||||
t.Fatal("Invalid type for set, expected: ", DOUBLE, ", but was: ", l[0])
|
||||
}
|
||||
if int(l[1].(float64)) != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Invalid length for set, expected: ", len(DOUBLE_VALUES), ", but was: ", l[1])
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
s := l[k+2]
|
||||
if math.IsInf(value, 1) {
|
||||
if s.(string) != JSON_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_INFINITY), str)
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if s.(string) != JSON_NEGATIVE_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY), str)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s.(string) != JSON_NAN {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NAN), str)
|
||||
}
|
||||
} else {
|
||||
if s.(float64) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s'", thetype, value, s)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteJSONProtocolMap(t *testing.T) {
|
||||
thetype := "map"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTJSONProtocol(trans)
|
||||
p.WriteMapBegin(TType(I32), TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteI32(int32(k)); e != nil {
|
||||
t.Fatalf("Unable to write %s key int32 value %v due to error: %s", thetype, k, e.Error())
|
||||
}
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value float64 value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteMapEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
if str[0] != '[' || str[len(str)-1] != ']' {
|
||||
t.Fatalf("Bad value for %s, wrote: %q, in go: %q", thetype, str, DOUBLE_VALUES)
|
||||
}
|
||||
expectedKeyType, expectedValueType, expectedSize, err := p.ReadMapBegin()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while reading map begin: %s", err.Error())
|
||||
}
|
||||
if expectedKeyType != I32 {
|
||||
t.Fatal("Expected map key type ", I32, ", but was ", expectedKeyType)
|
||||
}
|
||||
if expectedValueType != DOUBLE {
|
||||
t.Fatal("Expected map value type ", DOUBLE, ", but was ", expectedValueType)
|
||||
}
|
||||
if expectedSize != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Expected map size of ", len(DOUBLE_VALUES), ", but was ", expectedSize)
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
ik, err := p.ReadI32()
|
||||
if err != nil {
|
||||
t.Fatalf("Bad key for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, ik, string(k), err.Error())
|
||||
}
|
||||
if int(ik) != k {
|
||||
t.Fatalf("Bad key for %s index %v, wrote: %v, expected: %v", thetype, k, ik, k)
|
||||
}
|
||||
dv, err := p.ReadDouble()
|
||||
if err != nil {
|
||||
t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, dv, value, err.Error())
|
||||
}
|
||||
s := strconv.FormatFloat(dv, 'g', 10, 64)
|
||||
if math.IsInf(value, 1) {
|
||||
if !math.IsInf(dv, 1) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_INFINITY))
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if !math.IsInf(dv, 0) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY))
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if !math.IsNaN(dv) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NAN))
|
||||
}
|
||||
} else {
|
||||
expected := strconv.FormatFloat(value, 'g', 10, 64)
|
||||
if s != expected {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected %v", thetype, k, value, s, expected)
|
||||
}
|
||||
v := float64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
err = p.ReadMapEnd()
|
||||
if err != nil {
|
||||
t.Fatalf("Error while reading map end: %s", err.Error())
|
||||
}
|
||||
trans.Close()
|
||||
}
|
396
vendor/git.apache.org/thrift.git/lib/go/thrift/lowlevel_benchmarks_test.go
generated
vendored
Normal file
396
vendor/git.apache.org/thrift.git/lib/go/thrift/lowlevel_benchmarks_test.go
generated
vendored
Normal file
|
@ -0,0 +1,396 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var binaryProtoF = NewTBinaryProtocolFactoryDefault()
|
||||
var compactProtoF = NewTCompactProtocolFactory()
|
||||
|
||||
var buf = bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
var tfv = []TTransportFactory{
|
||||
NewTMemoryBufferTransportFactory(1024),
|
||||
NewStreamTransportFactory(buf, buf, true),
|
||||
NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)),
|
||||
}
|
||||
|
||||
func BenchmarkBinaryBool_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryByte_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI16_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI32_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryI64_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryDouble_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryString_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryBinary_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryBool_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryByte_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI16_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI32_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryI64_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryDouble_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryString_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryBinary_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryBool_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryByte_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI16_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkBinaryI32_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryI64_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryDouble_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryString_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkBinaryBinary_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := binaryProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactBool_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactByte_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI16_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI32_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactI64_0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactDouble0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactString0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactBinary0(b *testing.B) {
|
||||
trans := tfv[0].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactBool_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactByte_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI16_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI32_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactI64_1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactDouble1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactString1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactBinary1(b *testing.B) {
|
||||
trans := tfv[1].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactBool_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBool(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactByte_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteByte(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI16_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI16(b, p, trans)
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkCompactI32_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI32(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactI64_2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteI64(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactDouble2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteDouble(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactString2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteString(b, p, trans)
|
||||
}
|
||||
}
|
||||
func BenchmarkCompactBinary2(b *testing.B) {
|
||||
trans := tfv[2].GetTransport(nil)
|
||||
p := compactProtoF.GetProtocol(trans)
|
||||
for i := 0; i < b.N; i++ {
|
||||
ReadWriteBinary(b, p, trans)
|
||||
}
|
||||
}
|
29
vendor/git.apache.org/thrift.git/lib/go/thrift/memory_buffer_test.go
generated
vendored
Normal file
29
vendor/git.apache.org/thrift.git/lib/go/thrift/memory_buffer_test.go
generated
vendored
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestMemoryBuffer(t *testing.T) {
|
||||
trans := NewTMemoryBufferLen(1024)
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
9
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol.go
generated
vendored
9
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol.go
generated
vendored
|
@ -21,7 +21,6 @@ package thrift
|
|||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -89,9 +88,9 @@ func SkipDefaultDepth(prot TProtocol, typeId TType) (err error) {
|
|||
|
||||
// Skips over the next data element from the provided input TProtocol object.
|
||||
func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
|
||||
|
||||
if maxDepth <= 0 {
|
||||
return NewTProtocolExceptionWithType(DEPTH_LIMIT, errors.New("Depth limit exceeded"))
|
||||
|
||||
if maxDepth <= 0 {
|
||||
return NewTProtocolExceptionWithType( DEPTH_LIMIT, errors.New("Depth limit exceeded"))
|
||||
}
|
||||
|
||||
switch fieldType {
|
||||
|
@ -171,8 +170,6 @@ func Skip(self TProtocol, fieldType TType, maxDepth int) (err error) {
|
|||
}
|
||||
}
|
||||
return self.ReadListEnd()
|
||||
default:
|
||||
return NewTProtocolExceptionWithType(INVALID_DATA, errors.New(fmt.Sprintf("Unknown data type %d", fieldType)))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_exception.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_exception.go
generated
vendored
|
@ -60,7 +60,7 @@ func NewTProtocolException(err error) TProtocolException {
|
|||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if e, ok := err.(TProtocolException); ok {
|
||||
if e,ok := err.(TProtocolException); ok {
|
||||
return e
|
||||
}
|
||||
if _, ok := err.(base64.CorruptInputError); ok {
|
||||
|
@ -75,3 +75,4 @@ func NewTProtocolExceptionWithType(errType int, err error) TProtocolException {
|
|||
}
|
||||
return &tProtocolException{errType, err.Error()}
|
||||
}
|
||||
|
||||
|
|
479
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_test.go
generated
vendored
Normal file
479
vendor/git.apache.org/thrift.git/lib/go/thrift/protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,479 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io/ioutil"
|
||||
"math"
|
||||
"net"
|
||||
"net/http"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const PROTOCOL_BINARY_DATA_SIZE = 155
|
||||
|
||||
var (
|
||||
data string // test data for writing
|
||||
protocol_bdata []byte // test data for writing; same as data
|
||||
BOOL_VALUES []bool
|
||||
BYTE_VALUES []int8
|
||||
INT16_VALUES []int16
|
||||
INT32_VALUES []int32
|
||||
INT64_VALUES []int64
|
||||
DOUBLE_VALUES []float64
|
||||
STRING_VALUES []string
|
||||
)
|
||||
|
||||
func init() {
|
||||
protocol_bdata = make([]byte, PROTOCOL_BINARY_DATA_SIZE)
|
||||
for i := 0; i < PROTOCOL_BINARY_DATA_SIZE; i++ {
|
||||
protocol_bdata[i] = byte((i + 'a') % 255)
|
||||
}
|
||||
data = string(protocol_bdata)
|
||||
BOOL_VALUES = []bool{false, true, false, false, true}
|
||||
BYTE_VALUES = []int8{117, 0, 1, 32, 127, -128, -1}
|
||||
INT16_VALUES = []int16{459, 0, 1, -1, -128, 127, 32767, -32768}
|
||||
INT32_VALUES = []int32{459, 0, 1, -1, -128, 127, 32767, 2147483647, -2147483535}
|
||||
INT64_VALUES = []int64{459, 0, 1, -1, -128, 127, 32767, 2147483647, -2147483535, 34359738481, -35184372088719, -9223372036854775808, 9223372036854775807}
|
||||
DOUBLE_VALUES = []float64{459.3, 0.0, -1.0, 1.0, 0.5, 0.3333, 3.14159, 1.537e-38, 1.673e25, 6.02214179e23, -6.02214179e23, INFINITY.Float64(), NEGATIVE_INFINITY.Float64(), NAN.Float64()}
|
||||
STRING_VALUES = []string{"", "a", "st[uf]f", "st,u:ff with spaces", "stuff\twith\nescape\\characters'...\"lots{of}fun</xml>"}
|
||||
}
|
||||
|
||||
type HTTPEchoServer struct{}
|
||||
type HTTPHeaderEchoServer struct{}
|
||||
|
||||
func (p *HTTPEchoServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
buf, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(buf)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *HTTPHeaderEchoServer) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
buf, err := ioutil.ReadAll(req.Body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
w.Write(buf)
|
||||
} else {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write(buf)
|
||||
}
|
||||
}
|
||||
|
||||
func HttpClientSetupForTest(t *testing.T) (net.Listener, net.Addr) {
|
||||
addr, err := FindAvailableTCPServerPort(40000)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to find available tcp port addr: %s", err)
|
||||
return nil, addr
|
||||
}
|
||||
l, err := net.Listen(addr.Network(), addr.String())
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
|
||||
return l, addr
|
||||
}
|
||||
go http.Serve(l, &HTTPEchoServer{})
|
||||
return l, addr
|
||||
}
|
||||
|
||||
func HttpClientSetupForHeaderTest(t *testing.T) (net.Listener, net.Addr) {
|
||||
addr, err := FindAvailableTCPServerPort(40000)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to find available tcp port addr: %s", err)
|
||||
return nil, addr
|
||||
}
|
||||
l, err := net.Listen(addr.Network(), addr.String())
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to setup tcp listener on %s: %s", addr.String(), err)
|
||||
return l, addr
|
||||
}
|
||||
go http.Serve(l, &HTTPHeaderEchoServer{})
|
||||
return l, addr
|
||||
}
|
||||
|
||||
func ReadWriteProtocolTest(t *testing.T, protocolFactory TProtocolFactory) {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
l, addr := HttpClientSetupForTest(t)
|
||||
defer l.Close()
|
||||
transports := []TTransportFactory{
|
||||
NewTMemoryBufferTransportFactory(1024),
|
||||
NewStreamTransportFactory(buf, buf, true),
|
||||
NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)),
|
||||
NewTHttpPostClientTransportFactory("http://" + addr.String()),
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteBool(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteByte(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteI16(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteI32(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteI64(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteDouble(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteString(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteBinary(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
p := protocolFactory.GetProtocol(trans)
|
||||
ReadWriteI64(t, p, trans)
|
||||
ReadWriteDouble(t, p, trans)
|
||||
ReadWriteBinary(t, p, trans)
|
||||
ReadWriteByte(t, p, trans)
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteBool(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(BOOL)
|
||||
thelen := len(BOOL_VALUES)
|
||||
err := p.WriteListBegin(thetype, thelen)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing list begin: %q", "ReadWriteBool", p, trans, err, thetype)
|
||||
}
|
||||
for k, v := range BOOL_VALUES {
|
||||
err = p.WriteBool(v)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing bool in list at index %d: %q", "ReadWriteBool", p, trans, err, k, v)
|
||||
}
|
||||
}
|
||||
p.WriteListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteBool", p, trans, err, BOOL_VALUES)
|
||||
}
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteBool", p, trans, err, BOOL_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteBool", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteBool", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range BOOL_VALUES {
|
||||
value, err := p.ReadBool()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading bool at index %d: %q", "ReadWriteBool", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: index %d %q %q %q != %q", "ReadWriteBool", k, p, trans, v, value)
|
||||
}
|
||||
}
|
||||
err = p.ReadListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteBool", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteByte(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(BYTE)
|
||||
thelen := len(BYTE_VALUES)
|
||||
err := p.WriteListBegin(thetype, thelen)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing list begin: %q", "ReadWriteByte", p, trans, err, thetype)
|
||||
}
|
||||
for k, v := range BYTE_VALUES {
|
||||
err = p.WriteByte(v)
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing byte in list at index %d: %q", "ReadWriteByte", p, trans, err, k, v)
|
||||
}
|
||||
}
|
||||
err = p.WriteListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
|
||||
}
|
||||
err = p.Flush()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error flushing list of bytes: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
|
||||
}
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteByte", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteByte", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range BYTE_VALUES {
|
||||
value, err := p.ReadByte()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading byte at index %d: %q", "ReadWriteByte", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: %T %T %d != %d", "ReadWriteByte", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
err = p.ReadListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteByte", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteI16(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(I16)
|
||||
thelen := len(INT16_VALUES)
|
||||
p.WriteListBegin(thetype, thelen)
|
||||
for _, v := range INT16_VALUES {
|
||||
p.WriteI16(v)
|
||||
}
|
||||
p.WriteListEnd()
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI16", p, trans, err, INT16_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI16", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteI16", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range INT16_VALUES {
|
||||
value, err := p.ReadI16()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading int16 at index %d: %q", "ReadWriteI16", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: %T %T %d != %d", "ReadWriteI16", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
err = p.ReadListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI16", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteI32(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(I32)
|
||||
thelen := len(INT32_VALUES)
|
||||
p.WriteListBegin(thetype, thelen)
|
||||
for _, v := range INT32_VALUES {
|
||||
p.WriteI32(v)
|
||||
}
|
||||
p.WriteListEnd()
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI32", p, trans, err, INT32_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI32", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteI32", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range INT32_VALUES {
|
||||
value, err := p.ReadI32()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading int32 at index %d: %q", "ReadWriteI32", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: %T %T %d != %d", "ReadWriteI32", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI32", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteI64(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(I64)
|
||||
thelen := len(INT64_VALUES)
|
||||
p.WriteListBegin(thetype, thelen)
|
||||
for _, v := range INT64_VALUES {
|
||||
p.WriteI64(v)
|
||||
}
|
||||
p.WriteListEnd()
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI64", p, trans, err, INT64_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteI64", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteI64", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range INT64_VALUES {
|
||||
value, err := p.ReadI64()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading int64 at index %d: %q", "ReadWriteI64", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: %T %T %q != %q", "ReadWriteI64", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteI64", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteDouble(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(DOUBLE)
|
||||
thelen := len(DOUBLE_VALUES)
|
||||
p.WriteListBegin(thetype, thelen)
|
||||
for _, v := range DOUBLE_VALUES {
|
||||
p.WriteDouble(v)
|
||||
}
|
||||
p.WriteListEnd()
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteDouble", p, trans, err, DOUBLE_VALUES)
|
||||
}
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteDouble", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteDouble", p, trans, thelen, thelen2)
|
||||
}
|
||||
for k, v := range DOUBLE_VALUES {
|
||||
value, err := p.ReadDouble()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading double at index %d: %q", "ReadWriteDouble", p, trans, err, k, v)
|
||||
}
|
||||
if math.IsNaN(v) {
|
||||
if !math.IsNaN(value) {
|
||||
t.Errorf("%s: %T %T math.IsNaN(%q) != math.IsNaN(%q)", "ReadWriteDouble", p, trans, v, value)
|
||||
}
|
||||
} else if v != value {
|
||||
t.Errorf("%s: %T %T %v != %q", "ReadWriteDouble", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
err = p.ReadListEnd()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteDouble", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteString(t testing.TB, p TProtocol, trans TTransport) {
|
||||
thetype := TType(STRING)
|
||||
thelen := len(STRING_VALUES)
|
||||
p.WriteListBegin(thetype, thelen)
|
||||
for _, v := range STRING_VALUES {
|
||||
p.WriteString(v)
|
||||
}
|
||||
p.WriteListEnd()
|
||||
p.Flush()
|
||||
thetype2, thelen2, err := p.ReadListBegin()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteString", p, trans, err, STRING_VALUES)
|
||||
}
|
||||
_, ok := p.(*TSimpleJSONProtocol)
|
||||
if !ok {
|
||||
if thetype != thetype2 {
|
||||
t.Errorf("%s: %T %T type %s != type %s", "ReadWriteString", p, trans, thetype, thetype2)
|
||||
}
|
||||
if thelen != thelen2 {
|
||||
t.Errorf("%s: %T %T len %s != len %s", "ReadWriteString", p, trans, thelen, thelen2)
|
||||
}
|
||||
}
|
||||
for k, v := range STRING_VALUES {
|
||||
value, err := p.ReadString()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T %q Error reading string at index %d: %q", "ReadWriteString", p, trans, err, k, v)
|
||||
}
|
||||
if v != value {
|
||||
t.Errorf("%s: %T %T %d != %d", "ReadWriteString", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read list end: %q", "ReadWriteString", p, trans, err)
|
||||
}
|
||||
}
|
||||
|
||||
func ReadWriteBinary(t testing.TB, p TProtocol, trans TTransport) {
|
||||
v := protocol_bdata
|
||||
p.WriteBinary(v)
|
||||
p.Flush()
|
||||
value, err := p.ReadBinary()
|
||||
if err != nil {
|
||||
t.Errorf("%s: %T %T Unable to read binary: %s", "ReadWriteBinary", p, trans, err.Error())
|
||||
}
|
||||
if len(v) != len(value) {
|
||||
t.Errorf("%s: %T %T len(v) != len(value)... %d != %d", "ReadWriteBinary", p, trans, len(v), len(value))
|
||||
} else {
|
||||
for i := 0; i < len(v); i++ {
|
||||
if v[i] != value[i] {
|
||||
t.Errorf("%s: %T %T %s != %s", "ReadWriteBinary", p, trans, v, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
1
vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport.go
generated
vendored
1
vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport.go
generated
vendored
|
@ -66,3 +66,4 @@ func writeByte(w io.Writer, c byte) error {
|
|||
_, err := w.Write(v[0:1])
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
85
vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport_test.go
generated
vendored
Normal file
85
vendor/git.apache.org/thrift.git/lib/go/thrift/rich_transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,85 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"io"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestEnsureTransportsAreRich(t *testing.T) {
|
||||
buf := bytes.NewBuffer(make([]byte, 0, 1024))
|
||||
|
||||
transports := []TTransportFactory{
|
||||
NewTMemoryBufferTransportFactory(1024),
|
||||
NewStreamTransportFactory(buf, buf, true),
|
||||
NewTFramedTransportFactory(NewTMemoryBufferTransportFactory(1024)),
|
||||
NewTHttpPostClientTransportFactory("http://127.0.0.1"),
|
||||
}
|
||||
for _, tf := range transports {
|
||||
trans := tf.GetTransport(nil)
|
||||
_, ok := trans.(TRichTransport)
|
||||
if !ok {
|
||||
t.Errorf("Transport %s does not implement TRichTransport interface", reflect.ValueOf(trans))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TestReadByte tests whether readByte handles error cases correctly.
|
||||
func TestReadByte(t *testing.T) {
|
||||
for i, test := range readByteTests {
|
||||
v, err := readByte(test.r)
|
||||
if v != test.v {
|
||||
t.Fatalf("TestReadByte %d: value differs. Expected %d, got %d", i, test.v, test.r.v)
|
||||
}
|
||||
if err != test.err {
|
||||
t.Fatalf("TestReadByte %d: error differs. Expected %s, got %s", i, test.err, test.r.err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var someError = errors.New("Some error")
|
||||
var readByteTests = []struct {
|
||||
r *mockReader
|
||||
v byte
|
||||
err error
|
||||
}{
|
||||
{&mockReader{0, 55, io.EOF}, 0, io.EOF}, // reader sends EOF w/o data
|
||||
{&mockReader{0, 55, someError}, 0, someError}, // reader sends some other error
|
||||
{&mockReader{1, 55, nil}, 55, nil}, // reader sends data w/o error
|
||||
{&mockReader{1, 55, io.EOF}, 55, nil}, // reader sends data with EOF
|
||||
{&mockReader{1, 55, someError}, 55, someError}, // reader sends data withsome error
|
||||
}
|
||||
|
||||
type mockReader struct {
|
||||
n int
|
||||
v byte
|
||||
err error
|
||||
}
|
||||
|
||||
func (r *mockReader) Read(p []byte) (n int, err error) {
|
||||
if r.n > 0 {
|
||||
p[0] = r.v
|
||||
}
|
||||
return r.n, r.err
|
||||
}
|
169
vendor/git.apache.org/thrift.git/lib/go/thrift/serializer_test.go
generated
vendored
Normal file
169
vendor/git.apache.org/thrift.git/lib/go/thrift/serializer_test.go
generated
vendored
Normal file
|
@ -0,0 +1,169 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type ProtocolFactory interface {
|
||||
GetProtocol(t TTransport) TProtocol
|
||||
}
|
||||
|
||||
func compareStructs(m, m1 MyTestStruct) (bool, error) {
|
||||
switch {
|
||||
case m.On != m1.On:
|
||||
return false, errors.New("Boolean not equal")
|
||||
case m.B != m1.B:
|
||||
return false, errors.New("Byte not equal")
|
||||
case m.Int16 != m1.Int16:
|
||||
return false, errors.New("Int16 not equal")
|
||||
case m.Int32 != m1.Int32:
|
||||
return false, errors.New("Int32 not equal")
|
||||
case m.Int64 != m1.Int64:
|
||||
return false, errors.New("Int64 not equal")
|
||||
case m.D != m1.D:
|
||||
return false, errors.New("Double not equal")
|
||||
case m.St != m1.St:
|
||||
return false, errors.New("String not equal")
|
||||
|
||||
case len(m.Bin) != len(m1.Bin):
|
||||
return false, errors.New("Binary size not equal")
|
||||
case len(m.Bin) == len(m1.Bin):
|
||||
for i := range m.Bin {
|
||||
if m.Bin[i] != m1.Bin[i] {
|
||||
return false, errors.New("Binary not equal")
|
||||
}
|
||||
}
|
||||
case len(m.StringMap) != len(m1.StringMap):
|
||||
return false, errors.New("StringMap size not equal")
|
||||
case len(m.StringList) != len(m1.StringList):
|
||||
return false, errors.New("StringList size not equal")
|
||||
case len(m.StringSet) != len(m1.StringSet):
|
||||
return false, errors.New("StringSet size not equal")
|
||||
|
||||
case m.E != m1.E:
|
||||
return false, errors.New("MyTestEnum not equal")
|
||||
|
||||
default:
|
||||
return true, nil
|
||||
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func ProtocolTest1(test *testing.T, pf ProtocolFactory) (bool, error) {
|
||||
t := NewTSerializer()
|
||||
t.Protocol = pf.GetProtocol(t.Transport)
|
||||
var m = MyTestStruct{}
|
||||
m.On = true
|
||||
m.B = int8(0)
|
||||
m.Int16 = 1
|
||||
m.Int32 = 2
|
||||
m.Int64 = 3
|
||||
m.D = 4.1
|
||||
m.St = "Test"
|
||||
m.Bin = make([]byte, 10)
|
||||
m.StringMap = make(map[string]string, 5)
|
||||
m.StringList = make([]string, 5)
|
||||
m.StringSet = make(map[string]struct{}, 5)
|
||||
m.E = 2
|
||||
|
||||
s, err := t.WriteString(&m)
|
||||
if err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err))
|
||||
}
|
||||
|
||||
t1 := NewTDeserializer()
|
||||
t1.Protocol = pf.GetProtocol(t1.Transport)
|
||||
var m1 = MyTestStruct{}
|
||||
if err = t1.ReadString(&m1, s); err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Unable to Deserialize struct\n\t %s", err))
|
||||
|
||||
}
|
||||
|
||||
return compareStructs(m, m1)
|
||||
|
||||
}
|
||||
|
||||
func ProtocolTest2(test *testing.T, pf ProtocolFactory) (bool, error) {
|
||||
t := NewTSerializer()
|
||||
t.Protocol = pf.GetProtocol(t.Transport)
|
||||
var m = MyTestStruct{}
|
||||
m.On = false
|
||||
m.B = int8(0)
|
||||
m.Int16 = 1
|
||||
m.Int32 = 2
|
||||
m.Int64 = 3
|
||||
m.D = 4.1
|
||||
m.St = "Test"
|
||||
m.Bin = make([]byte, 10)
|
||||
m.StringMap = make(map[string]string, 5)
|
||||
m.StringList = make([]string, 5)
|
||||
m.StringSet = make(map[string]struct{}, 5)
|
||||
m.E = 2
|
||||
|
||||
s, err := t.WriteString(&m)
|
||||
if err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Unable to Serialize struct\n\t %s", err))
|
||||
|
||||
}
|
||||
|
||||
t1 := NewTDeserializer()
|
||||
t1.Protocol = pf.GetProtocol(t1.Transport)
|
||||
var m1 = MyTestStruct{}
|
||||
if err = t1.ReadString(&m1, s); err != nil {
|
||||
return false, errors.New(fmt.Sprintf("Unable to Deserialize struct\n\t %s", err))
|
||||
|
||||
}
|
||||
|
||||
return compareStructs(m, m1)
|
||||
|
||||
}
|
||||
|
||||
func TestSerializer(t *testing.T) {
|
||||
|
||||
var protocol_factories map[string]ProtocolFactory
|
||||
protocol_factories = make(map[string]ProtocolFactory)
|
||||
protocol_factories["Binary"] = NewTBinaryProtocolFactoryDefault()
|
||||
protocol_factories["Compact"] = NewTCompactProtocolFactory()
|
||||
//protocol_factories["SimpleJSON"] = NewTSimpleJSONProtocolFactory() - write only, can't be read back by design
|
||||
protocol_factories["JSON"] = NewTJSONProtocolFactory()
|
||||
|
||||
var tests map[string]func(*testing.T, ProtocolFactory) (bool, error)
|
||||
tests = make(map[string]func(*testing.T, ProtocolFactory) (bool, error))
|
||||
tests["Test 1"] = ProtocolTest1
|
||||
tests["Test 2"] = ProtocolTest2
|
||||
//tests["Test 3"] = ProtocolTest3 // Example of how to add additional tests
|
||||
|
||||
for name, pf := range protocol_factories {
|
||||
|
||||
for test, f := range tests {
|
||||
|
||||
if s, err := f(t, pf); !s || err != nil {
|
||||
t.Errorf("%s Failed for %s protocol\n\t %s", test, name, err)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
633
vendor/git.apache.org/thrift.git/lib/go/thrift/serializer_types_test.go
generated
vendored
Normal file
633
vendor/git.apache.org/thrift.git/lib/go/thrift/serializer_types_test.go
generated
vendored
Normal file
|
@ -0,0 +1,633 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
// Autogenerated by Thrift Compiler (1.0.0-dev)
|
||||
// DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
|
||||
/* THE FOLLOWING THRIFT FILE WAS USED TO CREATE THIS
|
||||
|
||||
enum MyTestEnum {
|
||||
FIRST = 1,
|
||||
SECOND = 2,
|
||||
THIRD = 3,
|
||||
FOURTH = 4,
|
||||
}
|
||||
|
||||
struct MyTestStruct {
|
||||
1: bool on,
|
||||
2: byte b,
|
||||
3: i16 int16,
|
||||
4: i32 int32,
|
||||
5: i64 int64,
|
||||
6: double d,
|
||||
7: string st,
|
||||
8: binary bin,
|
||||
9: map<string, string> stringMap,
|
||||
10: list<string> stringList,
|
||||
11: set<string> stringSet,
|
||||
12: MyTestEnum e,
|
||||
}
|
||||
*/
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// (needed to ensure safety because of naive import list construction.)
|
||||
var _ = ZERO
|
||||
var _ = fmt.Printf
|
||||
|
||||
var GoUnusedProtection__ int
|
||||
|
||||
type MyTestEnum int64
|
||||
|
||||
const (
|
||||
MyTestEnum_FIRST MyTestEnum = 1
|
||||
MyTestEnum_SECOND MyTestEnum = 2
|
||||
MyTestEnum_THIRD MyTestEnum = 3
|
||||
MyTestEnum_FOURTH MyTestEnum = 4
|
||||
)
|
||||
|
||||
func (p MyTestEnum) String() string {
|
||||
switch p {
|
||||
case MyTestEnum_FIRST:
|
||||
return "FIRST"
|
||||
case MyTestEnum_SECOND:
|
||||
return "SECOND"
|
||||
case MyTestEnum_THIRD:
|
||||
return "THIRD"
|
||||
case MyTestEnum_FOURTH:
|
||||
return "FOURTH"
|
||||
}
|
||||
return "<UNSET>"
|
||||
}
|
||||
|
||||
func MyTestEnumFromString(s string) (MyTestEnum, error) {
|
||||
switch s {
|
||||
case "FIRST":
|
||||
return MyTestEnum_FIRST, nil
|
||||
case "SECOND":
|
||||
return MyTestEnum_SECOND, nil
|
||||
case "THIRD":
|
||||
return MyTestEnum_THIRD, nil
|
||||
case "FOURTH":
|
||||
return MyTestEnum_FOURTH, nil
|
||||
}
|
||||
return MyTestEnum(0), fmt.Errorf("not a valid MyTestEnum string")
|
||||
}
|
||||
|
||||
func MyTestEnumPtr(v MyTestEnum) *MyTestEnum { return &v }
|
||||
|
||||
type MyTestStruct struct {
|
||||
On bool `thrift:"on,1" json:"on"`
|
||||
B int8 `thrift:"b,2" json:"b"`
|
||||
Int16 int16 `thrift:"int16,3" json:"int16"`
|
||||
Int32 int32 `thrift:"int32,4" json:"int32"`
|
||||
Int64 int64 `thrift:"int64,5" json:"int64"`
|
||||
D float64 `thrift:"d,6" json:"d"`
|
||||
St string `thrift:"st,7" json:"st"`
|
||||
Bin []byte `thrift:"bin,8" json:"bin"`
|
||||
StringMap map[string]string `thrift:"stringMap,9" json:"stringMap"`
|
||||
StringList []string `thrift:"stringList,10" json:"stringList"`
|
||||
StringSet map[string]struct{} `thrift:"stringSet,11" json:"stringSet"`
|
||||
E MyTestEnum `thrift:"e,12" json:"e"`
|
||||
}
|
||||
|
||||
func NewMyTestStruct() *MyTestStruct {
|
||||
return &MyTestStruct{}
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetOn() bool {
|
||||
return p.On
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetB() int8 {
|
||||
return p.B
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetInt16() int16 {
|
||||
return p.Int16
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetInt32() int32 {
|
||||
return p.Int32
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetInt64() int64 {
|
||||
return p.Int64
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetD() float64 {
|
||||
return p.D
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetSt() string {
|
||||
return p.St
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetBin() []byte {
|
||||
return p.Bin
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetStringMap() map[string]string {
|
||||
return p.StringMap
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetStringList() []string {
|
||||
return p.StringList
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetStringSet() map[string]struct{} {
|
||||
return p.StringSet
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) GetE() MyTestEnum {
|
||||
return p.E
|
||||
}
|
||||
func (p *MyTestStruct) Read(iprot TProtocol) error {
|
||||
if _, err := iprot.ReadStructBegin(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T read error: ", p), err)
|
||||
}
|
||||
for {
|
||||
_, fieldTypeId, fieldId, err := iprot.ReadFieldBegin()
|
||||
if err != nil {
|
||||
return PrependError(fmt.Sprintf("%T field %d read error: ", p, fieldId), err)
|
||||
}
|
||||
if fieldTypeId == STOP {
|
||||
break
|
||||
}
|
||||
switch fieldId {
|
||||
case 1:
|
||||
if err := p.readField1(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 2:
|
||||
if err := p.readField2(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 3:
|
||||
if err := p.readField3(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 4:
|
||||
if err := p.readField4(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 5:
|
||||
if err := p.readField5(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 6:
|
||||
if err := p.readField6(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 7:
|
||||
if err := p.readField7(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 8:
|
||||
if err := p.readField8(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 9:
|
||||
if err := p.readField9(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 10:
|
||||
if err := p.readField10(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 11:
|
||||
if err := p.readField11(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
case 12:
|
||||
if err := p.readField12(iprot); err != nil {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
if err := iprot.Skip(fieldTypeId); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := iprot.ReadFieldEnd(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := iprot.ReadStructEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T read struct end error: ", p), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField1(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadBool(); err != nil {
|
||||
return PrependError("error reading field 1: ", err)
|
||||
} else {
|
||||
p.On = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField2(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadByte(); err != nil {
|
||||
return PrependError("error reading field 2: ", err)
|
||||
} else {
|
||||
temp := int8(v)
|
||||
p.B = temp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField3(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadI16(); err != nil {
|
||||
return PrependError("error reading field 3: ", err)
|
||||
} else {
|
||||
p.Int16 = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField4(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadI32(); err != nil {
|
||||
return PrependError("error reading field 4: ", err)
|
||||
} else {
|
||||
p.Int32 = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField5(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadI64(); err != nil {
|
||||
return PrependError("error reading field 5: ", err)
|
||||
} else {
|
||||
p.Int64 = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField6(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadDouble(); err != nil {
|
||||
return PrependError("error reading field 6: ", err)
|
||||
} else {
|
||||
p.D = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField7(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return PrependError("error reading field 7: ", err)
|
||||
} else {
|
||||
p.St = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField8(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadBinary(); err != nil {
|
||||
return PrependError("error reading field 8: ", err)
|
||||
} else {
|
||||
p.Bin = v
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField9(iprot TProtocol) error {
|
||||
_, _, size, err := iprot.ReadMapBegin()
|
||||
if err != nil {
|
||||
return PrependError("error reading map begin: ", err)
|
||||
}
|
||||
tMap := make(map[string]string, size)
|
||||
p.StringMap = tMap
|
||||
for i := 0; i < size; i++ {
|
||||
var _key0 string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return PrependError("error reading field 0: ", err)
|
||||
} else {
|
||||
_key0 = v
|
||||
}
|
||||
var _val1 string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return PrependError("error reading field 0: ", err)
|
||||
} else {
|
||||
_val1 = v
|
||||
}
|
||||
p.StringMap[_key0] = _val1
|
||||
}
|
||||
if err := iprot.ReadMapEnd(); err != nil {
|
||||
return PrependError("error reading map end: ", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField10(iprot TProtocol) error {
|
||||
_, size, err := iprot.ReadListBegin()
|
||||
if err != nil {
|
||||
return PrependError("error reading list begin: ", err)
|
||||
}
|
||||
tSlice := make([]string, 0, size)
|
||||
p.StringList = tSlice
|
||||
for i := 0; i < size; i++ {
|
||||
var _elem2 string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return PrependError("error reading field 0: ", err)
|
||||
} else {
|
||||
_elem2 = v
|
||||
}
|
||||
p.StringList = append(p.StringList, _elem2)
|
||||
}
|
||||
if err := iprot.ReadListEnd(); err != nil {
|
||||
return PrependError("error reading list end: ", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField11(iprot TProtocol) error {
|
||||
_, size, err := iprot.ReadSetBegin()
|
||||
if err != nil {
|
||||
return PrependError("error reading set begin: ", err)
|
||||
}
|
||||
tSet := make(map[string]struct{}, size)
|
||||
p.StringSet = tSet
|
||||
for i := 0; i < size; i++ {
|
||||
var _elem3 string
|
||||
if v, err := iprot.ReadString(); err != nil {
|
||||
return PrependError("error reading field 0: ", err)
|
||||
} else {
|
||||
_elem3 = v
|
||||
}
|
||||
p.StringSet[_elem3] = struct{}{}
|
||||
}
|
||||
if err := iprot.ReadSetEnd(); err != nil {
|
||||
return PrependError("error reading set end: ", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) readField12(iprot TProtocol) error {
|
||||
if v, err := iprot.ReadI32(); err != nil {
|
||||
return PrependError("error reading field 12: ", err)
|
||||
} else {
|
||||
temp := MyTestEnum(v)
|
||||
p.E = temp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) Write(oprot TProtocol) error {
|
||||
if err := oprot.WriteStructBegin("MyTestStruct"); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write struct begin error: ", p), err)
|
||||
}
|
||||
if err := p.writeField1(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField2(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField3(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField4(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField5(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField6(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField7(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField8(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField9(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField10(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField11(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := p.writeField12(oprot); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := oprot.WriteFieldStop(); err != nil {
|
||||
return PrependError("write field stop error: ", err)
|
||||
}
|
||||
if err := oprot.WriteStructEnd(); err != nil {
|
||||
return PrependError("write struct stop error: ", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField1(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("on", BOOL, 1); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 1:on: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteBool(bool(p.On)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.on (1) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 1:on: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField2(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("b", BYTE, 2); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 2:b: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteByte(int8(p.B)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.b (2) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 2:b: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField3(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("int16", I16, 3); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 3:int16: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteI16(int16(p.Int16)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.int16 (3) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 3:int16: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField4(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("int32", I32, 4); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 4:int32: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteI32(int32(p.Int32)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.int32 (4) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 4:int32: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField5(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("int64", I64, 5); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 5:int64: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteI64(int64(p.Int64)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.int64 (5) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 5:int64: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField6(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("d", DOUBLE, 6); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 6:d: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteDouble(float64(p.D)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.d (6) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 6:d: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField7(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("st", STRING, 7); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 7:st: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteString(string(p.St)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.st (7) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 7:st: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField8(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("bin", STRING, 8); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 8:bin: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteBinary(p.Bin); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.bin (8) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 8:bin: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField9(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("stringMap", MAP, 9); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 9:stringMap: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteMapBegin(STRING, STRING, len(p.StringMap)); err != nil {
|
||||
return PrependError("error writing map begin: ", err)
|
||||
}
|
||||
for k, v := range p.StringMap {
|
||||
if err := oprot.WriteString(string(k)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteString(string(v)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
|
||||
}
|
||||
}
|
||||
if err := oprot.WriteMapEnd(); err != nil {
|
||||
return PrependError("error writing map end: ", err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 9:stringMap: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField10(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("stringList", LIST, 10); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 10:stringList: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteListBegin(STRING, len(p.StringList)); err != nil {
|
||||
return PrependError("error writing list begin: ", err)
|
||||
}
|
||||
for _, v := range p.StringList {
|
||||
if err := oprot.WriteString(string(v)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
|
||||
}
|
||||
}
|
||||
if err := oprot.WriteListEnd(); err != nil {
|
||||
return PrependError("error writing list end: ", err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 10:stringList: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField11(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("stringSet", SET, 11); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 11:stringSet: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteSetBegin(STRING, len(p.StringSet)); err != nil {
|
||||
return PrependError("error writing set begin: ", err)
|
||||
}
|
||||
for v, _ := range p.StringSet {
|
||||
if err := oprot.WriteString(string(v)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T. (0) field write error: ", p), err)
|
||||
}
|
||||
}
|
||||
if err := oprot.WriteSetEnd(); err != nil {
|
||||
return PrependError("error writing set end: ", err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 11:stringSet: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) writeField12(oprot TProtocol) (err error) {
|
||||
if err := oprot.WriteFieldBegin("e", I32, 12); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field begin error 12:e: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteI32(int32(p.E)); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T.e (12) field write error: ", p), err)
|
||||
}
|
||||
if err := oprot.WriteFieldEnd(); err != nil {
|
||||
return PrependError(fmt.Sprintf("%T write field end error 12:e: ", p), err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *MyTestStruct) String() string {
|
||||
if p == nil {
|
||||
return "<nil>"
|
||||
}
|
||||
return fmt.Sprintf("MyTestStruct(%+v)", *p)
|
||||
}
|
50
vendor/git.apache.org/thrift.git/lib/go/thrift/server_socket_test.go
generated
vendored
Normal file
50
vendor/git.apache.org/thrift.git/lib/go/thrift/server_socket_test.go
generated
vendored
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSocketIsntListeningAfterInterrupt(t *testing.T) {
|
||||
host := "127.0.0.1"
|
||||
port := 9090
|
||||
addr := fmt.Sprintf("%s:%d", host, port)
|
||||
|
||||
socket := CreateServerSocket(t, addr)
|
||||
socket.Listen()
|
||||
socket.Interrupt()
|
||||
|
||||
newSocket := CreateServerSocket(t, addr)
|
||||
err := newSocket.Listen()
|
||||
defer newSocket.Interrupt()
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to rebinds: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
func CreateServerSocket(t *testing.T, addr string) *TServerSocket {
|
||||
socket, err := NewTServerSocket(addr)
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to create server socket: %s", err)
|
||||
}
|
||||
return socket
|
||||
}
|
28
vendor/git.apache.org/thrift.git/lib/go/thrift/server_test.go
generated
vendored
Normal file
28
vendor/git.apache.org/thrift.git/lib/go/thrift/server_test.go
generated
vendored
Normal file
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNothing(t *testing.T) {
|
||||
|
||||
}
|
715
vendor/git.apache.org/thrift.git/lib/go/thrift/simple_json_protocol_test.go
generated
vendored
Normal file
715
vendor/git.apache.org/thrift.git/lib/go/thrift/simple_json_protocol_test.go
generated
vendored
Normal file
|
@ -0,0 +1,715 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestWriteSimpleJSONProtocolBool(t *testing.T) {
|
||||
thetype := "boolean"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range BOOL_VALUES {
|
||||
if e := p.WriteBool(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := false
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolBool(t *testing.T) {
|
||||
thetype := "boolean"
|
||||
for _, value := range BOOL_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
if value {
|
||||
trans.Write(JSON_TRUE)
|
||||
} else {
|
||||
trans.Write(JSON_FALSE)
|
||||
}
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadBool()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolByte(t *testing.T) {
|
||||
thetype := "byte"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range BYTE_VALUES {
|
||||
if e := p.WriteByte(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int8(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolByte(t *testing.T) {
|
||||
thetype := "byte"
|
||||
for _, value := range BYTE_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadByte()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolI16(t *testing.T) {
|
||||
thetype := "int16"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range INT16_VALUES {
|
||||
if e := p.WriteI16(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int16(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolI16(t *testing.T) {
|
||||
thetype := "int16"
|
||||
for _, value := range INT16_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI16()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolI32(t *testing.T) {
|
||||
thetype := "int32"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range INT32_VALUES {
|
||||
if e := p.WriteI32(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int32(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolI32(t *testing.T) {
|
||||
thetype := "int32"
|
||||
for _, value := range INT32_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(strconv.Itoa(int(value)))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI32()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolI32Null(t *testing.T) {
|
||||
thetype := "int32"
|
||||
value := "null"
|
||||
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(value)
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI32()
|
||||
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != 0 {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolI64(t *testing.T) {
|
||||
thetype := "int64"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range INT64_VALUES {
|
||||
if e := p.WriteI64(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := int64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolI64(t *testing.T) {
|
||||
thetype := "int64"
|
||||
for _, value := range INT64_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(strconv.FormatInt(value, 10))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI64()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolI64Null(t *testing.T) {
|
||||
thetype := "int32"
|
||||
value := "null"
|
||||
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(value)
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadI64()
|
||||
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != 0 {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolDouble(t *testing.T) {
|
||||
thetype := "double"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if math.IsInf(value, 1) {
|
||||
if s != jsonQuote(JSON_INFINITY) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_INFINITY))
|
||||
}
|
||||
} else if math.IsInf(value, -1) {
|
||||
if s != jsonQuote(JSON_NEGATIVE_INFINITY) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_NEGATIVE_INFINITY))
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s != jsonQuote(JSON_NAN) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, expected: %v", thetype, value, s, jsonQuote(JSON_NAN))
|
||||
}
|
||||
} else {
|
||||
if s != fmt.Sprint(value) {
|
||||
t.Fatalf("Bad value for %s %v: %s", thetype, value, s)
|
||||
}
|
||||
v := float64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolDouble(t *testing.T) {
|
||||
thetype := "double"
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
n := NewNumericFromDouble(value)
|
||||
trans.WriteString(n.String())
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadDouble()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if math.IsInf(value, 1) {
|
||||
if !math.IsInf(v, 1) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else if math.IsInf(value, -1) {
|
||||
if !math.IsInf(v, -1) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if !math.IsNaN(v) {
|
||||
t.Fatalf("Bad value for %s %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
} else {
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolString(t *testing.T) {
|
||||
thetype := "string"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
for _, value := range STRING_VALUES {
|
||||
if e := p.WriteString(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s[0] != '"' || s[len(s)-1] != '"' {
|
||||
t.Fatalf("Bad value for %s '%v', wrote '%v', expected: %v", thetype, value, s, fmt.Sprint("\"", value, "\""))
|
||||
}
|
||||
v := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v); err != nil || *v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v)
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolString(t *testing.T) {
|
||||
thetype := "string"
|
||||
for _, value := range STRING_VALUES {
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(jsonQuote(value))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadString()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != value {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
v1 := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v1); err != nil || *v1 != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v1)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
}
|
||||
func TestReadSimpleJSONProtocolStringNull(t *testing.T) {
|
||||
thetype := "string"
|
||||
value := "null"
|
||||
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(value)
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadString()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != "" {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolBinary(t *testing.T) {
|
||||
thetype := "binary"
|
||||
value := protocol_bdata
|
||||
b64value := make([]byte, base64.StdEncoding.EncodedLen(len(protocol_bdata)))
|
||||
base64.StdEncoding.Encode(b64value, value)
|
||||
b64String := string(b64value)
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
if e := p.WriteBinary(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error flushing: %s", thetype, value, e.Error())
|
||||
}
|
||||
s := trans.String()
|
||||
if s != fmt.Sprint("\"", b64String, "\"") {
|
||||
t.Fatalf("Bad value for %s %v\n wrote: %v\nexpected: %v", thetype, value, s, "\""+b64String+"\"")
|
||||
}
|
||||
v1 := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v1); err != nil || *v1 != b64String {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v1)
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolBinary(t *testing.T) {
|
||||
thetype := "binary"
|
||||
value := protocol_bdata
|
||||
b64value := make([]byte, base64.StdEncoding.EncodedLen(len(protocol_bdata)))
|
||||
base64.StdEncoding.Encode(b64value, value)
|
||||
b64String := string(b64value)
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(jsonQuote(b64String))
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
v, e := p.ReadBinary()
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if len(v) != len(value) {
|
||||
t.Fatalf("Bad value for %s value length %v, wrote: %v, received length: %v", thetype, len(value), s, len(v))
|
||||
}
|
||||
for i := 0; i < len(v); i++ {
|
||||
if v[i] != value[i] {
|
||||
t.Fatalf("Bad value for %s at index %d value %v, wrote: %v, received: %v", thetype, i, value[i], s, v[i])
|
||||
}
|
||||
}
|
||||
v1 := new(string)
|
||||
if err := json.Unmarshal([]byte(s), v1); err != nil || *v1 != b64String {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, *v1)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestReadSimpleJSONProtocolBinaryNull(t *testing.T) {
|
||||
thetype := "binary"
|
||||
value := "null"
|
||||
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
trans.WriteString(value)
|
||||
trans.Flush()
|
||||
s := trans.String()
|
||||
b, e := p.ReadBinary()
|
||||
v := string(b)
|
||||
|
||||
if e != nil {
|
||||
t.Fatalf("Unable to read %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
if v != "" {
|
||||
t.Fatalf("Bad value for %s value %v, wrote: %v, received: %v", thetype, value, s, v)
|
||||
}
|
||||
trans.Reset()
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolList(t *testing.T) {
|
||||
thetype := "list"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
p.WriteListBegin(TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteListEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
str1 := new([]interface{})
|
||||
err := json.Unmarshal([]byte(str), str1)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
|
||||
}
|
||||
l := *str1
|
||||
if len(l) < 2 {
|
||||
t.Fatalf("List must be at least of length two to include metadata")
|
||||
}
|
||||
if int(l[0].(float64)) != DOUBLE {
|
||||
t.Fatal("Invalid type for list, expected: ", DOUBLE, ", but was: ", l[0])
|
||||
}
|
||||
if int(l[1].(float64)) != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Invalid length for list, expected: ", len(DOUBLE_VALUES), ", but was: ", l[1])
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
s := l[k+2]
|
||||
if math.IsInf(value, 1) {
|
||||
if s.(string) != JSON_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_INFINITY), str)
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if s.(string) != JSON_NEGATIVE_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY), str)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s.(string) != JSON_NAN {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NAN), str)
|
||||
}
|
||||
} else {
|
||||
if s.(float64) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s'", thetype, value, s)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolSet(t *testing.T) {
|
||||
thetype := "set"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
p.WriteSetBegin(TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for _, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteSetEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
str1 := new([]interface{})
|
||||
err := json.Unmarshal([]byte(str), str1)
|
||||
if err != nil {
|
||||
t.Fatalf("Unable to decode %s, wrote: %s", thetype, str)
|
||||
}
|
||||
l := *str1
|
||||
if len(l) < 2 {
|
||||
t.Fatalf("Set must be at least of length two to include metadata")
|
||||
}
|
||||
if int(l[0].(float64)) != DOUBLE {
|
||||
t.Fatal("Invalid type for set, expected: ", DOUBLE, ", but was: ", l[0])
|
||||
}
|
||||
if int(l[1].(float64)) != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Invalid length for set, expected: ", len(DOUBLE_VALUES), ", but was: ", l[1])
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
s := l[k+2]
|
||||
if math.IsInf(value, 1) {
|
||||
if s.(string) != JSON_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_INFINITY), str)
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if s.(string) != JSON_NEGATIVE_INFINITY {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY), str)
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s.(string) != JSON_NAN {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %q, expected: %q, originally wrote: %q", thetype, k, value, s, jsonQuote(JSON_NAN), str)
|
||||
}
|
||||
} else {
|
||||
if s.(float64) != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s'", thetype, value, s)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
||||
|
||||
func TestWriteSimpleJSONProtocolMap(t *testing.T) {
|
||||
thetype := "map"
|
||||
trans := NewTMemoryBuffer()
|
||||
p := NewTSimpleJSONProtocol(trans)
|
||||
p.WriteMapBegin(TType(I32), TType(DOUBLE), len(DOUBLE_VALUES))
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
if e := p.WriteI32(int32(k)); e != nil {
|
||||
t.Fatalf("Unable to write %s key int32 value %v due to error: %s", thetype, k, e.Error())
|
||||
}
|
||||
if e := p.WriteDouble(value); e != nil {
|
||||
t.Fatalf("Unable to write %s value float64 value %v due to error: %s", thetype, value, e.Error())
|
||||
}
|
||||
}
|
||||
p.WriteMapEnd()
|
||||
if e := p.Flush(); e != nil {
|
||||
t.Fatalf("Unable to write %s due to error flushing: %s", thetype, e.Error())
|
||||
}
|
||||
str := trans.String()
|
||||
if str[0] != '[' || str[len(str)-1] != ']' {
|
||||
t.Fatalf("Bad value for %s, wrote: %q, in go: %q", thetype, str, DOUBLE_VALUES)
|
||||
}
|
||||
l := strings.Split(str[1:len(str)-1], ",")
|
||||
if len(l) < 3 {
|
||||
t.Fatal("Expected list of at least length 3 for map for metadata, but was of length ", len(l))
|
||||
}
|
||||
expectedKeyType, _ := strconv.Atoi(l[0])
|
||||
expectedValueType, _ := strconv.Atoi(l[1])
|
||||
expectedSize, _ := strconv.Atoi(l[2])
|
||||
if expectedKeyType != I32 {
|
||||
t.Fatal("Expected map key type ", I32, ", but was ", l[0])
|
||||
}
|
||||
if expectedValueType != DOUBLE {
|
||||
t.Fatal("Expected map value type ", DOUBLE, ", but was ", l[1])
|
||||
}
|
||||
if expectedSize != len(DOUBLE_VALUES) {
|
||||
t.Fatal("Expected map size of ", len(DOUBLE_VALUES), ", but was ", l[2])
|
||||
}
|
||||
for k, value := range DOUBLE_VALUES {
|
||||
strk := l[k*2+3]
|
||||
strv := l[k*2+4]
|
||||
ik, err := strconv.Atoi(strk)
|
||||
if err != nil {
|
||||
t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v, error: %s", thetype, k, strk, string(k), err.Error())
|
||||
}
|
||||
if ik != k {
|
||||
t.Fatalf("Bad value for %s index %v, wrote: %v, expected: %v", thetype, k, strk, k)
|
||||
}
|
||||
s := strv
|
||||
if math.IsInf(value, 1) {
|
||||
if s != jsonQuote(JSON_INFINITY) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_INFINITY))
|
||||
}
|
||||
} else if math.IsInf(value, 0) {
|
||||
if s != jsonQuote(JSON_NEGATIVE_INFINITY) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NEGATIVE_INFINITY))
|
||||
}
|
||||
} else if math.IsNaN(value) {
|
||||
if s != jsonQuote(JSON_NAN) {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected: %v", thetype, k, value, s, jsonQuote(JSON_NAN))
|
||||
}
|
||||
} else {
|
||||
expected := strconv.FormatFloat(value, 'g', 10, 64)
|
||||
if s != expected {
|
||||
t.Fatalf("Bad value for %s at index %v %v, wrote: %v, expected %v", thetype, k, value, s, expected)
|
||||
}
|
||||
v := float64(0)
|
||||
if err := json.Unmarshal([]byte(s), &v); err != nil || v != value {
|
||||
t.Fatalf("Bad json-decoded value for %s %v, wrote: '%s', expected: '%v'", thetype, value, s, v)
|
||||
}
|
||||
}
|
||||
trans.Reset()
|
||||
}
|
||||
trans.Close()
|
||||
}
|
2
vendor/git.apache.org/thrift.git/lib/go/thrift/simple_server.go
generated
vendored
2
vendor/git.apache.org/thrift.git/lib/go/thrift/simple_server.go
generated
vendored
|
@ -188,7 +188,7 @@ func (p *TSimpleServer) processRequests(client TTransport) error {
|
|||
if err, ok := err.(TApplicationException); ok && err.TypeId() == UNKNOWN_METHOD {
|
||||
continue
|
||||
}
|
||||
if !ok {
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/socket.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/socket.go
generated
vendored
|
@ -161,5 +161,6 @@ func (p *TSocket) Interrupt() error {
|
|||
|
||||
func (p *TSocket) RemainingBytes() (num_bytes uint64) {
|
||||
const maxSize = ^uint64(0)
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
}
|
||||
|
||||
|
|
2
vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_server_socket.go
generated
vendored
2
vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_server_socket.go
generated
vendored
|
@ -20,9 +20,9 @@
|
|||
package thrift
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net"
|
||||
"time"
|
||||
"crypto/tls"
|
||||
)
|
||||
|
||||
type TSSLServerSocket struct {
|
||||
|
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_socket.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/ssl_socket.go
generated
vendored
|
@ -166,5 +166,6 @@ func (p *TSSLSocket) Interrupt() error {
|
|||
|
||||
func (p *TSSLSocket) RemainingBytes() (num_bytes uint64) {
|
||||
const maxSize = ^uint64(0)
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
return maxSize // the thruth is, we just don't know unless framed is used
|
||||
}
|
||||
|
||||
|
|
3
vendor/git.apache.org/thrift.git/lib/go/thrift/transport.go
generated
vendored
3
vendor/git.apache.org/thrift.git/lib/go/thrift/transport.go
generated
vendored
|
@ -34,6 +34,7 @@ type ReadSizeProvider interface {
|
|||
RemainingBytes() (num_bytes uint64)
|
||||
}
|
||||
|
||||
|
||||
// Encapsulates the I/O layer
|
||||
type TTransport interface {
|
||||
io.ReadWriteCloser
|
||||
|
@ -51,6 +52,7 @@ type stringWriter interface {
|
|||
WriteString(s string) (n int, err error)
|
||||
}
|
||||
|
||||
|
||||
// This is "enchanced" transport with extra capabilities. You need to use one of these
|
||||
// to construct protocol.
|
||||
// Notably, TSocket does not implement this interface, and it is always a mistake to use
|
||||
|
@ -63,3 +65,4 @@ type TRichTransport interface {
|
|||
Flusher
|
||||
ReadSizeProvider
|
||||
}
|
||||
|
||||
|
|
60
vendor/git.apache.org/thrift.git/lib/go/thrift/transport_exception_test.go
generated
vendored
Normal file
60
vendor/git.apache.org/thrift.git/lib/go/thrift/transport_exception_test.go
generated
vendored
Normal file
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
type timeout struct{ timedout bool }
|
||||
|
||||
func (t *timeout) Timeout() bool {
|
||||
return t.timedout
|
||||
}
|
||||
|
||||
func (t *timeout) Error() string {
|
||||
return fmt.Sprintf("Timeout: %v", t.timedout)
|
||||
}
|
||||
|
||||
func TestTExceptionTimeout(t *testing.T) {
|
||||
timeout := &timeout{true}
|
||||
exception := NewTTransportExceptionFromError(timeout)
|
||||
if timeout.Error() != exception.Error() {
|
||||
t.Fatalf("Error did not match: expected %q, got %q", timeout.Error(), exception.Error())
|
||||
}
|
||||
|
||||
if exception.TypeId() != TIMED_OUT {
|
||||
t.Fatalf("TypeId was not TIMED_OUT: expected %v, got %v", TIMED_OUT, exception.TypeId())
|
||||
}
|
||||
}
|
||||
|
||||
func TestTExceptionEOF(t *testing.T) {
|
||||
exception := NewTTransportExceptionFromError(io.EOF)
|
||||
if io.EOF.Error() != exception.Error() {
|
||||
t.Fatalf("Error did not match: expected %q, got %q", io.EOF.Error(), exception.Error())
|
||||
}
|
||||
|
||||
if exception.TypeId() != END_OF_FILE {
|
||||
t.Fatalf("TypeId was not END_OF_FILE: expected %v, got %v", END_OF_FILE, exception.TypeId())
|
||||
}
|
||||
}
|
176
vendor/git.apache.org/thrift.git/lib/go/thrift/transport_test.go
generated
vendored
Normal file
176
vendor/git.apache.org/thrift.git/lib/go/thrift/transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,176 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
"strconv"
|
||||
"testing"
|
||||
)
|
||||
|
||||
const TRANSPORT_BINARY_DATA_SIZE = 4096
|
||||
|
||||
var (
|
||||
transport_bdata []byte // test data for writing; same as data
|
||||
transport_header map[string]string
|
||||
)
|
||||
|
||||
func init() {
|
||||
transport_bdata = make([]byte, TRANSPORT_BINARY_DATA_SIZE)
|
||||
for i := 0; i < TRANSPORT_BINARY_DATA_SIZE; i++ {
|
||||
transport_bdata[i] = byte((i + 'a') % 255)
|
||||
}
|
||||
transport_header = map[string]string{"key": "User-Agent",
|
||||
"value": "Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36"}
|
||||
}
|
||||
|
||||
func TransportTest(t *testing.T, writeTrans TTransport, readTrans TTransport) {
|
||||
buf := make([]byte, TRANSPORT_BINARY_DATA_SIZE)
|
||||
if !writeTrans.IsOpen() {
|
||||
t.Fatalf("Transport %T not open: %s", writeTrans, writeTrans)
|
||||
}
|
||||
if !readTrans.IsOpen() {
|
||||
t.Fatalf("Transport %T not open: %s", readTrans, readTrans)
|
||||
}
|
||||
_, err := writeTrans.Write(transport_bdata)
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot write binary data of length %d: %s", writeTrans, len(transport_bdata), err)
|
||||
}
|
||||
err = writeTrans.Flush()
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot flush write of binary data: %s", writeTrans, err)
|
||||
}
|
||||
n, err := io.ReadFull(readTrans, buf)
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot read binary data of length %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, err)
|
||||
}
|
||||
if n != TRANSPORT_BINARY_DATA_SIZE {
|
||||
t.Errorf("Transport %T read only %d instead of %d bytes of binary data", readTrans, n, TRANSPORT_BINARY_DATA_SIZE)
|
||||
}
|
||||
for k, v := range buf {
|
||||
if v != transport_bdata[k] {
|
||||
t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k)
|
||||
}
|
||||
}
|
||||
_, err = writeTrans.Write(transport_bdata)
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot write binary data 2 of length %d: %s", writeTrans, len(transport_bdata), err)
|
||||
}
|
||||
err = writeTrans.Flush()
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot flush write binary data 2: %s", writeTrans, err)
|
||||
}
|
||||
buf = make([]byte, TRANSPORT_BINARY_DATA_SIZE)
|
||||
read := 1
|
||||
for n = 0; n < TRANSPORT_BINARY_DATA_SIZE && read != 0; {
|
||||
read, err = readTrans.Read(buf[n:])
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot read binary data 2 of total length %d from offset %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, n, err)
|
||||
}
|
||||
n += read
|
||||
}
|
||||
if n != TRANSPORT_BINARY_DATA_SIZE {
|
||||
t.Errorf("Transport %T read only %d instead of %d bytes of binary data 2", readTrans, n, TRANSPORT_BINARY_DATA_SIZE)
|
||||
}
|
||||
for k, v := range buf {
|
||||
if v != transport_bdata[k] {
|
||||
t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TransportHeaderTest(t *testing.T, writeTrans TTransport, readTrans TTransport) {
|
||||
buf := make([]byte, TRANSPORT_BINARY_DATA_SIZE)
|
||||
if !writeTrans.IsOpen() {
|
||||
t.Fatalf("Transport %T not open: %s", writeTrans, writeTrans)
|
||||
}
|
||||
if !readTrans.IsOpen() {
|
||||
t.Fatalf("Transport %T not open: %s", readTrans, readTrans)
|
||||
}
|
||||
// Need to assert type of TTransport to THttpClient to expose the Setter
|
||||
httpWPostTrans := writeTrans.(*THttpClient)
|
||||
httpWPostTrans.SetHeader(transport_header["key"], transport_header["value"])
|
||||
|
||||
_, err := writeTrans.Write(transport_bdata)
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot write binary data of length %d: %s", writeTrans, len(transport_bdata), err)
|
||||
}
|
||||
err = writeTrans.Flush()
|
||||
if err != nil {
|
||||
t.Fatalf("Transport %T cannot flush write of binary data: %s", writeTrans, err)
|
||||
}
|
||||
// Need to assert type of TTransport to THttpClient to expose the Getter
|
||||
httpRPostTrans := readTrans.(*THttpClient)
|
||||
readHeader := httpRPostTrans.GetHeader(transport_header["key"])
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot read HTTP Header Value", httpRPostTrans)
|
||||
}
|
||||
|
||||
if transport_header["value"] != readHeader {
|
||||
t.Errorf("Expected HTTP Header Value %s, got %s", transport_header["value"], readHeader)
|
||||
}
|
||||
n, err := io.ReadFull(readTrans, buf)
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot read binary data of length %d: %s", readTrans, TRANSPORT_BINARY_DATA_SIZE, err)
|
||||
}
|
||||
if n != TRANSPORT_BINARY_DATA_SIZE {
|
||||
t.Errorf("Transport %T read only %d instead of %d bytes of binary data", readTrans, n, TRANSPORT_BINARY_DATA_SIZE)
|
||||
}
|
||||
for k, v := range buf {
|
||||
if v != transport_bdata[k] {
|
||||
t.Fatalf("Transport %T read %d instead of %d for index %d of binary data 2", readTrans, v, transport_bdata[k], k)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func CloseTransports(t *testing.T, readTrans TTransport, writeTrans TTransport) {
|
||||
err := readTrans.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot close read transport: %s", readTrans, err)
|
||||
}
|
||||
if writeTrans != readTrans {
|
||||
err = writeTrans.Close()
|
||||
if err != nil {
|
||||
t.Errorf("Transport %T cannot close write transport: %s", writeTrans, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func FindAvailableTCPServerPort(startPort int) (net.Addr, error) {
|
||||
for i := startPort; i < 65535; i++ {
|
||||
s := "127.0.0.1:" + strconv.Itoa(i)
|
||||
l, err := net.Listen("tcp", s)
|
||||
if err == nil {
|
||||
l.Close()
|
||||
return net.ResolveTCPAddr("tcp", s)
|
||||
}
|
||||
}
|
||||
return nil, NewTTransportException(UNKNOWN_TRANSPORT_EXCEPTION, "Could not find available server port")
|
||||
}
|
||||
|
||||
func valueInSlice(value string, slice []string) bool {
|
||||
for _, v := range slice {
|
||||
if value == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
33
vendor/git.apache.org/thrift.git/lib/go/thrift/zlib_transport_test.go
generated
vendored
Normal file
33
vendor/git.apache.org/thrift.git/lib/go/thrift/zlib_transport_test.go
generated
vendored
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*
|
||||
* 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 thrift
|
||||
|
||||
import (
|
||||
"compress/zlib"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestZlibTransport(t *testing.T) {
|
||||
trans, err := NewTZlibTransport(NewTMemoryBuffer(), zlib.BestCompression)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
TransportTest(t, trans, trans)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue