Created
July 4, 2017 10:46
-
-
Save MikeGoldsmith/4206a3924846936e76e6a32b2efa6dba to your computer and use it in GitHub Desktop.
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
[Test] | |
public async Task Test_Enhanced_Error_Messages() | |
{ | |
// boostrap client | |
var config = TestConfiguration.GetConfiguration("basic"); | |
config.BucketConfigs = new Dictionary<string, BucketConfiguration> | |
{ | |
{"default", new BucketConfiguration {UseKvErrorMap = true}} | |
}; | |
var serverUri = config.Servers.First(); | |
using (var client = new HttpClient()) | |
{ | |
using (var cluster = new Cluster(config)) | |
{ | |
var bucket = cluster.OpenBucket("default"); | |
// preload document to ensure everything is connected and working as expected | |
const string documentKey = "hello"; | |
var upsertResult = await bucket.UpsertAsync(documentKey, new { }); | |
Assert.IsTrue(upsertResult.Success); | |
// Get server index for the key | |
var vbucket = (bucket as CouchbaseBucket).GetKeyMapper().MapKey(documentKey) as IVBucket; | |
var serverIndex = vbucket.Primary; | |
// enable enhanced error messages | |
var response = await client.GetAsync(new Uri(serverUri, string.Format("mock/set_enhanced_errors?enabled={0}", true))); | |
Assert.IsTrue(CheckContentIsValid(response)); | |
// setup opcode failure | |
const int errorCode = 1; // not stored | |
response = await client.GetAsync(new Uri(serverUri, string.Format("mock/opfail?servers=[{0}]&bucket=default&count=-1&code={1}", serverIndex, errorCode))); | |
Assert.IsTrue(CheckContentIsValid(response)); | |
// execute get operation - should contain enhanced error information | |
var result = await bucket.GetAsync<dynamic>(documentKey); | |
Assert.IsFalse(result.Success); | |
// stop opfail failures | |
response = await client.GetAsync(new Uri(serverUri, string.Format("mock/opfail?servers=[{0}]&bucket=default&count=0&code=0", serverIndex))); | |
Assert.IsTrue(CheckContentIsValid(response)); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment