Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications config #691

Merged
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
fa84ddc
set up
thelonelyvulpes Feb 3, 2023
e8cdda0
notifications
thelonelyvulpes Feb 3, 2023
02be906
handshake
thelonelyvulpes Feb 3, 2023
e019852
add bolt v5.1 messages and protocol, need to expose logoff message to…
thelonelyvulpes Feb 3, 2023
986079c
Merge branch 'feature/bolt-5.1' into feature/notifications-take-two
thelonelyvulpes Feb 3, 2023
b44da2a
some notifications
thelonelyvulpes Feb 3, 2023
e501a2e
fix build & mapping tests
thelonelyvulpes Feb 6, 2023
1b8ffe3
notifications working
thelonelyvulpes Feb 6, 2023
4ce2131
fix unit tests
thelonelyvulpes Feb 6, 2023
22b3ae6
update tests for notifications
thelonelyvulpes Feb 8, 2023
ff058c8
rename no notifications config methods and mark optimize internal
thelonelyvulpes Feb 8, 2023
617e33b
remove optimizations
thelonelyvulpes Feb 13, 2023
675ca39
Merge branch '5.0' into feature/notifications-take-two
thelonelyvulpes Mar 14, 2023
0a08e31
fix UT
thelonelyvulpes Mar 14, 2023
5224af8
fix for stub tests
thelonelyvulpes Mar 15, 2023
c91bdd8
Remove unneeded response handler
thelonelyvulpes Mar 17, 2023
4cdf964
tidying
thelonelyvulpes Mar 17, 2023
62ff8f8
Merge branch '5.0' into feature/notifications-take-two
thelonelyvulpes Mar 20, 2023
082293e
tidying and docs
thelonelyvulpes Mar 20, 2023
5296026
remove pointless null check.
thelonelyvulpes Mar 20, 2023
9492c58
fix build
thelonelyvulpes Mar 20, 2023
bec2c8d
remove magic values for testkit.
thelonelyvulpes Mar 27, 2023
564c8a7
remove magic value in writer
thelonelyvulpes Mar 27, 2023
c251edd
fix comments
thelonelyvulpes Mar 28, 2023
b94d2d4
move to 0th position
thelonelyvulpes Mar 28, 2023
a283188
block notifications config when not using 5.7
thelonelyvulpes Mar 29, 2023
e6c9ce6
fix create user test.
thelonelyvulpes Mar 30, 2023
c8d0b7e
disable test
thelonelyvulpes Mar 30, 2023
731a8ee
Merge branch 'tests/fix-ITs' into feature/notifications-take-two
thelonelyvulpes Mar 30, 2023
85db5c2
fix IT for 5.7
thelonelyvulpes Mar 30, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,8 @@ public void ShouldReturnNotifications()
null,
null,
null,
"WARNING")
"WARNING",
null)
}
},
options => options.ExcludingMissingMembers()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,27 @@ List<string> GetPaths()
configBuilder.WithFetchSize(data.fetchSize.Value);
}

var logger = new SimpleLogger();
if (data.notificationsMinSeverity != null || data.notificationsDisabledCategories != null)
{
if (data.notificationsMinSeverity == "OFF")
thelonelyvulpes marked this conversation as resolved.
Show resolved Hide resolved
{
configBuilder.WithNotificationsDisabled();
}
else
{
var sev = Enum.TryParse<Severity>(data.notificationsMinSeverity ?? "ignore", true, out var severity)
? (Severity?)severity
: null;

var cats = data.notificationsDisabledCategories
?.Select(x => Enum.Parse<Category>(x, true))
.ToArray();

configBuilder.WithNotifications(sev, cats);
}
}

var logger = new SimpleLogger();
configBuilder.WithLogger(logger);
}

Expand Down Expand Up @@ -177,5 +196,8 @@ public string[] trustedCertificates
}

public bool? encrypted { get; set; }

