Skip to content

Commit

Permalink
GOCBC-619: Update and add new transcoder types
Browse files Browse the repository at this point in the history
Motivation
----------
We have updated transcoding RFC so that the default transcoder is
a JSON transcoder. The RFC has added extra transcoders that the
SDK must implement.

Changes
-------
Renamed DefaultTranscoder to JSONTranscoder and updated its
behaviour to match the RFC. Added new transcoders for Legacy,
RawJSON, RawString and RawBinary.

Change-Id: I889f508c8f13e7a0c06602f2a04d3d84b9b10fd5
Reviewed-on: http://review.couchbase.org/115591
Reviewed-by: Brett Lawson <brett19@gmail.com>
Tested-by: Charles Dixon <chvckd@gmail.com>
  • Loading branch information
chvck committed Sep 30, 2019
1 parent e6ec9ba commit 07ab88c
Show file tree
Hide file tree
Showing 8 changed files with 1,150 additions and 213 deletions.
4 changes: 2 additions & 2 deletions bucket_viewquery_test.go
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/couchbase/gocbcore/v8"
gocbcore "github.com/couchbase/gocbcore/v8"
)

func TestViewQuery(t *testing.T) {
Expand Down Expand Up @@ -540,7 +540,7 @@ func testGetBucketForHTTP(provider *mockHTTPProvider, viewTimeout time.Duration)
clients["mock"] = cli
b := &Bucket{
sb: stateBlock{
Transcoder: NewDefaultTranscoder(&DefaultJSONSerializer{}),
Transcoder: NewJSONTranscoder(&DefaultJSONSerializer{}),
cachedClient: cli,
},
}
Expand Down
4 changes: 2 additions & 2 deletions cluster.go
Expand Up @@ -7,7 +7,7 @@ import (
"sync/atomic"
"time"

"github.com/couchbase/gocbcore/v8"
gocbcore "github.com/couchbase/gocbcore/v8"
"github.com/couchbaselabs/gocbconnstr"
)

Expand Down Expand Up @@ -116,7 +116,7 @@ func Connect(connStr string, opts ClusterOptions) (*Cluster, error) {
managementTimeout = opts.SearchTimeout
}
if opts.Transcoder == nil {
opts.Transcoder = NewDefaultTranscoder(&DefaultJSONSerializer{})
opts.Transcoder = NewJSONTranscoder(&DefaultJSONSerializer{})
}
if opts.Serializer == nil {
opts.Serializer = &DefaultJSONSerializer{}
Expand Down
5 changes: 2 additions & 3 deletions cluster_query_test.go
Expand Up @@ -9,9 +9,8 @@ import (
"testing"
"time"

gocbcore "github.com/couchbase/gocbcore/v8"
"github.com/pkg/errors"

"github.com/couchbase/gocbcore/v8"
)

func TestQuery(t *testing.T) {
Expand Down Expand Up @@ -1366,7 +1365,7 @@ func testGetClusterForHTTP(provider *mockHTTPProvider, n1qlTimeout, analyticsTim
c.sb.AnalyticsTimeout = analyticsTimeout
c.sb.SearchTimeout = searchTimeout

c.sb.Transcoder = NewDefaultTranscoder(&DefaultJSONSerializer{})
c.sb.Transcoder = NewJSONTranscoder(&DefaultJSONSerializer{})
c.sb.Serializer = &DefaultJSONSerializer{}

return c
Expand Down
26 changes: 18 additions & 8 deletions collection_binary_crud_test.go
Expand Up @@ -8,7 +8,10 @@ func TestBinaryAppend(t *testing.T) {
}
colBinary := globalCollection.Binary()

res, err := globalCollection.Upsert("binaryAppend", "foo", nil)
tcoder := NewRawBinaryTranscoder()
res, err := globalCollection.Upsert("binaryAppend", []byte("foo"), &UpsertOptions{
Transcoder: tcoder,
})
if err != nil {
t.Fatalf("Failed to Upsert, err: %v", err)
}
Expand All @@ -26,18 +29,20 @@ func TestBinaryAppend(t *testing.T) {
t.Fatalf("Expected Cas to be non-zero")
}

appendDoc, err := globalCollection.Get("binaryAppend", nil)
appendDoc, err := globalCollection.Get("binaryAppend", &GetOptions{
Transcoder: tcoder,
})
if err != nil {
t.Fatalf("Get failed, error was %v", err)
}

var appendContent string
var appendContent []byte
err = appendDoc.Content(&appendContent)
if err != nil {
t.Fatalf("Content failed, error was %v", err)
}

if appendContent != "foobar" {
if string(appendContent) != "foobar" {
t.Fatalf("Expected append result to be foobar but was %s", appendContent)
}
}
Expand All @@ -48,7 +53,10 @@ func TestBinaryPrepend(t *testing.T) {
}
colBinary := globalCollection.Binary()

res, err := globalCollection.Upsert("binaryPrepend", "foo", nil)
tcoder := NewRawBinaryTranscoder()
res, err := globalCollection.Upsert("binaryPrepend", []byte("foo"), &UpsertOptions{
Transcoder: tcoder,
})
if err != nil {
t.Fatalf("Failed to Upsert, err: %v", err)
}
Expand All @@ -66,18 +74,20 @@ func TestBinaryPrepend(t *testing.T) {
t.Fatalf("Expected Cas to be non-zero")
}

appendDoc, err := globalCollection.Get("binaryPrepend", nil)
appendDoc, err := globalCollection.Get("binaryPrepend", &GetOptions{
Transcoder: tcoder,
})
if err != nil {
t.Fatalf("Get failed, error was %v", err)
}

var appendContent string
var appendContent []byte
err = appendDoc.Content(&appendContent)
if err != nil {
t.Fatalf("Content failed, error was %v", err)
}

if appendContent != "barfoo" {
if string(appendContent) != "barfoo" {
t.Fatalf("Expected prepend result to be boofar but was %s", appendContent)
}
}
Expand Down
4 changes: 2 additions & 2 deletions results_test.go
Expand Up @@ -59,7 +59,7 @@ func TestGetResultContent(t *testing.T) {

res := GetResult{
contents: dataset,
transcoder: NewDefaultTranscoder(&DefaultJSONSerializer{}),
transcoder: NewJSONTranscoder(&DefaultJSONSerializer{}),
}

var doc testBeerDocument
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestGetResultFromSubDoc(t *testing.T) {
Address address `json:"address"`
}
var doc person
getResult := GetResult{transcoder: NewDefaultTranscoder(&DefaultJSONSerializer{})}
getResult := GetResult{transcoder: NewJSONTranscoder(&DefaultJSONSerializer{})}
err = getResult.fromSubDoc([]LookupInSpec{
{op: ops[0]},
{op: ops[1]},
Expand Down

0 comments on commit 07ab88c

Please sign in to comment.