public async Task ShouldDiscoverEndpointsForDefaultDatabase() { using (BoltStubServer.Start("V4/acquire_endpoints_default_database", 9001)) { using (BoltStubServer.Start("V4/read", 9005)) { using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, _setupConfig)) { var session = driver.AsyncSession(o => o.WithDefaultAccessMode(AccessMode.Read)); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } } } } }
public void ShouldThrowOnInvalidRoutingTable() { using (BoltStubServer.Start("V4/acquire_endpoints_aDatabase_no_servers", 9001)) { using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, _setupConfig)) { this.Awaiting(async _ => { var session = driver.AsyncSession(o => o.WithDatabase("aDatabase").WithDefaultAccessMode(AccessMode.Read)); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } }) .Should() .Throw <ServiceUnavailableException>() .WithMessage("Failed to connect to any routing server.*"); } } }
public async Task ShouldDiscoverEndpointsForADatabaseWithBookmarks() { using (BoltStubServer.Start("V4/acquire_endpoints_aDatabase_with_bookmark", 9001)) { using (BoltStubServer.Start("V4/read_from_aDatabase_with_bookmark", 9005)) { var bookmark1 = Bookmark.From("system:1111"); var bookmark2 = Bookmark.From("aDatabase:5555"); using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, _setupConfig)) { var session = driver.AsyncSession(o => o.WithDatabase("aDatabase").WithDefaultAccessMode(AccessMode.Read) .WithBookmarks(bookmark1, bookmark2)); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } } } } }
public void ShouldThrowOnProcedureNotFound() { using (BoltStubServer.Start("V4/acquire_endpoints_db_not_found", 9001)) { using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, _setupConfig)) { this.Awaiting(async _ => { var session = driver.AsyncSession(o => o.WithDatabase("aDatabase").WithDefaultAccessMode(AccessMode.Read)); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } }) .Should() .Throw <FatalDiscoveryException>() .WithMessage("database not found"); } } }
public async Task ShouldOnlyResetAfterError(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/rollback_error", 9001)) { var uri = new Uri("bolt://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, SetupConfig)) { var session = driver.AsyncSession(); try { var txc = await session.BeginTransactionAsync(); try { var result = await txc.RunAsync("CREATE (n {name:'Alice'}) RETURN n.name AS name"); var exception = await Record.ExceptionAsync(() => result.ConsumeAsync()); exception.Should().BeOfType <TransientException>(); } finally { await txc.RollbackAsync(); } } finally { await session.CloseAsync(); } } } }
public async Task SendRoutingContextToServer() { using (BoltStubServer.Start("get_routing_table_with_context", 9001)) { var uri = new Uri("bolt+routing://127.0.0.1:9001/?policy=my_policy®ion=china"); using (var driver = GraphDatabase.Driver(uri, Config)) { var session = driver.AsyncSession(); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name AS name"); var records = await cursor.ToListAsync(); records.Count.Should().Be(2); records[0]["name"].ValueAs <string>().Should().Be("Alice"); records[1]["name"].ValueAs <string>().Should().Be("Bob"); } finally { await session.CloseAsync(); } } } }
public async Task InvokeProcedureGetRoutingTableWhenServerVersionPermits() { using (BoltStubServer.Start("get_routing_table", 9001)) { var uri = new Uri("bolt+routing://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, Config)) { var session = driver.AsyncSession(); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name AS name"); var records = await cursor.ToListAsync(); records.Count.Should().Be(3); records[0]["name"].ValueAs <string>().Should().Be("Alice"); records[1]["name"].ValueAs <string>().Should().Be("Bob"); records[2]["name"].ValueAs <string>().Should().Be("Eve"); } finally { await session.CloseAsync(); } } } }
public async Task ShouldVerifyConnectivity(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/verify_connectivity", 9001)) { using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, SetupConfig)) { await driver.VerifyConnectivityAsync(); } } }
public async Task ShouldVerifyConnectivity(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/supports_multidb", 9001)) { using (var driver = GraphDatabase.Driver("bolt://127.0.0.1:9001", AuthTokens.None, SetupConfig)) { await driver.VerifyConnectivityAsync(); } } }
public async Task ShouldThrowSecurityErrorWhenFailToHello(string boltVersion, string scheme) { using (BoltStubServer.Start($"{boltVersion}/fail_to_auth", 9001)) { using (var driver = GraphDatabase.Driver($"{scheme}://127.0.0.1:9001", AuthTokens.None, _setupConfig)) { var error = await Record.ExceptionAsync(() => driver.SupportsMultiDbAsync()); error.Should().BeOfType <AuthenticationException>(); error.Message.Should().StartWith("blabla"); } } }
public async Task ShouldThrowSecurityErrorWhenFailedToHello(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/fail_to_auth", 9001)) { using (var driver = GraphDatabase.Driver("neo4j://localhost:9001", AuthTokens.None, SetupConfig)) { var error = await Record.ExceptionAsync(() => driver.VerifyConnectivityAsync()); error.Should().BeOfType <AuthenticationException>(); error.Message.Should().StartWith("blabla"); } } }
public void SendRoutingContextToServer() { using (BoltStubServer.Start("get_routing_table_with_context", 9001)) { var uri = new Uri("bolt+routing://127.0.0.1:9001/?policy=my_policy®ion=china"); using (var driver = GraphDatabase.Driver(uri, BoltStubServer.Config)) using (var session = driver.Session()) { var records = session.Run("MATCH (n) RETURN n.name AS name").ToList(); records.Count.Should().Be(2); records[0]["name"].ValueAs <string>().Should().Be("Alice"); records[1]["name"].ValueAs <string>().Should().Be("Bob"); } } }
public void InvokeProcedureGetRoutingTableWhenServerVersionPermits() { using (BoltStubServer.Start("get_routing_table", 9001)) { var uri = new Uri("bolt+routing://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, BoltStubServer.Config)) using (var session = driver.Session()) { var records = session.Run("MATCH (n) RETURN n.name AS name").ToList(); records.Count.Should().Be(3); records[0]["name"].ValueAs <string>().Should().Be("Alice"); records[1]["name"].ValueAs <string>().Should().Be("Bob"); records[2]["name"].ValueAs <string>().Should().Be("Eve"); } } }
public void ShouldOnlyResetAfterError() { using (BoltStubServer.Start("rollback_error", 9001)) { var uri = new Uri("bolt://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, BoltStubServer.Config)) using (var session = driver.Session()) { var tx = session.BeginTransaction(); var result = tx.Run("CREATE (n {name:'Alice'}) RETURN n.name AS name"); var exception = Record.Exception(() => result.Consume()); exception.Should().BeOfType <TransientException>(); tx.Dispose(); } } }
public async Task CanSendMultipleBookmarks() { var bookmarks = new[] { "neo4j:bookmark:v1:tx5", "neo4j:bookmark:v1:tx29", "neo4j:bookmark:v1:tx94", "neo4j:bookmark:v1:tx56", "neo4j:bookmark:v1:tx16", "neo4j:bookmark:v1:tx68" }; using (BoltStubServer.Start("V4/multiple_bookmarks", 9001)) { var uri = new Uri("bolt://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, SetupConfig)) { var session = driver.AsyncSession(o => o.WithBookmarks(Bookmark.From(bookmarks))); try { var txc = await session.BeginTransactionAsync(); try { await txc.RunAsync("CREATE (n {name:'Bob'})"); await txc.CommitAsync(); } catch { await txc.RollbackAsync(); throw; } } catch (Exception ex) { string var = ex.Message; } finally { await session.CloseAsync(); } session.LastBookmark.Should().Be(Bookmark.From("neo4j:bookmark:v1:tx95")); } } }
public void ShouldDiscardTxIfNotFinished() { using (BoltStubServer.Start("V4/discard_streaming_records_tx", 9001)) { using (var driver = GraphDatabase.Driver("bolt://localhost:9001", AuthTokens.None, o => o.WithLogger(TestLogger.Create(_output)).WithFetchSize(2))) { var session = driver.RxSession(); session.ReadTransaction(tx => tx.Run("UNWIND [1,2,3,4] AS n RETURN n").Keys()) .WaitForCompletion() .AssertEqual( OnNext(0, Utils.MatchesKeys("n")), OnCompleted <string[]>(0)); session.Close <string>().WaitForCompletion().AssertEqual(OnCompleted <string>(0)); } } }
public void TestCustomResolverExample() { using (var server1 = BoltStubServer.Start("get_routing_table_only", 9001)) { using (var server2 = BoltStubServer.Start("return_1", 9002)) { using (var driver = CreateDriverWithCustomResolver("bolt+routing://x.acme.com", AuthTokens.None, ServerAddress.From("localhost", 9001))) { using (var session = driver.Session(AccessMode.Read)) { // When & Then session.Run("RETURN 1").Single()[0].As <int>().Should().Be(1); } } } } }
[InlineData("V4_1")] //Use same script on all versions after 4.1 public async Task ShouldNotThrowOnNoopMessages(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/noop", 9001)) { using (var driver = GraphDatabase.Driver("bolt://127.0.0.1:9001", AuthTokens.None, SetupConfig)) { //await driver.VerifyConnectivityAsync(); var session = driver.AsyncSession(); try { var cursor = await session.RunAsync("MATCH (N) RETURN n.name"); } finally { await session.CloseAsync(); } } } }
public void TestCustomResolverExample() { using (var server1 = BoltStubServer.Start("V4/get_routing_table_only", 9001)) { using (var server2 = BoltStubServer.Start("V4/return_1", 9002)) { using (var driver = CreateDriverWithCustomResolver("neo4j://x.example.com", AuthTokens.None, ServerAddress.From("127.0.0.1", 9001))) { using (var session = driver.Session(o => o.WithDefaultAccessMode(AccessMode.Read))) { // When & Then session.Run("RETURN 1").Single()[0].As <int>().Should().Be(1); } } } } }
public async Task ShouldDetectMultiDatabasesFeature(string boltVersion, string scheme) { using (BoltStubServer.Start($"{boltVersion}/supports_multidb", 9001)) { using (var driver = GraphDatabase.Driver($"{scheme}://127.0.0.1:9001", AuthTokens.None, _setupConfig)) { var support = await driver.SupportsMultiDbAsync(); if (boltVersion.Equals("V3")) { support.Should().BeFalse(); } else { support.Should().BeTrue(); } } } }
public void ShouldFailIfCommitFailsDueToBrokenConnection(string boltVersion) { using (BoltStubServer.Start($"{boltVersion}/connection_error_on_commit", 9001)) { using (var driver = GraphDatabase.Driver("bolt://127.0.0.1:9001", AuthTokens.None, NoEncryptionAndShortRetry)) { using (var session = driver.Session(o => o.WithDefaultAccessMode(AccessMode.Write))) { var txc = session.BeginTransaction(); var result = txc.Run("CREATE (n {name: 'Bob'})"); var exc = Record.Exception(() => txc.Commit()); exc.Should().BeOfType <ServiceUnavailableException>().Which .HasCause <IOException>().Should().BeTrue(); } } } }
public async Task ShouldLogServerAddress() { var logs = new List <string>(); void SetupConfig(ConfigBuilder o) { o.WithEncryptionLevel(EncryptionLevel.None); o.WithLogger(new TestLogger(logs.Add, ExtendedLogLevel.Debug)); } using (BoltStubServer.Start("V4/accessmode_reader_implicit", 9001)) { using (var driver = GraphDatabase.Driver("bolt://localhost:9001", AuthTokens.None, SetupConfig)) { var session = driver.AsyncSession(o => o.WithDefaultAccessMode(AccessMode.Read)); try { var cursor = await session.RunAsync("RETURN $x", new { x = 1 }); var list = await cursor.ToListAsync(r => Convert.ToInt32(r[0])); list.Should().HaveCount(1).And.Contain(1); } finally { await session.CloseAsync(); } } } foreach (var log in logs) { if (log.StartsWith("[Debug]:[conn-")) { log.Should().Contain("localhost:9001"); } } }
public void ShouldFailIfCommitFailsDueToBrokenConnection(string boltVersion) { using (BoltStubServer.Start($"connection_error_on_commit_{boltVersion}", 9001)) { using (var driver = GraphDatabase.Driver("bolt://localhost:9001", AuthTokens.None, NoEncryptionAndShortRetry)) { var session = driver.Session(AccessMode.Write); try { var exc = Record.Exception(() => session.WriteTransaction(txc => txc.Run("CREATE (n {name: 'Bob'})")) ); exc.Should().BeOfType <ServiceUnavailableException>().Which .HasCause <IOException>().Should().BeTrue(); } finally { session.Dispose(); } } } }
public async Task ShouldDiscoverEndpointsForADatabaseAndWrite() { using (BoltStubServer.Start("V4/acquire_endpoints_aDatabase", 9001)) { using (BoltStubServer.Start("V4/write_to_aDatabase", 9007)) { using (var driver = GraphDatabase.Driver("neo4j://127.0.0.1:9001", AuthTokens.None, _setupConfig)) { var session = driver.AsyncSession(o => o.WithDatabase("aDatabase").WithDefaultAccessMode(AccessMode.Write)); try { await session.RunAndConsumeAsync("CREATE (n {name:'Bob'})"); } finally { await session.CloseAsync(); } } } } }
public async Task RunOnReadModeSessionShouldGoToReader() { using (BoltStubServer.Start("V4/accessmode_router", 9001)) { using (BoltStubServer.Start("V4/accessmode_reader_implicit", 9003)) { using (var driver = GraphDatabase.Driver("neo4j://127.0.0.1:9001", AuthTokens.None, NoEncryption)) { var session = driver.AsyncSession(o => o.WithDefaultAccessMode(AccessMode.Read)); try { var result = await session.RunAndSingleAsync("RETURN $x", new { x = 1 }, r => r[0].As <int>()); result.Should().Be(1); } finally { await session.CloseAsync(); } } } } }
public async Task ShouldAllowChangeFetchSize() { using (BoltStubServer.Start("V4/streaming_records", 9001)) { using (var driver = GraphDatabase.Driver("bolt://localhost:9001", AuthTokens.None, o => o.WithLogger(TestLogger.Create(_output)).WithFetchSize(2))) { var session = driver.AsyncSession(); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } } } }
public async Task ShouldStreamingWithAsyncSession() { using (BoltStubServer.Start("V4/streaming_records_all", 9001)) { using (var driver = GraphDatabase.Driver("bolt://localhost:9001", AuthTokens.None, _setupConfig)) { var session = driver.AsyncSession(); try { var cursor = await session.RunAsync("MATCH (n) RETURN n.name"); var result = await cursor.ToListAsync(r => r[0].As <string>()); result.Should().BeEquivalentTo("Bob", "Alice", "Tina"); } finally { await session.CloseAsync(); } } } }
public void CanSendMultipleBookmarks() { var bookmarks = new[] { "neo4j:bookmark:v1:tx5", "neo4j:bookmark:v1:tx29", "neo4j:bookmark:v1:tx94", "neo4j:bookmark:v1:tx56", "neo4j:bookmark:v1:tx16", "neo4j:bookmark:v1:tx68" }; using (BoltStubServer.Start("multiple_bookmarks", 9001)) { var uri = new Uri("bolt://127.0.0.1:9001"); using (var driver = GraphDatabase.Driver(uri, BoltStubServer.Config)) using (var session = driver.Session(bookmarks)) { using (var tx = session.BeginTransaction()) { tx.Run("CREATE (n {name:'Bob'})"); tx.Success(); } session.LastBookmark.Should().Be("neo4j:bookmark:v1:tx95"); } } }