public string notificationsMinSeverity { get; set; }
public string[] notificationsDisabledCategories { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override NewDriver.NewDriverType ReadJson(
newDriverRequest.connectionAcquisitionTimeoutMs = jsonObj["connectionAcquisitionTimeoutMs"]?.Value<int?>();
newDriverRequest.fetchSize = jsonObj["fetchSize"]?.Value<long?>();
newDriverRequest.maxTxRetryTimeMs = jsonObj["maxTxRetryTimeMs"]?.Value<long?>();
newDriverRequest.notificationsMinSeverity = jsonObj["notificationsMinSeverity"]?.Value<string>();

if (jsonObj.TryGetValue("trustedCertificates", out var token))
{
Expand All @@ -59,6 +60,9 @@ public override NewDriver.NewDriverType ReadJson(
newDriverRequest.encrypted = token.Value<bool?>();
}

if (jsonObj.TryGetValue("notificationsDisabledCategories", out token))
newDriverRequest.notificationsDisabledCategories = token.ToObject<string[]>();

return newDriverRequest;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ private static object CreateNotificationList(IResultSummary summary)
return summary.Notifications.Select(
x => new
{
rawCategory = x.RawCategory ?? String.Empty,
category = x.Category.ToString().ToUpper(),
severity = x.Severity,
rawSeverityLevel = x.RawSeverityLevel ?? String.Empty,
severityLevel = x.SeverityLevel.ToString().ToUpper(),
description = x.Description,
code = x.Code,
title = x.Title
Expand All @@ -184,7 +188,11 @@ private static object CreateNotificationList(IResultSummary summary)
return summary.Notifications.Select(
x => new
{
rawCategory = x.RawCategory ?? String.Empty,
category = x.Category.ToString().ToUpper(),
severity = x.Severity,
rawSeverityLevel = x.RawSeverityLevel ?? String.Empty,
severityLevel = x.SeverityLevel.ToString().ToUpper(),
description = x.Description,
code = x.Code,
title = x.Title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Newtonsoft.Json;

Expand Down Expand Up @@ -85,6 +87,26 @@ private void SessionConfig(SessionConfigBuilder configBuilder)
ObjManager.GetObject<NewBookmarkManager>(data.bookmarkManagerId)
.BookmarkManager);
}

if (data.notificationsMinSeverity != null || data.notificationsDisabledCategories != null)
{
if (data.notificationsMinSeverity == "OFF")
{
configBuilder.WithNotificationsDisabled();
}
else
{
var sev = Enum.TryParse<Severity>(data.notificationsMinSeverity ?? "ignore", true, out var severity)
? (Severity?)severity
: null;

var cats = data.notificationsDisabledCategories
?.Select(x => Enum.Parse<Category>(x, true))
.ToArray();

configBuilder.WithNotifications(sev, cats);
}
}
}

public override async Task Process()
Expand Down Expand Up @@ -127,5 +149,10 @@ public class NewSessionType
public string impersonatedUser { get; set; }

public string bookmarkManagerId { get; set; }

public AuthorizationToken authorizationToken { get; set; }

public string notificationsMinSeverity { get; set; }
public string[] notificationsDisabledCategories { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ static SupportedFeatures()
"Feature:API:Driver.ExecuteQuery",
"Feature:API:Driver:GetServerInfo",
"Feature:API:Driver.IsEncrypted",
"Feature:API:Driver:NotificationsConfig",
"Feature:API:Driver.VerifyConnectivity",
//"Feature:API:Liveness.Check",
"Feature:API:Result.List",
"Feature:API:Result.Peek",
"Feature:API:Result.Single",
"Feature:API:Session:NotificationsConfig",
"Feature:API:SSLConfig",
"Feature:API:SSLSchemes",
"Feature:API:Type.Temporal",
Expand All @@ -51,6 +53,7 @@ static SupportedFeatures()
"Feature:Bolt:4.3",
"Feature:Bolt:4.4",
"Feature:Bolt:5.0",
"Feature:Bolt:5.2",
"Feature:Bolt:Patch:UTC",
"Feature:Impersonation",
//"Feature:TLS:1.1",
Expand Down
12 changes: 8 additions & 4 deletions Neo4j.Driver/Neo4j.Driver.Tests/AsyncSessionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ public async Task ShouldDelegateToProtocolRunAutoCommitTxAsync(bool reactive)
await session.RunAsync("lalalal");

mockConn.Verify(
x => x.RunInAutoCommitTransactionAsync(It.IsAny<AutoCommitParams>()),
x => x.RunInAutoCommitTransactionAsync(It.IsAny<AutoCommitParams>(),
It.IsAny<INotificationsConfig>()),
Times.Once);
}
}
Expand Down Expand Up @@ -207,7 +208,8 @@ public async void ShouldCloseConnectionOnRunIfBeginTxFailed()
It.IsAny<string>(),
It.IsAny<Bookmarks>(),
It.IsAny<TransactionConfig>(),
It.IsAny<string>()))
It.IsAny<string>(),
It.IsAny<INotificationsConfig>()))
.Throws(new IOException("Triggered an error when beginTx"));

var session = NewSession(mockConn.Object);
Expand Down Expand Up @@ -235,7 +237,8 @@ public async void ShouldCloseConnectionOnNewBeginTxIfBeginTxFailed()
It.IsAny<string>(),
It.IsAny<Bookmarks>(),
It.IsAny<TransactionConfig>(),
It.IsAny<string>()))
It.IsAny<string>(),
It.IsAny<INotificationsConfig>()))
.Returns(Task.CompletedTask)
.Callback(
() =>
Expand Down Expand Up @@ -274,7 +277,8 @@ public async void ShouldCloseConnectionIfBeginTxFailed()
It.IsAny<string>(),
It.IsAny<Bookmarks>(),
It.IsAny<TransactionConfig>(),
It.IsAny<string>()))
It.IsAny<string>(),
It.IsAny<INotificationsConfig>()))
.Throws(new IOException("Triggered an error when beginTx"));

