Skip to content

Commit

Permalink
NCBC-159: Add debug option to view queries
Browse files Browse the repository at this point in the history
Change-Id: I99cee6738ca1fb096f2933fed24f3bbc45d04edb
Reviewed-on: http://review.couchbase.org/23788
Reviewed-by: Saakshi Manocha <saakshi.manocha@globallogic.com>
Tested-by: Saakshi Manocha <saakshi.manocha@globallogic.com>
  • Loading branch information
jzablocki authored and saakshimanocha committed Jan 25, 2013
1 parent 8a7d754 commit 17acec1
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
21 changes: 19 additions & 2 deletions src/Couchbase.Tests/CouchbaseClientViewTests.cs
Expand Up @@ -15,13 +15,30 @@ public class CouchbaseClientViewTests : CouchbaseClientViewTestsBase
/// @pre: Default configuration to initialize client in app.config and have view wih design document cities and view name by_name
/// @post: Test passes if debug info is returned correctly
/// </summary>
[Test]
public void When_Querying_Grouped_View_With_Debug_True_Debug_Info_Dictionary_Is_Returned()
{
var view = _Client.GetView("cities", "by_state").Group(true).Debug(true);
foreach (var item in view) { }

Assert.That(view.DebugInfo, Is.InstanceOf(typeof(Dictionary<string, object>)));
Console.WriteLine(view.DebugInfo.Keys.Count);
}

/// <summary>
/// @test: Retrieve view result with debug true should return debug information
/// of data type dictionary
/// @pre: Default configuration to initialize client in app.config and have view wih design document cities and view name by_name
/// @post: Test passes if debug info is returned correctly
/// </summary>
[Test]
public void When_Querying_View_With_Debug_True_Debug_Info_Dictionary_Is_Returned()
{
var view = _Client.GetView("cities", "by_name").Limit(1).Debug(true);
foreach (var item in view) { }

Assert.That(view.DebugInfo, Is.InstanceOf(typeof(Dictionary<string, object>)));
Console.WriteLine(view.DebugInfo.Keys.Count);
}

/// <summary>
Expand All @@ -30,9 +47,9 @@ public void When_Querying_View_With_Debug_True_Debug_Info_Dictionary_Is_Returned
/// @post: Test passes if no debug info is returned
/// </summary>
[Test]
public void When_Querying_View_With_Debug_False_Debug_Info_Dictionary_Is_Returned()
public void When_Querying_View_With_Debug_False_Debug_Info_Dictionary_Is_Null()
{
var view = _Client.GetView("cities", "by_name").Limit(1).Debug(true);
var view = _Client.GetView("cities", "by_name").Limit(1).Debug(false);
foreach (var item in view) { }

Assert.That(view.DebugInfo, Is.Null);
Expand Down
16 changes: 8 additions & 8 deletions src/Couchbase/CouchbaseViewHandler.cs
Expand Up @@ -46,7 +46,14 @@ public IEnumerator<T> TransformResults<T>(Func<JsonReader, T> rowTransformer, ID
{
if (jsonReader.TokenType == JsonToken.PropertyName && jsonReader.Depth == 1)
{
if (jsonReader.Value as string == "total_rows" && jsonReader.Read())
if (jsonReader.TokenType == JsonToken.PropertyName
&& jsonReader.Depth == 1
&& ((string)jsonReader.Value) == "debug_info")
{
var debugInfoJson = (JObject.ReadFrom(jsonReader) as JProperty).Value;
DebugInfo = JsonHelper.Deserialize<Dictionary<string, object>>(debugInfoJson.ToString());
}
else if (jsonReader.Value as string == "total_rows" && jsonReader.Read())
{
TotalRows = Convert.ToInt32(jsonReader.Value);
}
Expand Down Expand Up @@ -77,13 +84,6 @@ public IEnumerator<T> TransformResults<T>(Func<JsonReader, T> rowTransformer, ID
throw new InvalidOperationException("Cannot read view: " + formatted);
}
}
else if (jsonReader.TokenType == JsonToken.PropertyName
&& jsonReader.Depth == 1
&& ((string)jsonReader.Value) == "debug_info")
{
var debugInfoJson = (JObject.ReadFrom(jsonReader) as JProperty).Value;
DebugInfo = JsonHelper.Deserialize<Dictionary<string, object>>(debugInfoJson.ToString());
}
}
}
}
Expand Down

0 comments on commit 17acec1

Please sign in to comment.