You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by je...@apache.org on 2014/11/24 22:56:41 UTC
thrift git commit: THRIFT-2852 Better Open/IsOpen/Close behavior for
StreamTransport. Client: Go Patch: Chi Vinh Le
Repository: thrift
Updated Branches:
refs/heads/master 28d9315de -> cb0afcc03
THRIFT-2852 Better Open/IsOpen/Close behavior for StreamTransport.
Client: Go
Patch: Chi Vinh Le <cv...@chinet.info>
This closes #285
Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/cb0afcc0
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/cb0afcc0
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/cb0afcc0
Branch: refs/heads/master
Commit: cb0afcc0353af24b111dc000a98915580768c8bb
Parents: 28d9315
Author: Jens Geyer <je...@apache.org>
Authored: Mon Nov 24 22:49:09 2014 +0100
Committer: Jens Geyer <je...@apache.org>
Committed: Mon Nov 24 22:55:42 2014 +0100
----------------------------------------------------------------------
lib/go/thrift/iostream_transport.go | 13 +++++++++++--
lib/go/thrift/iostream_transport_test.go | 22 ++++++++++++++++++++++
2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/thrift/blob/cb0afcc0/lib/go/thrift/iostream_transport.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/iostream_transport.go b/lib/go/thrift/iostream_transport.go
index 314eaa6..82563e9 100644
--- a/lib/go/thrift/iostream_transport.go
+++ b/lib/go/thrift/iostream_transport.go
@@ -29,6 +29,7 @@ type StreamTransport struct {
io.Reader
io.Writer
isReadWriter bool
+ closed bool
}
type StreamTransportFactory struct {
@@ -95,12 +96,16 @@ func NewStreamTransportRW(rw io.ReadWriter) *StreamTransport {
// (The streams must already be open at construction time, so this should
// always return true.)
func (p *StreamTransport) IsOpen() bool {
- return true
+ return !p.closed
}
// (The streams must already be open. This method does nothing.)
func (p *StreamTransport) Open() error {
- return nil
+ if !p.closed {
+ return NewTTransportException(ALREADY_OPEN, "StreamTransport already open.")
+ } else {
+ return NewTTransportException(NOT_OPEN, "cannot reopen StreamTransport.")
+ }
}
// func (p *StreamTransport) Peek() bool {
@@ -109,6 +114,10 @@ func (p *StreamTransport) Open() error {
// Closes both the input and output streams.
func (p *StreamTransport) Close() error {
+ if p.closed {
+ return NewTTransportException(NOT_OPEN, "StreamTransport already closed.")
+ }
+ p.closed = true
closedReader := false
if p.Reader != nil {
c, ok := p.Reader.(io.Closer)
http://git-wip-us.apache.org/repos/asf/thrift/blob/cb0afcc0/lib/go/thrift/iostream_transport_test.go
----------------------------------------------------------------------
diff --git a/lib/go/thrift/iostream_transport_test.go b/lib/go/thrift/iostream_transport_test.go
index 15ea2d4..15a6116 100644
--- a/lib/go/thrift/iostream_transport_test.go
+++ b/lib/go/thrift/iostream_transport_test.go
@@ -28,3 +28,25 @@ 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")
+ }
+}