var session = NewSession(mockConn.Object);
Expand Down
9 changes: 7 additions & 2 deletions Neo4j.Driver/Neo4j.Driver.Tests/ConnectionPoolTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,9 @@ public async Task ShouldCallConnInit()
await connectionPool.AcquireAsync(AccessMode.Read, null, null, Bookmarks.Empty);

//Then
mock.Verify(x => x.InitAsync(It.IsAny<CancellationToken>()), Times.Once);
mock.Verify(
x => x.InitAsync(It.IsAny<INotificationsConfig>(), It.IsAny<CancellationToken>()),
Times.Once);
}

[Fact]
Expand Down Expand Up @@ -217,7 +219,10 @@ public async Task ShouldCreateNewWhenQueueIsEmpty()
public async Task ShouldCloseConnectionIfFailedToCreate()
{
var connMock = new Mock<IPooledConnection>();
connMock.Setup(x => x.InitAsync(It.IsAny<CancellationToken>())).Throws<NotImplementedException>();
connMock.Setup(x => x.InitAsync(
It.IsAny<INotificationsConfig>(),
It.IsAny<CancellationToken>()))
.Throws<NotImplementedException>();

var connFactory = new MockedConnectionFactory(connMock.Object);
var pool = new ConnectionPool(connFactory);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,17 @@ public async Task ShouldConnectClient()
var conn = NewSocketConnection(mockClient.Object, boltProtocolFactory: bpFactory.Object);

// When
await conn.InitAsync();
await conn.InitAsync(null);

// Then
mockClient.Verify(c => c.ConnectAsync(null, CancellationToken.None), Times.Once);
protocolMock.Verify(x => x.LoginAsync(conn, It.IsAny<string>(), It.IsAny<IAuthToken>()), Times.Once);
protocolMock.Verify(
x => x.AuthenticateAsync(
conn,
It.IsAny<string>(),
It.IsAny<IAuthToken>(),
It.IsAny<INotificationsConfig>()),
Times.Once);
}

[Fact]
Expand All @@ -94,7 +100,7 @@ public async Task ShouldThrowClientErrorIfFailedToConnectToServerWithinTimeout()
// ReSharper disable once ObjectCreationAsStatement
var conn = new SocketConnection(mockClient.Object, AuthToken, UserAgent, Logger, Server);
// When
var error = await Record.ExceptionAsync(() => conn.InitAsync());
var error = await Record.ExceptionAsync(() => conn.InitAsync(null));
// Then
error.Should().BeOfType<IOException>();
error.Message.Should().Be("I will stop socket conn from initialization");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public void ShouldThrowWhenNotCommitMessage()
[InlineData(4, 3)]
[InlineData(4, 4)]
[InlineData(5, 0)]
[InlineData(5, 2)]
[InlineData(6, 0)]
public void ShouldSerialize(int major, int minor)
{
Expand All @@ -62,8 +63,8 @@ public void ShouldSerialize(int major, int minor)
"neo4j",
new InternalBookmarks("a"),
null,
null,
AccessMode.Read,
null,
null);

BeginMessageSerializer.Instance.Serialize(psw, message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
// limitations under the License.

using System;
using System.Collections.Generic;
using System.IO;
using FluentAssertions;
using Neo4j.Driver.Internal.Connector;
Expand Down Expand Up @@ -48,7 +49,6 @@ public void ShouldThrowIfPassedWrongMessage()
[InlineData(4, 3)]
[InlineData(4, 4)]
[InlineData(5, 0)]
[InlineData(6, 0)]
public void ShouldSerialize(int major, int minor)
{
using var memory = new MemoryStream();
Expand All @@ -58,7 +58,10 @@ public void ShouldSerialize(int major, int minor)

var psw = new PackStreamWriter(format, memory);

HelloMessageSerializer.Instance.Serialize(psw, new HelloMessage(boltProtocolVersion, "user", null, null));
HelloMessageSerializer.Instance.Serialize(
psw,
new HelloMessage(boltProtocolVersion, "user", null, null as IDictionary<string, string>));

memory.Position = 0;

var reader = new PackStreamReader(format, memory, new ByteBuffers());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void ShouldBeAbleToWriteRunWithMetadataMessage()
[Fact]
public void ShouldThrowIfPassedWrongMessage()
{
var message = new BeginMessage(BoltProtocolVersion.V3_0, "we", null, null, AccessMode.Read, null);
var message = new BeginMessage(BoltProtocolVersion.V3_0, "we", null, null, AccessMode.Read, null, null);
Record.Exception(() => RollbackMessageSerializer.Instance.Serialize(null, message))
.Should()
.BeOfType<ArgumentOutOfRangeException>();
Expand Down
Loading