コード例 #1
0
ファイル: one_way_test.go プロジェクト: GDGroup/thrift
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)
	}
}
コード例 #2
0
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)
	}
}
コード例 #3
0
//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
}
コード例 #4
0
ファイル: utils.go プロジェクト: shenfeng/thrift-router
func formatError(fname string, seqId, exceptionId int32, err error) []byte {
	buffer := thrift.NewTMemoryBuffer()
	trans := thrift.NewTFramedTransport(buffer)
	oprot := thrift.NewTBinaryProtocolTransport(trans)
	a := thrift.NewTApplicationException(exceptionId, err.Error())
	oprot.WriteMessageBegin(fname, thrift.EXCEPTION, seqId)
	a.Write(oprot)
	oprot.WriteMessageEnd()
	oprot.Flush()
	return buffer.Bytes()
}
コード例 #5
0
ファイル: simple_test.go プロジェクト: pablo-meier/thrift4go
func TestWireFormatWithSetPayload(t *testing.T) {
	var transport *thrift.TMemoryBuffer

	var protocols = []struct {
		name    string
		builder protocolBuilder
	}{
		{
			"TBinaryProtocol",
			func() thrift.TProtocol {
				return thrift.NewTBinaryProtocolTransport(transport)
			},
		},
		{
			"TCompactProtocol",
			func() thrift.TProtocol {
				return thrift.NewTCompactProtocol(transport)
			},
		},
		{
			"TJSONProtocol",
			func() thrift.TProtocol {
				return thrift.NewTJSONProtocol(transport)
			},
		},
		{
			"TSimpleJSONProtocol",
			func() thrift.TProtocol {
				return thrift.NewTSimpleJSONProtocol(transport)
			},
		},
	}

	for i, definition := range protocols {
		transport = thrift.NewTMemoryBuffer()
		defer transport.Close()
		protocol := definition.builder()
		name := definition.name

		emission := NewContainerOfEnums()
		emission.First = UndefinedTwo
		emission.Second = DefinedTwo
		emission.Third = HeterogeneousTwo
		emission.OptionalFourth = UndefinedThree
		emission.OptionalFifth = DefinedThree
		emission.OptionalSixth = HeterogeneousThree

		if err := emission.Write(protocol); err != nil {
			t.Fatalf("%d (%s): Could not emit simple %q to JSON.", i, name, emission)
		}

		if err := protocol.Flush(); err != nil {
			t.Fatalf("%d (%s): Could not flush emission.", i, name)
		}

		incoming := NewContainerOfEnums()

		if err := incoming.Read(protocol); err != nil {
			t.Fatalf("%d (%s): Could not read from buffer: %q", i, name, err)
		}

		if emission.First != incoming.First {
			t.Errorf("%d (%s) emission.First (%q) != incoming.First (%q)", i, name, emission.First, incoming.First)
		}

		if emission.Second != incoming.Second {
			t.Errorf("%d (%s) emission.Second (%q) != incoming.Second (%q)", i, name, emission.Second, incoming.Second)
		}

		if emission.Third != incoming.Third {
			t.Errorf("%d (%s) emission.Third (%q) != incoming.Third (%q)", i, name, emission.Third, incoming.Third)
		}

		if emission.OptionalFourth != incoming.OptionalFourth {
			t.Errorf("%d (%s) emission.OptionalFourth (%q) != incoming.OptionalFourth (%q)", i, name, emission.OptionalFourth, incoming.OptionalFourth)
		}

		if emission.OptionalFifth != incoming.OptionalFifth {
			t.Errorf("%d (%s) emission.OptionalFifth (%q) != incoming.OptionalFifth (%q)", i, name, emission.OptionalFifth, incoming.OptionalFifth)
		}

		if emission.OptionalSixth != incoming.OptionalSixth {
			t.Errorf("%d (%s) emission.OptionalSixth (%q) != incoming.OptionalSixth (%q)", i, name, emission.OptionalSixth, incoming.OptionalSixth)
		}

		if emission.DefaultSeventh != incoming.DefaultSeventh {
			t.Errorf("%d (%s) emission.DefaultSeventh (%q) != incoming.DefaultSeventh (%q)", i, name, emission.DefaultSeventh, incoming.DefaultSeventh)
		}

		if emission.DefaultEighth != incoming.DefaultEighth {
			t.Errorf("%d (%s) emission.DefaultEighth (%q) != incoming.DefaultEighth (%q)", i, name, emission.DefaultEighth, incoming.DefaultEighth)
		}

		if emission.DefaultNineth != incoming.DefaultNineth {
			t.Errorf("%d (%s) emission.DefaultNineth (%q) != incoming.DefaultNineth (%q)", i, name, emission.DefaultNineth, incoming.DefaultNineth)
		}

		if emission.IsSetOptionalFourth() != incoming.IsSetOptionalFourth() {
			t.Errorf("%d (%s) emission.IsSetOptionalFourth (%q) != incoming.IsSetOptionalFourth (%q)", i, name, emission.IsSetOptionalFourth(), incoming.IsSetOptionalFourth())
		}

		if emission.IsSetOptionalFifth() != incoming.IsSetOptionalFifth() {
			t.Errorf("%d (%s) emission.IsSetOptionalFifth (%q) != incoming.IsSetOptionalFifth (%q)", i, name, emission.IsSetOptionalFifth(), incoming.IsSetOptionalFifth())
		}

		if emission.IsSetOptionalSixth() != incoming.IsSetOptionalSixth() {
			t.Errorf("%d (%s) emission.IsSetOptionalSixth (%q) != incoming.IsSetOptionalSixth (%q)", i, name, emission.IsSetOptionalSixth(), incoming.IsSetOptionalSixth())
		}

		if emission.IsSetDefaultSeventh() != incoming.IsSetDefaultSeventh() {
			t.Errorf("%d (%s) emission.IsSetDefaultSeventh (%q) != incoming.IsSetDefaultSeventh (%q)", i, name, emission.IsSetDefaultSeventh(), incoming.IsSetDefaultSeventh())
		}

		if emission.IsSetDefaultEighth() != incoming.IsSetDefaultEighth() {
			t.Errorf("%d (%s) emission.IsSetDefaultEighth (%q) != incoming.IsSetDefaultEighth (%q)", i, name, emission.IsSetDefaultEighth(), incoming.IsSetDefaultEighth())
		}

		if emission.IsSetDefaultNineth() != incoming.IsSetDefaultNineth() {
			t.Errorf("%d (%s) emission.IsSetDefaultNineth (%q) != incoming.IsSetDefaultNineth (%q)", i, name, emission.IsSetDefaultNineth(), incoming.IsSetDefaultNineth())
		}
	}
}