public void ShouldAllowToSetToNewValue() { var config = new TransactionConfig(); config.Metadata = new Dictionary <string, object> { { "key", "value" } }; config.Metadata.Should().HaveCount(1).And.Contain(new KeyValuePair <string, object>("key", "value")); }
private void AssertNullOrEmptyTransactionConfig(TransactionConfig txConfig) { if (txConfig != null && !txConfig.IsEmpty()) { throw new ArgumentException( "Driver is connected to the database that does not support transaction configuration. " + "Please upgrade to neo4j 3.5.0 or later in order to use this functionality"); } }
private Task RunTransactionAsync(AccessMode mode, Func <IAsyncTransaction, Task> work, TransactionConfig txConfig) { return(RunTransactionAsync(mode, async tx => { await work(tx).ConfigureAwait(false); var ignored = 1; return ignored; }, txConfig)); }
public IStatementResult Run(Statement statement, TransactionConfig txConfig) { return(TryExecute(_logger, () => { EnsureCanRunMoreStatements(); _connection = _connectionProvider.Acquire(_defaultMode); var protocol = _connection.BoltProtocol; return protocol.RunInAutoCommitTransaction(_connection, statement, this, _bookmark, txConfig); })); }
public Task <IStatementResultCursor> RunAsync(Statement statement, TransactionConfig txConfig) { return(TryExecuteAsync(_logger, async() => { await EnsureCanRunMoreStatementsAsync().ConfigureAwait(false); _connection = await _connectionProvider.AcquireAsync(_defaultMode).ConfigureAwait(false); var protocol = _connection.BoltProtocol; return await protocol.RunInAutoCommitTransactionAsync(_connection, statement, this, _bookmark, txConfig).ConfigureAwait(false); })); }
public TransactionClient(ICluster cluster, TransactionConfig config) { _cluster = cluster; _startedAt = DateTime.UtcNow; Config = config; // setup retry policy using Polly //TODO: handle retryable exceptions differently _policy = Policy.Handle <Exception>().Retry(Config.MaxAttempts); }
public Transaction(TransactionConfig trConfig, IDevice sourceDevice, IDevice targetDevice, IDataPoint dataPoint, ILogger logger) { this.logger = logger; this.config = trConfig; this.sourceDevice = sourceDevice; this.targetDevice = targetDevice; this.dataPoint = dataPoint; this.TriggerQueue = new BlockingCollection <Dictionary <string, object> >(128); Stopwatch = new Stopwatch(); firstCall = true; }
private ITransaction BeginTransactionWithoutLogging(AccessMode mode, TransactionConfig txConfig) { EnsureCanRunMoreStatements(); _connection = _connectionProvider.Acquire(mode); var tx = new Transaction(_connection, this, _logger, _bookmark); tx.BeginTransaction(txConfig ?? TransactionConfig.Empty); _transaction = tx; return(_transaction); }
public void BeginTransaction(IConnection connection, Bookmark bookmark, TransactionConfig txConfig) { AssertNullOrEmptyTransactionConfig(txConfig); IDictionary <string, object> parameters = bookmark?.AsBeginTransactionParameters(); connection.Enqueue(new RunMessage(Begin, parameters), null, PullAll); if (bookmark != null && !bookmark.IsEmpty()) { connection.Sync(); } }
public void ShouldNotEqualToNull() { var config2 = new TransactionConfig { Timeout = TimeSpan.FromMinutes(6), Metadata = new Dictionary <string, object> { { "Molly", "MostlyWhite" } } }; config2.Equals(null).Should().BeFalse(); }
private static InternalRxSession CreateSession(AccessMode mode, TransactionConfig txConfig, out Mock <IInternalAsyncSession> session, out Mock <IAsyncTransaction> txc) { txc = new Mock <IAsyncTransaction>(); txc.Setup(x => x.CommitAsync()).Returns(Task.CompletedTask); txc.Setup(x => x.RollbackAsync()).Returns(Task.CompletedTask); session = new Mock <IInternalAsyncSession>(); session.Setup(x => x.BeginTransactionAsync(mode, txConfig)).ReturnsAsync(txc.Object); return(new InternalRxSession(session.Object, new SingleRetryLogic())); }
public static void Config(XmlElement xmlElement, ref TransactionConfig txnConfig, bool compulsory) { Configuration.ConfigIsolation(xmlElement, "IsolationDegree", ref txnConfig.IsolationDegree, compulsory); Configuration.ConfigBool(xmlElement, "NoWait", ref txnConfig.NoWait, compulsory); Configuration.ConfigBool(xmlElement, "Snapshot", ref txnConfig.Snapshot, compulsory); Configuration.ConfigLogFlush(xmlElement, "SyncAction", ref txnConfig.SyncAction, compulsory); }
private async Task <IAsyncTransaction> BeginTransactionWithoutLoggingAsync(AccessMode mode, TransactionConfig txConfig) { await EnsureCanRunMoreStatementsAsync().ConfigureAwait(false); _connection = await _connectionProvider.AcquireAsync(mode).ConfigureAwait(false); var tx = new AsyncTransaction(_connection, this, _logger, _bookmark, _reactive); await tx.BeginTransactionAsync(txConfig ?? TransactionConfig.Empty).ConfigureAwait(false); _transaction = tx; return(_transaction); }
public async Task ShouldRunWithTxTimeoutAsync() { // Given using (var session = Server.Driver.Session()) { session.Run("CREATE (:Node)").Consume(); } var otherSession = Server.Driver.AsyncSession(); try { var otherTx = await otherSession.BeginTransactionAsync(); try { // lock dummy node but keep the transaction open await otherTx.RunAsync("MATCH (n:Node) SET n.prop = 1").ContinueWith(t => t.Result.ConsumeAsync()) .Unwrap(); // When // run a query in an auto-commit transaction with timeout and try to update the locked dummy node var txConfig = new TransactionConfig { Timeout = TimeSpan.FromMilliseconds(1) }; var session = Server.Driver.AsyncSession(); try { var error = await Record.ExceptionAsync(() => session.RunAsync("MATCH (n:Node) SET n.prop = 2", txConfig) .ContinueWith(c => c.Result.ConsumeAsync()).Unwrap()); // Then error.Should().BeOfType <TransientException>().Which.Message.Should().Contain("terminated"); } finally { await session.CloseAsync(); } } finally { await otherTx.CommitAsync(); } } finally { await otherSession.CloseAsync(); } }
public override async Task BeginTransactionAsync(IConnection connection, string database, Bookmark bookmark, TransactionConfig configBuilder) { await connection.EnqueueAsync( new BeginMessage(database, bookmark, configBuilder?.Timeout, configBuilder?.Metadata, connection.GetEnforcedAccessMode()), new V3.BeginResponseHandler()) .ConfigureAwait(false); if (bookmark != null && bookmark.Values.Any()) { await connection.SyncAsync().ConfigureAwait(false); } }
public void TestConfig() { testName = "TestConfig"; /* * Configure the fields/properties and see if * they are updated successfully. */ TransactionConfig txnConfig = new TransactionConfig(); XmlElement xmlElem = Configuration.TestSetUp( testFixtureName, testName); Config(xmlElem, ref txnConfig, true); Confirm(xmlElem, txnConfig, true); }
public virtual async Task BeginTransactionAsync(IConnection connection, string database, Bookmark bookmark, TransactionConfig configBuilder) { AssertNullDatabase(database); await connection.EnqueueAsync( new BeginMessage(bookmark, configBuilder, connection.GetEnforcedAccessMode()), new V3.BeginResponseHandler()) .ConfigureAwait(false); if (bookmark != null && bookmark.Values.Any()) { await connection.SyncAsync().ConfigureAwait(false); } }
public void CreateOrEditTransaction(TransactionConfig transaction) { var configFolder = GetConfigFolder(); var fileName = transaction.ContextName + ".json"; var configPath = Path.Combine(configFolder, fileName); var configString = File.ReadAllText(configPath); var config = JsonSerializer.Deserialize <OtmContextConfig>(configString); var index = config.Transactions != null?config.Transactions.Where(e => e.Id == transaction.Id).ToList() : null; if (index != null) { if (index.Count() > 0) { foreach (var de in config.Transactions) { if (de.Id == transaction.Id) { de.Name = transaction.Name; de.DataPointName = transaction.DataPointName; de.SourceDeviceName = transaction.SourceDeviceName; de.TargetDeviceName = transaction.TargetDeviceName; de.TriggerTagName = transaction.TriggerTagName; de.TriggerTime = transaction.TriggerTime; de.TriggerType = transaction.TriggerType; de.SourceBinds = transaction.SourceBinds; de.TargetBinds = transaction.TargetBinds; } } } else { transaction.Id = Guid.NewGuid(); config.Transactions.Add(transaction); } } else { config.Transactions = new List <TransactionConfig>(); transaction.Id = Guid.NewGuid(); config.Transactions.Add(transaction); } var configJson = JsonSerializer.Serialize <OtmContextConfig>(config); File.WriteAllText(configPath, configJson); }
public async Task ShouldThrowExceptionIfTxConfigIsGiven() { var mockConn = new Mock <IConnection>(); var txConfig = new TransactionConfig { Timeout = TimeSpan.FromMinutes(1), Metadata = new Dictionary <string, object> { { "key1", "value1" } } }; var error = await Xunit.Record.ExceptionAsync(() => BoltV1.BeginTransactionAsync(mockConn.Object, null, txConfig)); error.Should().BeOfType <ArgumentException>().Which.Message.Should().StartWith( "Driver is connected to the database that does not support transaction configuration."); }
public IActionResult Post([FromBody] TransactionConfig form) { var result = new ResultApi(); try { TransactionService.CreateOrEditTransaction(form); result.result = true; } catch (Exception e) { result.result = false; result.message = e.Message; } return(Ok(result)); }
public static void Register(HttpConfiguration config) { // Configuration et services API Web // Itinéraires de l'API Web config.MapHttpAttributeRoutes(); UtilisateurConfig.addRoutes(config); PrivilegeConfig.addRoutes(config); PrivilegeUtilisateurConfig.addRoutes(config); CompteConfig.addRoutes(config); TransactionConfig.addRoutes(config); TransactionPeriodiqueConfig.addRoutes(config); TransfertConfig.addRoutes(config); CategorieConfig.addRoutes(config); PorteFeuilleConfig.addRoutes(config); }
public async Task ShouldRunWithTxConfigAsync() { // Given var txConfig = new TransactionConfig { Metadata = new Dictionary <string, object> { { "name", "Molly" } } }; // When using (var session = Server.Driver.Session()) { var result = await session.RunAsync("CALL dbms.listTransactions()", txConfig); // Then var value = (await result.SingleAsync())["metaData"].ValueAs <IDictionary <string, object> >(); value.Should().HaveCount(1).And.Contain(new KeyValuePair <string, object>("name", "Molly")); } }
public void UpdateTxn() { int int32Value; DatabaseEntry data; // Get a new transaction for updating the db. TransactionConfig txnConfig = new TransactionConfig(); txnConfig.IsolationDegree = Isolation.DEGREE_THREE; updateTxn = paramEnv.BeginTransaction(txnConfig); // Continually putting record to db. BTreeCursor cursor = paramDB.Cursor(updateTxn); // Move the cursor to the first record. Assert.IsTrue(cursor.MoveFirst()); int i = 0; try { do { int32Value = BitConverter.ToInt32( cursor.Current.Value.Data, 0); data = new DatabaseEntry( BitConverter.GetBytes(int32Value - 1)); cursor.Overwrite(data); } while (i <= 1000 && cursor.MoveNext()); } catch (DeadlockException) { } finally { cursor.Close(); } }
private void RunWithTxConfig(bool read) { // Given var txConfig = new TransactionConfig { Metadata = new Dictionary <string, object> { { "name", "Molly" } } }; // When using (var session = Server.Driver.Session()) { var result = read ? session.ReadTransaction(tx => tx.Run("CALL dbms.listTransactions()"), txConfig) : session.WriteTransaction(tx => tx.Run("CALL dbms.listTransactions()"), txConfig); // Then var value = result.Single()["metaData"].ValueAs <IDictionary <string, object> >(); value.Should().HaveCount(1).And.Contain(new KeyValuePair <string, object>("name", "Molly")); } }
internal IObservable <T> RunTransaction <T>(AccessMode mode, Func <IRxTransaction, IObservable <T> > work, TransactionConfig txConfig) { return(_retryLogic.Retry( BeginTransaction(mode, txConfig) .SelectMany(txc => Observable.Defer(() => { try { return work(txc); } catch (Exception exc) { return Observable.Throw <T>(exc); } }).CatchAndThrow(exc => txc.Rollback <T>()).Concat(txc.Commit <T>())) )); }
internal T RunTransaction <T>(AccessMode mode, Func <ITransaction, T> work, TransactionConfig txConfig) { return(_retryLogic.Retry(() => { using (var txc = BeginTransaction(mode, txConfig)) { try { var result = work(txc); txc.Success(); return result; } catch { txc.Failure(); throw; } } })); }
public void ShouldRunWithTxConfig() { // Given var txConfig = new TransactionConfig { Metadata = new Dictionary <string, object> { { "name", "Molly" } } }; // When using (var session = Server.Driver.Session()) { var result = session.Run("CALL dbms.listTransactions()", txConfig); // Then var value = result.Single()["metaData"].ValueAs <IDictionary <string, object> >(); value.Should().HaveCount(1).And.Contain(new KeyValuePair <string, object>("name", "Molly")); result.Summary.ToString().Should().Contain("ResultAvailableAfter"); result.Summary.ToString().Should().Contain("ResultConsumedAfter"); } }
private T RunTransaction <T>(AccessMode mode, Func <ITransaction, T> work, TransactionConfig txConfig) { return(TryExecute(_logger, () => _retryLogic.Retry(() => { using (var tx = BeginTransactionWithoutLogging(mode, txConfig)) { try { var result = work(tx); tx.Success(); return result; } catch { tx.Failure(); throw; } } }))); }
public void TestNestedTXN() { DatabaseEntry key, data; DatabaseEnvironment master = SetUpEnv("./master", 100, 8000, true); BTreeDatabase db = Open(master, true); TransactionConfig txnconfig = new TransactionConfig(); Transaction txn = master.BeginTransaction(); Transaction txn1 = master.BeginTransaction(txnconfig, txn); key = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes("Key")); data = new DatabaseEntry( ASCIIEncoding.ASCII.GetBytes("Data")); db.Put(key, data, txn1); txn1.Commit(); txn.Commit(); byte[] token; Assert.Throws <ArgumentException>(delegate { token = txn1.CommitToken; }); master.Close(); }
private Task <T> RunTransactionAsync <T>(AccessMode mode, Func <IAsyncTransaction, Task <T> > work, TransactionConfig txConfig) { return(TryExecuteAsync(_logger, async() => await _retryLogic.RetryAsync(async() => { var tx = await BeginTransactionWithoutLoggingAsync(mode, txConfig).ConfigureAwait(false); { try { var result = await work(tx).ConfigureAwait(false); await tx.CommitAsync().ConfigureAwait(false); return result; } catch { await tx.RollbackAsync().ConfigureAwait(false); throw; } } }).ConfigureAwait(false))); }