-
Notifications
You must be signed in to change notification settings - Fork 248
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
NCBC-1453: Use JSON transcoder when reading updated bucket config
MOTIVATION ---------- It possible to configure a custom document content transcoder where the transcoder is responsible for encoding and decoding document bodies. However, if a NotMyVBucket response is received from the server, this transcoder is used to try and decode the updated bucket config. This is dangerous because the custom transcoder may not work with JSON and the response will always be JSON. MODIFICATIONS ------------- - Add an overload to IOperation.GetConfig that takes an ITypeTranscoder to be used for decoding the response body - Overload the new method on OperationBase to use the transcoder parameter instead of the content transcoder - Add ServerConfigTranscoder to IClusterController & ClusterController that internall resolves to a DefaultTranscoder - Update all internal usage of GetConfig to use the transcoder in IClusterController - Add unit tests to verify behaviour for both method variants RESULT ------ When a NotMyVBucket response is received, the SDK will use a JSON transcoder to decode the response instead of the custom transcoder. Change-Id: Ic2d0aa63653947070a7b8e18c378ce2b35386d81 Reviewed-on: http://review.couchbase.org/80524 Reviewed-by: Jeffry Morris <jeffrymorris@gmail.com> Tested-by: Build Bot <build@couchbase.com>
- Loading branch information
1 parent
8e67747
commit b349839
Showing
8 changed files
with
101 additions
and
9 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
Src/Couchbase.UnitTests/IO/Operations/OperationBaseTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using Couchbase.Configuration.Server.Serialization; | ||
using Couchbase.Core.Transcoders; | ||
using Couchbase.IO; | ||
using Couchbase.IO.Operations; | ||
using Moq; | ||
using NUnit.Framework; | ||
|
||
namespace Couchbase.UnitTests.IO.Operations | ||
{ | ||
[TestFixture] | ||
public class OperationBaseTests | ||
{ | ||
[Test] | ||
public void GetConfig_Without_Transcoder_Parameter_Uses_Content_Transcoder() | ||
{ | ||
var config = new BucketConfig(); | ||
var contentTranscoder = new Mock<ITypeTranscoder>(); | ||
contentTranscoder | ||
.Setup(transcoder => transcoder.Decode<BucketConfig>(It.IsAny<byte[]>(), It.IsAny<int>(), | ||
It.IsAny<int>(), It.IsAny<Flags>(), It.IsAny<OperationCode>())) | ||
.Returns(config); | ||
var operation = new FakeOperation(contentTranscoder.Object); | ||
|
||
var result = operation.GetConfig(); | ||
Assert.AreSame(config, result); | ||
|
||
// make sure the transcoder for decoding document content is not used | ||
contentTranscoder.Verify( | ||
t => t.Decode<BucketConfig>(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Flags>(), | ||
It.IsAny<OperationCode>()), Times.Once); | ||
} | ||
|
||
[Test] | ||
public void Getconfig_Uses_Paramater_Transcoder() | ||
{ | ||
var contentTranscoder = new Mock<ITypeTranscoder>(); | ||
var operation = new FakeOperation(contentTranscoder.Object); | ||
|
||
var config = new BucketConfig(); | ||
var configTranscoder = new Mock<ITypeTranscoder>(); | ||
configTranscoder | ||
.Setup(transcoder => transcoder.Decode<BucketConfig>(It.IsAny<byte[]>(), It.IsAny<int>(), | ||
It.IsAny<int>(), It.IsAny<Flags>(), It.IsAny<OperationCode>())) | ||
.Returns(config); | ||
|
||
var result = operation.GetConfig(configTranscoder.Object); | ||
Assert.AreSame(config, result); | ||
|
||
// make sure the transcoder for decoding document content is not used | ||
configTranscoder.Verify( | ||
t => t.Decode<BucketConfig>(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Flags>(), | ||
It.IsAny<OperationCode>()), Times.Once); | ||
contentTranscoder.Verify( | ||
t => t.Decode<BucketConfig>(It.IsAny<byte[]>(), It.IsAny<int>(), It.IsAny<int>(), It.IsAny<Flags>(), | ||
It.IsAny<OperationCode>()), Times.Never); | ||
} | ||
|
||
private class FakeOperation : OperationBase | ||
{ | ||
public FakeOperation(ITypeTranscoder transcoder) | ||
: base("hello", null, transcoder, 0) | ||
{ | ||
} | ||
|
||
public override OperationCode OperationCode | ||
{ | ||
get { return OperationCode.Get; } | ||
} | ||
|
||
public override ResponseStatus GetResponseStatus() | ||
{ | ||
return ResponseStatus.VBucketBelongsToAnotherServer; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters