public void ShouldUseChildRetryPolicy_OnWriteTimeout() { var tableName = TestUtils.GetUniqueTableName(); var cql = $"INSERT INTO {tableName}(k, i) VALUES (0, 0)"; using (var simulacronCluster = SimulacronCluster.CreateNew(1)) using (var cluster = ClusterBuilder().AddContactPoint(simulacronCluster.InitialContactPoint) .Build()) { var session = cluster.Connect(); simulacronCluster.PrimeFluent(b => b.WhenQuery(cql).ThenWriteTimeout("write_timeout", 5, 1, 2, "SIMPLE")); var testPolicy = new TestRetryPolicy(); var policy = new IdempotenceAwareRetryPolicy(testPolicy); Assert.Throws <WriteTimeoutException>(() => session.Execute( new SimpleStatement(cql) .SetIdempotence(true) .SetConsistencyLevel(ConsistencyLevel.All) .SetRetryPolicy(policy))); Assert.AreEqual(1L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); Interlocked.Exchange(ref testPolicy.WriteTimeoutCounter, 0); Assert.Throws <WriteTimeoutException>(() => session.Execute( new SimpleStatement(cql) .SetIdempotence(false) .SetConsistencyLevel(ConsistencyLevel.All) .SetRetryPolicy(policy))); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); } }
public void IdempotenceAwareRetryPolicy_Should_Rethrow_OnWriteTimeout_With_Non_Idempotent_Statements() { var testPolicy = new TestRetryPolicy(); var policy = new IdempotenceAwareRetryPolicy(testPolicy); var decision = policy.OnWriteTimeout(new SimpleStatement("Q").SetIdempotence(false), ConsistencyLevel.All, "BATCH", 0, 0, 1); Assert.AreEqual(decision.DecisionType, RetryDecision.RetryDecisionType.Rethrow); Assert.AreEqual(0, testPolicy.ReadTimeoutCounter); Assert.AreEqual(0, testPolicy.WriteTimeoutCounter); Assert.AreEqual(0, testPolicy.UnavailableCounter); }
public void IdempotenceAwareRetryPolicy_Should_Use_ChildPolicy_OnUnavailable() { var testPolicy = new TestRetryPolicy(); var policy = new IdempotenceAwareRetryPolicy(testPolicy); var decision = policy.OnUnavailable(new SimpleStatement("Q"), ConsistencyLevel.All, 0, 0, 1); Assert.AreEqual(decision.DecisionType, RetryDecision.RetryDecisionType.Ignore); Assert.AreEqual(0, testPolicy.ReadTimeoutCounter); Assert.AreEqual(0, testPolicy.WriteTimeoutCounter); Assert.AreEqual(1, testPolicy.UnavailableCounter); }
public async Task TestFailoverWithRetryPolicyDoesNotRetryTxCommit() { var testRetryPolicy = new TestRetryPolicy(); var cfg = new IgniteClientConfiguration { RetryPolicy = testRetryPolicy }; using var server = new FakeServer(reqId => reqId % 2 == 0); using var client = await server.ConnectClientAsync(cfg); var tx = await client.Transactions.BeginAsync(); Assert.ThrowsAsync <IgniteClientException>(async() => await tx.CommitAsync()); Assert.IsEmpty(testRetryPolicy.Invocations); }
public TestRetryContext(TestRetryPolicy policy, TContext context, Exception exception, int retryCount, CancellationToken cancellationToken) : base(context, exception, retryCount, cancellationToken) { _policy = policy; }
public void ShouldUseChildRetryPolicy_OnWriteTimeout() { const string keyspace = "idempotenceAwarepolicytestks"; var options = new TestClusterOptions { CassandraYaml = new[] { "phi_convict_threshold: 16" } }; var testCluster = TestClusterManager.CreateNew(2, options); using (var cluster = Cluster.Builder().AddContactPoint(testCluster.InitialContactPoint) .WithQueryTimeout(60000) .WithSocketOptions(new SocketOptions().SetConnectTimeoutMillis(30000)) .Build()) { var session = cluster.Connect(); var tableName = TestUtils.GetUniqueTableName(); session.DeleteKeyspaceIfExists(keyspace); session.Execute(string.Format(TestUtils.CreateKeyspaceSimpleFormat, keyspace, 2), ConsistencyLevel.All); session.ChangeKeyspace(keyspace); session.Execute(new SimpleStatement(string.Format("CREATE TABLE {0} (k int PRIMARY KEY, i int)", tableName)).SetConsistencyLevel(ConsistencyLevel.All)); testCluster.PauseNode(2); var testPolicy = new TestRetryPolicy(); var policy = new IdempotenceAwareRetryPolicy(testPolicy); try { session.Execute(new SimpleStatement(string.Format("INSERT INTO {0}(k, i) VALUES (0, 0)", tableName)) .SetIdempotence(true) .SetConsistencyLevel(ConsistencyLevel.All) .SetRetryPolicy(policy)); } catch (WriteTimeoutException) { //throws a WriteTimeoutException, as its set as an idempotent query, it will call the childPolicy Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.ReadTimeoutCounter)); Assert.AreEqual(1L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.UnavailableCounter)); } catch (UnavailableException) { Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.ReadTimeoutCounter)); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); Assert.AreEqual(1L, Interlocked.Read(ref testPolicy.UnavailableCounter)); } catch (Exception e) { Trace.TraceWarning(e.Message); } Interlocked.Exchange(ref testPolicy.UnavailableCounter, 0); Interlocked.Exchange(ref testPolicy.WriteTimeoutCounter, 0); Interlocked.Exchange(ref testPolicy.ReadTimeoutCounter, 0); //testing with unidempotent query try { session.Execute(new SimpleStatement(string.Format("INSERT INTO {0}(k, i) VALUES (0, 0)", tableName)) .SetIdempotence(false) .SetConsistencyLevel(ConsistencyLevel.All) .SetRetryPolicy(policy)); } catch (WriteTimeoutException) { //throws a WriteTimeoutException, as its set as NOT an idempotent query, it will not call the childPolicy Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.ReadTimeoutCounter)); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.UnavailableCounter)); } catch (UnavailableException) { Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.ReadTimeoutCounter)); Assert.AreEqual(0L, Interlocked.Read(ref testPolicy.WriteTimeoutCounter)); Assert.AreEqual(1L, Interlocked.Read(ref testPolicy.UnavailableCounter)); } catch (Exception e) { Trace.TraceWarning(e.Message); } } testCluster.Remove(); }