Moving from the Thrift JSON protocol to the Thrift Binary protocol by default. Realis config now holds transport and Protocol factory for impreoved flexibility. Renamed realis_test to reflect the true nature of the test along with a minor fix for an API change.

This commit is contained in:
Renan DelValle 2017-02-10 19:23:20 -05:00
parent 2c7dd3468f
commit 5f155f4337
2 changed files with 8 additions and 9 deletions

View file

@ -55,18 +55,13 @@ type realisClient struct {
// Wrap object to provide future flexibility
type RealisConfig struct {
transport thrift.TTransport
protoFactory thrift.TProtocolFactory
}
// Create a new Client with a default transport layer
func NewClient(config RealisConfig) Realis {
httpTrans := (config.transport).(*thrift.THttpClient)
httpTrans.SetHeader("User-Agent", "GoRealis v1.0.4")
protocolFactory := thrift.NewTJSONProtocolFactory()
return realisClient{
client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, protocolFactory)}
client: aurora.NewAuroraSchedulerManagerClientFactory(config.transport, config.protoFactory)}
}
// Create a default configuration of the transport layer, requires a URL to test connection with.
@ -89,8 +84,12 @@ func NewDefaultConfig(url string, timeoutms int) (RealisConfig, error) {
fmt.Fprintln(os.Stderr)
return RealisConfig{}, errors.Wrapf(err, "Error opening connection to %s", url)
}
httpTrans := (trans).(*thrift.THttpClient)
httpTrans.SetHeader("Accept", "application/vnd.apache.thrift.binary")
httpTrans.SetHeader("Content-Type", "application/vnd.apache.thrift.binary")
httpTrans.SetHeader("User-Agent", "GoRealis v1.0.4")
return RealisConfig{transport: trans}, nil
return RealisConfig{transport: trans, protoFactory: thrift.NewTBinaryProtocolFactoryDefault()}, nil
}

View file

@ -28,7 +28,7 @@ var thermosPayload []byte
func TestMain(m *testing.M) {
// New configuration to connect to Vagrant image
config, err := NewDefaultConfig("http://192.168.33.7:8081")
config, err := NewDefaultConfig("http://192.168.33.7:8081",10000)
if err != nil {
fmt.Println("Please run vagrant box before running test suite")
os.Exit(1)