THRIFT-2497 server and client for test/go, also several fixes and improvements
Client: Go
Patch: Aleksey Pesternikov
This closes #109
commit f2e7186ca8d63f407dba0c56ee51afd6405926ba
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-22T12:48:14Z
add _ to generated filename if it ends with _test.go
commit a6ed88196fbf4622a3b0261bbac0fe6b258bdd36
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-22T14:19:13Z
use tcxx instead of tr1 in test/cpp
commit d1848fa05f4baefc66eb405f4b1a8657bb2869bd
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-23T01:01:03Z
Merge branch 'master' of https://github.com/apache/thrift into go_integration
commit 04d22fef228d3f868b32a296a38f99ff52ee2142
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T00:34:24Z
additions:
test for client/server with several protocol/transport/ssl combinations
bin/testclient and bin/testserver
debug_transport
fixes:
separate Listen() and AcceptLoop() instead of Serve() in SimpleServer
if handler function returns any unknown exception, handler closes connection
commit ed88d57d977cffea9fac8f61143801f3097ef46c
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T13:29:54Z
Generate lowercase package name
lowercased pkg name in thrift files
underline() -> lowercase()
commit 498a910c6c6753a4b1e3633eb5c9c82be33e8c7b
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T13:32:26Z
Merge branch 'master' into go_test_service_name
commit 25792d7218a2c32ee3c2077f65ca7d0cea7f31f5
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-22T12:48:14Z
add _ to generated filename if it ends with _test.go
commit af994b415308a2e174d57a03675fc83d7cbd43d1
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T00:34:24Z
additions:
test for client/server with several protocol/transport/ssl combinations
bin/testclient and bin/testserver
debug_transport
fixes:
separate Listen() and AcceptLoop() instead of Serve() in SimpleServer
if handler function returns any unknown exception, handler closes connection
commit f22a777a5d5b4d93a8d7981e7aadc2c63919518a
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T13:44:08Z
Merge branch 'go_integration' of github.com:apesternikov/thrift into go_integration
commit 49a33c8c80ea35f923ee9aa3577780fcf41fe840
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T13:49:05Z
Merge branch 'master' into test_cpp_on_mac
commit 81b402ec6301f6b132c9b346ad5481f55f0aff89
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T13:56:56Z
operator < for ThriftTest
commit cde312d940d12077274dd0ba677ca850b5b439a7
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T14:12:58Z
minor formatting
commit 0a693115c2c20a2a8375f3859ff7bed261e6c8da
Author: Aleksey Pesternikov <ap@alekseys-mbp.att.net>
Date: 2014-04-25T14:13:20Z
Merge branch 'test_cpp_on_mac' into go_integration
commit e06b5d24e8b6d429723a3c77a58c6ce903e1366a
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T15:19:20Z
Merge branch 'go_test_service_name' into go_integration
commit 42d577c9812a070060c773fcd0598e58e6d6ba61
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T15:39:57Z
imported THRIFT-2491
lowercase package names
commit 491ccf8b018c046c5ced72b1e19d9ac4ec48a6f5
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T15:51:53Z
--noinsane flag for c++ TestClient. works with go server now for other default params
commit 78db3c9a3a5742818a5de6e57f2fe9aed84919e5
Author: Aleksey Pesternikov <ap@alekseys-macbook-pro.local>
Date: 2014-04-25T16:03:23Z
license
diff --git a/test/go/src/common/printing_handler.go b/test/go/src/common/printing_handler.go
new file mode 100644
index 0000000..e93621f
--- /dev/null
+++ b/test/go/src/common/printing_handler.go
@@ -0,0 +1,351 @@
+/*
+ * 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 common
+
+import (
+ "errors"
+ "fmt"
+ . "gen/thrifttest"
+ "time"
+)
+
+var PrintingHandler = &printingHandler{}
+
+type printingHandler struct{}
+
+// Prints "testVoid()" and returns nothing.
+func (p *printingHandler) TestVoid() (err error) {
+ fmt.Println("testVoid()")
+ return nil
+}
+
+// Prints 'testString("%s")' with thing as '%s'
+// @param string thing - the string to print
+// @return string - returns the string 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestString(thing string) (r string, err error) {
+ fmt.Printf("testString(\"%s\")\n", thing)
+ return thing, nil
+}
+
+// Prints 'testByte("%d")' with thing as '%d'
+// @param byte thing - the byte to print
+// @return byte - returns the byte 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestByte(thing int8) (r int8, err error) {
+ fmt.Printf("testByte(%d)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testI32("%d")' with thing as '%d'
+// @param i32 thing - the i32 to print
+// @return i32 - returns the i32 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestI32(thing int32) (r int32, err error) {
+ fmt.Printf("testI32(%d)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testI64("%d")' with thing as '%d'
+// @param i64 thing - the i64 to print
+// @return i64 - returns the i64 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestI64(thing int64) (r int64, err error) {
+ fmt.Printf("testI64(%d)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testDouble("%f")' with thing as '%f'
+// @param double thing - the double to print
+// @return double - returns the double 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestDouble(thing float64) (r float64, err error) {
+ fmt.Printf("testDouble(%f)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testStruct("{%s}")' where thing has been formatted into a string of comma seperated values
+// @param Xtruct thing - the Xtruct to print
+// @return Xtruct - returns the Xtruct 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestStruct(thing *Xtruct) (r *Xtruct, err error) {
+ fmt.Printf("testStruct({\"%s\", %d, %d, %d})\n", thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing)
+ return thing, err
+}
+
+// Prints 'testNest("{%s}")' where thing has been formatted into a string of the nested struct
+// @param Xtruct2 thing - the Xtruct2 to print
+// @return Xtruct2 - returns the Xtruct2 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestNest(nest *Xtruct2) (r *Xtruct2, err error) {
+ thing := nest.StructThing
+ fmt.Printf("testNest({%d, {\"%s\", %d, %d, %d}, %d})\n", nest.ByteThing, thing.StringThing, thing.ByteThing, thing.I32Thing, thing.I64Thing, nest.I32Thing)
+ return nest, nil
+}
+
+// Prints 'testMap("{%s")' where thing has been formatted into a string of 'key => value' pairs
+// seperated by commas and new lines
+// @param map<i32,i32> thing - the map<i32,i32> to print
+// @return map<i32,i32> - returns the map<i32,i32> 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestMap(thing map[int32]int32) (r map[int32]int32, err error) {
+ fmt.Printf("testMap({")
+ first := true
+ for k, v := range thing {
+ if first {
+ first = false
+ } else {
+ fmt.Printf(", ")
+ }
+ fmt.Printf("%d => %d", k, v)
+ }
+ fmt.Printf("})\n")
+ return thing, nil
+}
+
+// Prints 'testStringMap("{%s}")' where thing has been formatted into a string of 'key => value' pairs
+// seperated by commas and new lines
+// @param map<string,string> thing - the map<string,string> to print
+// @return map<string,string> - returns the map<string,string> 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestStringMap(thing map[string]string) (r map[string]string, err error) {
+ fmt.Printf("testStringMap({")
+ first := true
+ for k, v := range thing {
+ if first {
+ first = false
+ } else {
+ fmt.Printf(", ")
+ }
+ fmt.Printf("%s => %s", k, v)
+ }
+ fmt.Printf("})\n")
+ return thing, nil
+}
+
+// Prints 'testSet("{%s}")' where thing has been formatted into a string of values
+// seperated by commas and new lines
+// @param set<i32> thing - the set<i32> to print
+// @return set<i32> - returns the set<i32> 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestSet(thing map[int32]bool) (r map[int32]bool, err error) {
+ fmt.Printf("testSet({")
+ first := true
+ for k, _ := range thing {
+ if first {
+ first = false
+ } else {
+ fmt.Printf(", ")
+ }
+ fmt.Printf("%d", k)
+ }
+ fmt.Printf("})\n")
+ return thing, nil
+}
+
+// Prints 'testList("{%s}")' where thing has been formatted into a string of values
+// seperated by commas and new lines
+// @param list<i32> thing - the list<i32> to print
+// @return list<i32> - returns the list<i32> 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestList(thing []int32) (r []int32, err error) {
+ fmt.Printf("testList({")
+ for i, v := range thing {
+ if i != 0 {
+ fmt.Printf(", ")
+ }
+ fmt.Printf("%d", v)
+ }
+ fmt.Printf("})\n")
+ return thing, nil
+}
+
+// Prints 'testEnum("%d")' where thing has been formatted into it's numeric value
+// @param Numberz thing - the Numberz to print
+// @return Numberz - returns the Numberz 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestEnum(thing Numberz) (r Numberz, err error) {
+ fmt.Printf("testEnum(%d)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testTypedef("%d")' with thing as '%d'
+// @param UserId thing - the UserId to print
+// @return UserId - returns the UserId 'thing'
+//
+// Parameters:
+// - Thing
+func (p *printingHandler) TestTypedef(thing UserId) (r UserId, err error) {
+ fmt.Printf("testTypedef(%d)\n", thing)
+ return thing, nil
+}
+
+// Prints 'testMapMap("%d")' with hello as '%d'
+// @param i32 hello - the i32 to print
+// @return map<i32,map<i32,i32>> - returns a dictionary with these values:
+// {-4 => {-4 => -4, -3 => -3, -2 => -2, -1 => -1, }, 4 => {1 => 1, 2 => 2, 3 => 3, 4 => 4, }, }
+//
+// Parameters:
+// - Hello
+func (p *printingHandler) TestMapMap(hello int32) (r map[int32]map[int32]int32, err error) {
+ fmt.Printf("testMapMap(%d)\n", hello)
+
+ r = map[int32]map[int32]int32{
+ -4: map[int32]int32{-4: -4, -3: -3, -2: -2, -1: -1},
+ 4: map[int32]int32{4: 4, 3: 3, 2: 2, 1: 1},
+ }
+ return
+}
+
+// So you think you've got this all worked, out eh?
+//
+// Creates a the returned map with these values and prints it out:
+// { 1 => { 2 => argument,
+// 3 => argument,
+// },
+// 2 => { 6 => <empty Insanity struct>, },
+// }
+// @return map<UserId, map<Numberz,Insanity>> - a map with the above values
+//
+// Parameters:
+// - Argument
+func (p *printingHandler) TestInsanity(argument *Insanity) (r map[UserId]map[Numberz]*Insanity, err error) {
+ return nil, errors.New("No Insanity")
+}
+
+// Prints 'testMulti()'
+// @param byte arg0 -
+// @param i32 arg1 -
+// @param i64 arg2 -
+// @param map<i16, string> arg3 -
+// @param Numberz arg4 -
+// @param UserId arg5 -
+// @return Xtruct - returns an Xtruct with StringThing = "Hello2, ByteThing = arg0, I32Thing = arg1
+// and I64Thing = arg2
+//
+// Parameters:
+// - Arg0
+// - Arg1
+// - Arg2
+// - Arg3
+// - Arg4
+// - Arg5
+func (p *printingHandler) TestMulti(arg0 int8, arg1 int32, arg2 int64, arg3 map[int16]string, arg4 Numberz, arg5 UserId) (r *Xtruct, err error) {
+ fmt.Printf("testMulti()\n")
+ r = NewXtruct()
+
+ r.StringThing = "Hello2"
+ r.ByteThing = arg0
+ r.I32Thing = arg1
+ r.I64Thing = arg2
+ return
+}
+
+// Print 'testException(%s)' with arg as '%s'
+// @param string arg - a string indication what type of exception to throw
+// if arg == "Xception" throw Xception with errorCode = 1001 and message = arg
+// elsen if arg == "TException" throw TException
+// else do not throw anything
+//
+// Parameters:
+// - Arg
+func (p *printingHandler) TestException(arg string) (err error) {
+ fmt.Printf("testException(%s)\n", arg)
+ switch arg {
+ case "Xception":
+ e := NewXception()
+ e.ErrorCode = 1001
+ e.Message = arg
+ return e
+ case "TException":
+ return errors.New("Just TException")
+ }
+ return
+}
+
+// Print 'testMultiException(%s, %s)' with arg0 as '%s' and arg1 as '%s'
+// @param string arg - a string indication what type of exception to throw
+// if arg0 == "Xception" throw Xception with errorCode = 1001 and message = "This is an Xception"
+// elsen if arg0 == "Xception2" throw Xception2 with errorCode = 2002 and message = "This is an Xception2"
+// else do not throw anything
+// @return Xtruct - an Xtruct with StringThing = arg1
+//
+// Parameters:
+// - Arg0
+// - Arg1
+func (p *printingHandler) TestMultiException(arg0 string, arg1 string) (r *Xtruct, err error) {
+ fmt.Printf("testMultiException(%s, %s)\n", arg0, arg1)
+ switch arg0 {
+
+ case "Xception":
+ e := NewXception()
+ e.ErrorCode = 1001
+ e.Message = "This is an Xception"
+ return nil, e
+ case "Xception2":
+ e := NewXception2()
+ e.ErrorCode = 2002
+ e.StructThing = NewXtruct()
+ e.StructThing.StringThing = "This is an Xception2"
+ return nil, e
+ default:
+ r = NewXtruct()
+ r.StringThing = arg1
+ return
+ }
+}
+
+// Print 'testOneway(%d): Sleeping...' with secondsToSleep as '%d'
+// sleep 'secondsToSleep'
+// Print 'testOneway(%d): done sleeping!' with secondsToSleep as '%d'
+// @param i32 secondsToSleep - the number of seconds to sleep
+//
+// Parameters:
+// - SecondsToSleep
+func (p *printingHandler) TestOneway(secondsToSleep int32) (err error) {
+ fmt.Printf("testOneway(%d): Sleeping...\n", secondsToSleep)
+ time.Sleep(time.Second * time.Duration(secondsToSleep))
+ fmt.Printf("testOneway(%d): done sleeping!\n", secondsToSleep)
+ return
+}