public Task <IResultCursor> RunAsync(Query query, IConnection connection, IBoltProtocol protocol, ILogger logger, bool reactive, long fetchSize, out IState nextState) { nextState = Active; return(protocol.RunInExplicitTransactionAsync(connection, query, reactive, fetchSize)); }
internal static Mock <IConnection> MockedConnectionWithSuccessResponse(IBoltProtocol protocol = null) { var mockConn = new Mock <IConnection>(); // Whenever you enqueue any message, you immediately receives a response mockConn.Setup(x => x.EnqueueAsync(It.IsAny <IRequestMessage>(), It.IsAny <IResponseHandler>(), It.IsAny <IRequestMessage>(), It.IsAny <IResponseHandler>())) .Returns(Task.CompletedTask) .Callback <IRequestMessage, IResponseHandler, IRequestMessage, IResponseHandler>( (m1, h1, m2, h2) => { h1.OnSuccess(new Dictionary <string, object>()); if (m2 != null) { h2.OnSuccess(new Dictionary <string, object>()); } }); if (protocol == null) { var mockProtocol = new Mock <IBoltProtocol>(); protocol = mockProtocol.Object; } mockConn.Setup(x => x.BoltProtocol).Returns(protocol); mockConn.SetupGet(x => x.Mode).Returns(AccessMode.Write); return(mockConn); }
public Transaction(IConnection connection, ITransactionResourceHandler resourceHandler = null, ILogger logger = null, Bookmark bookmark = null) : base(logger) { _connection = new TransactionConnection(this, connection); _protocol = _connection.BoltProtocol; _resourceHandler = resourceHandler; Bookmark = bookmark; }
internal static Mock <IConnection> MockedConnectionWithSuccessResponse(IBoltProtocol protocol = null) { var mockConn = new Mock <IConnection>(); // Whenever you enqueue any message, you immediately receives a response mockConn.Setup(x => x.Enqueue(It.IsAny <IRequestMessage>(), It.IsAny <IMessageResponseCollector>(), It.IsAny <IRequestMessage>())) .Callback <IRequestMessage, IMessageResponseCollector, IRequestMessage>( (msg1, h, msg2) => { h?.DoneSuccess(); if (msg1 != null) { h?.DoneSuccess(); } }); if (protocol == null) { var mockProtocol = new Mock <IBoltProtocol>(); protocol = mockProtocol.Object; } mockConn.Setup(x => x.BoltProtocol).Returns(protocol); return(mockConn); }
internal static Session NewSession(IBoltProtocol protocol, ILogger logger = null, IRetryLogic retryLogic = null, AccessMode mode = AccessMode.Write, string bookmark = null) { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); mockConn.Setup(x => x.BoltProtocol).Returns(protocol); return(new Session(new TestConnectionProvider(mockConn.Object), logger, retryLogic, mode, Bookmark.From(bookmark))); }
public Task <IResultCursor> RunAsync(Query query, IConnection connection, IBoltProtocol protocol, ILogger logger, bool reactive, long fetchSize, out IState nextState) { throw new ClientException( "Cannot run query in this transaction, because it has already been committed."); }
public Task <IStatementResultCursor> RunAsync(Statement statement, IConnection connection, IBoltProtocol protocol, ILogger logger, bool reactive, long fetchSize, out IState nextState) { throw new ClientException( "Cannot run statement in this transaction, because it has already been rolled back."); }
public Task <IResultCursor> RunAsync(Query query, IConnection connection, IBoltProtocol protocol, ILogger logger, bool reactive, long fetchSize, out IState nextState) { throw new ClientException( "Cannot run query in this transaction, because it has been rolled back either because of an error or explicit termination."); }
internal static AsyncSession NewSession(IBoltProtocol protocol, bool reactive = false) { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); mockConn.Setup(x => x.BoltProtocol).Returns(protocol); return(new AsyncSession(new TestConnectionProvider(mockConn.Object), null, reactive: reactive)); }
public Transaction(IConnection connection, ITransactionResourceHandler resourceHandler = null, IDriverLogger logger = null, Bookmark bookmark = null) { _connection = new TransactionConnection(this, connection); _protocol = _connection.BoltProtocol; _resourceHandler = resourceHandler; _bookmark = bookmark; _logger = logger; }
private async Task EnqueAndSync(IBoltProtocol protocol) { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.Server).Returns(new ServerInfo(new Uri("http://neo4j.com"))); await protocol.LoginAsync(mockConn.Object, "user-andy", AuthTokens.None); mockConn.Verify( x => x.EnqueueAsync(It.IsAny <HelloMessage>(), It.IsAny <V3.HelloResponseHandler>(), null, null), Times.Once); mockConn.Verify(x => x.SyncAsync()); }
internal static Mock <IConnection> NewMockedConnection(IBoltProtocol boltProtocol = null) { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); if (boltProtocol == null) { boltProtocol = new Mock <IBoltProtocol>().Object; } mockConn.Setup(x => x.BoltProtocol).Returns(boltProtocol); return(mockConn); }
public AsyncTransaction(IConnection connection, ITransactionResourceHandler resourceHandler, ILogger logger = null, string database = null, Bookmark bookmark = null, bool reactive = false, long fetchSize = Config.Infinite) { _connection = new TransactionConnection(this, connection); _protocol = _connection.BoltProtocol; _resourceHandler = resourceHandler ?? throw new ArgumentNullException(nameof(resourceHandler)); _bookmark = bookmark; _logger = logger; _reactive = reactive; _database = database; _fetchSize = fetchSize; }
public void Start() { _connMetricsListener?.ConnectionConnecting(_connEvent); _tcpSocketClient.Connect(_uri); SetOpened(); _logger?.Debug($"~~ [CONNECT] {_uri}"); _connMetricsListener?.ConnectionConnected(_connEvent); var version = DoHandshake(); _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger); }
public void Init() { try { _boltProtocol = _client.Connect(); _boltProtocol.Authenticate(this, _userAgent, _authToken); } catch (AggregateException e) { // To remove the wrapper around the inner exception because of Task.Wait() throw e.InnerException; } }
public async Task InitAsync() { _sendLock.Wait(); try { _boltProtocol = await _client.ConnectAsync(RoutingContext).ConfigureAwait(false); } finally { _sendLock.Release(); } await _boltProtocol.LoginAsync(this, _userAgent, _authToken).ConfigureAwait(false); }
public Task StartAsync() { TaskCompletionSource <object> tcs = new TaskCompletionSource <object>(); _connMetricsListener?.ConnectionConnecting(_connEvent); _tcpSocketClient.ConnectAsync(_uri) .ContinueWith(t => { if (t.IsFaulted) { tcs.SetException(t.Exception.GetBaseException()); } else if (t.IsCanceled) { tcs.SetCanceled(); } else { SetOpened(); _logger?.Debug($"~~ [CONNECT] {_uri}"); _connMetricsListener?.ConnectionConnected(_connEvent); return(DoHandshakeAsync()); } return(Task.FromResult(-1)); }, TaskContinuationOptions.ExecuteSynchronously).Unwrap() .ContinueWith(t => { int version = t.Result; if (version != -1) { try { _boltProtocol = BoltProtocolFactory.Create(version, _tcpSocketClient, _bufferSettings, _logger); tcs.SetResult(null); } catch (AggregateException exc) { tcs.SetException(exc.GetBaseException()); } catch (Exception exc) { tcs.SetException(exc); } } }, TaskContinuationOptions.ExecuteSynchronously); return(tcs.Task); }
internal static Mock <IConnection> NewMockedConnection(IBoltProtocol boltProtocol = null) { var mockConn = new Mock <IConnection>(); mockConn.Setup(x => x.IsOpen).Returns(true); if (boltProtocol == null) { var protocol = new Mock <IBoltProtocol>(); protocol.Setup(x => x.LoginAsync(It.IsAny <IConnection>(), It.IsAny <string>(), It.IsAny <IAuthToken>())) .Returns(Task.CompletedTask); protocol.Setup(x => x.RunInAutoCommitTransactionAsync(It.IsAny <IConnection>(), It.IsAny <Query>(), false, It.IsAny <IBookmarkTracker>(), It.IsAny <IResultResourceHandler>(), It.IsAny <string>(), It.IsAny <Bookmark>(), It.IsAny <TransactionConfig>(), It.IsAny <long>())) .ReturnsAsync(new Mock <IResultCursor>().Object); protocol.Setup(x => x.BeginTransactionAsync(It.IsAny <IConnection>(), It.IsAny <string>(), It.IsAny <Bookmark>(), It.IsAny <TransactionConfig>())) .Returns(Task.CompletedTask); protocol.Setup(x => x.RunInExplicitTransactionAsync(It.IsAny <IConnection>(), It.IsAny <Query>(), false, It.IsAny <long>())) .ReturnsAsync(new Mock <IResultCursor>().Object); protocol.Setup(x => x.CommitTransactionAsync(It.IsAny <IConnection>(), It.IsAny <IBookmarkTracker>())) .Returns(Task.CompletedTask); protocol.Setup(x => x.RollbackTransactionAsync(It.IsAny <IConnection>())) .Returns(Task.CompletedTask); protocol.Setup(x => x.ResetAsync(It.IsAny <IConnection>())) .Returns(Task.CompletedTask); protocol.Setup(x => x.LogoutAsync(It.IsAny <IConnection>())) .Returns(Task.CompletedTask); boltProtocol = protocol.Object; } mockConn.Setup(x => x.BoltProtocol).Returns(boltProtocol); return(mockConn); }
public void ResetMessageReaderAndWriterForServerV3_1(IBoltProtocol boltProtocol) { Reader = boltProtocol.NewReader(_tcpSocketClient.ReadStream, _bufferSettings, _logger, false); Writer = boltProtocol.NewWriter(_tcpSocketClient.WriteStream, _bufferSettings, _logger, false); }
public Task CommitAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { throw new ClientException( "Cannot commit this transaction, because it has been rolled back either because of an error or explicit termination."); }
public Task CommitAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { nextState = Committed; return(protocol.CommitTransactionAsync(connection, tracker)); }
public async Task InitAsync() { _boltProtocol = await _client.ConnectAsync().ConfigureAwait(false); await _boltProtocol.AuthenticateAsync(this, _userAgent, _authToken).ConfigureAwait(false); }
// For testing only internal SocketClient(IBoltProtocol boltProtocol, ITcpSocketClient socketClient = null) { _boltProtocol = boltProtocol; _tcpSocketClient = socketClient; }
public Task RollbackAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { nextState = RolledBack; return(protocol.RollbackTransactionAsync(connection)); }
public Task CommitAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { throw new ClientException("Cannot commit this transaction, because it has already been committed."); }
public Task RollbackAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { throw new ClientException("Cannot rollback this transaction, because it has already been rolled back."); }
public Task RollbackAsync(IConnection connection, IBoltProtocol protocol, IBookmarkTracker tracker, out IState nextState) { nextState = Failed; return(Task.CompletedTask); }