From 39fe01035553af2f7a78282076aff81c43b53a99 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 13 Jan 2022 15:35:48 +0100 Subject: [PATCH 1/4] Add Result.peek support to TestKit back end --- .../Protocol/Protocol.cs | 3 +- .../Protocol/Result/Result.cs | 6 +++ .../Protocol/Result/ResultPeek.cs | 42 +++++++++++++++++++ .../SupportedFeatures.cs | 6 +-- 4 files changed, 53 insertions(+), 4 deletions(-) create mode 100644 Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Protocol.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Protocol.cs index ad1db5590..5f8fd9181 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Protocol.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Protocol.cs @@ -41,6 +41,7 @@ public static class Protocol typeof(SessionBeginTransaction), typeof(Result), typeof(ResultNext), + typeof(ResultPeek), typeof(ResultConsume), typeof(RetryablePositive), typeof(RetryableNegative), @@ -69,7 +70,7 @@ public static void ValidateType(string typeName) catch { throw new TestKitProtocolException($"Attempting to use an unrecognized protocol type: {typeName}"); - } + } } public static void ValidateType(Type objectType) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs index 1f19d66c2..d58ab9594 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs @@ -41,6 +41,12 @@ public async Task GetNextRecord() return await Task.FromResult(null); } + public async Task PeekRecord() + { + IRecord record = await ResultCursor.PeekAsync(); + return await Task.FromResult(record); + } + public async Task ConsumeResults() { return await ResultCursor.ConsumeAsync().ConfigureAwait(false); diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs new file mode 100644 index 000000000..840fa48d3 --- /dev/null +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs @@ -0,0 +1,42 @@ +using System; +using Newtonsoft.Json; +using System.Threading.Tasks; +using Neo4j.Driver; +using System.Linq; +using System.Diagnostics; + + +namespace Neo4j.Driver.Tests.TestBackend +{ + internal class ResultPeek : IProtocolObject + { + public ResultPeekType data { get; set; } = new ResultPeekType(); + [JsonIgnore] + public IRecord Records { get; set; } + + public class ResultPeekType + { + public string resultId { get; set; } + } + + public override async Task Process() + { + var result = (Result)ObjManager.GetObject(data.resultId); + Records = await result.PeekRecord(); + } + + public override string Respond() + { + if (!(Records is null)) + { + //Generate list of ordered records + var valuesList = Records.Keys.Select(v => NativeToCypher.Convert(Records[v])); + return new ProtocolResponse("Record", new { values = valuesList }).Encode(); + } + else + { + return new ProtocolResponse("NullRecord", (object)null).Encode(); + } + } + } +} diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs index a45d81d72..dca53940a 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/SupportedFeatures.cs @@ -13,9 +13,9 @@ internal static class SupportedFeatures static SupportedFeatures() { FeaturesList.Add("AuthorizationExpiredTreatment"); - + FeaturesList.Add("ConfHint:connection.recv_timeout_seconds"); - + FeaturesList.Add("Optimization:EagerTransactionBegin"); FeaturesList.Add("Feature:Auth:Bearer"); @@ -34,7 +34,7 @@ static SupportedFeatures() //FeaturesList.Add("Feature:API:SSLSchemes"); //FeaturesList.Add("Feature:API:Result.Single"); - //FeaturesList.Add("Feature:API:Result.Peek"); + FeaturesList.Add("Feature:API:Result.Peek"); //FeaturesList.Add("Feature:API:Result.List"); From 81448ba0d581f6a474ee8c0bcf51ce2c1b30e5d8 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Thu, 13 Jan 2022 15:41:35 +0100 Subject: [PATCH 2/4] Code style --- .../Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs index d58ab9594..a716011c9 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/Result.cs @@ -41,10 +41,9 @@ public async Task GetNextRecord() return await Task.FromResult(null); } - public async Task PeekRecord() + public Task PeekRecord() { - IRecord record = await ResultCursor.PeekAsync(); - return await Task.FromResult(record); + return ResultCursor.PeekAsync(); } public async Task ConsumeResults() From 66ff168acade49f405c9805d6cd9d6113304303e Mon Sep 17 00:00:00 2001 From: grant lodge <6323995+thelonelyvulpes@users.noreply.github.com> Date: Thu, 13 Jan 2022 16:13:35 +0000 Subject: [PATCH 3/4] reverse logic --- .../Protocol/Result/ResultPeek.cs | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs index 840fa48d3..b93dae648 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs @@ -1,10 +1,6 @@ -using System; -using Newtonsoft.Json; +using Newtonsoft.Json; using System.Threading.Tasks; -using Neo4j.Driver; using System.Linq; -using System.Diagnostics; - namespace Neo4j.Driver.Tests.TestBackend { @@ -27,16 +23,12 @@ public override async Task Process() public override string Respond() { - if (!(Records is null)) - { - //Generate list of ordered records - var valuesList = Records.Keys.Select(v => NativeToCypher.Convert(Records[v])); - return new ProtocolResponse("Record", new { values = valuesList }).Encode(); - } - else - { + if (Records is null) return new ProtocolResponse("NullRecord", (object)null).Encode(); - } + + //Generate list of ordered records + var valuesList = Records.Keys.Select(v => NativeToCypher.Convert(Records[v])); + return new ProtocolResponse("Record", new { values = valuesList }).Encode(); } } } From 21b802967261c3579881ebd15085788392369335 Mon Sep 17 00:00:00 2001 From: Rouven Bauer Date: Fri, 14 Jan 2022 11:16:05 +0100 Subject: [PATCH 4/4] Remove `JsonIgnore` from class that never gets serialized --- .../Protocol/Result/ResultPeek.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs index b93dae648..1ff91e908 100644 --- a/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs +++ b/Neo4j.Driver/Neo4j.Driver.Tests.TestBackend/Protocol/Result/ResultPeek.cs @@ -7,7 +7,7 @@ namespace Neo4j.Driver.Tests.TestBackend internal class ResultPeek : IProtocolObject { public ResultPeekType data { get; set; } = new ResultPeekType(); - [JsonIgnore] + public IRecord Records { get; set; } public class ResultPeekType