//====== ctors public EFAppContext(FileOrganizerEntities entities, IRequestorAccessor requestor, ITimestampGenerator timestamp) { Entities = Guard.NotNull(entities, nameof(entities)); Requestor = Guard.NotNull(requestor, nameof(requestor)); this.timestamp = Guard.NotNull(timestamp, nameof(timestamp)); }
private static void TimestampGeneratorLogDriftingTest( ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler, int logIntervalMs) { var timestamp = DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond; TestHelper.ParallelInvoke( () => { generator.Next(); }, 1000000); var elapsed = (DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond) - timestamp; if (elapsed > 3000) { Assert.Ignore("Generated numbers too slowly for this test to work."); } else { var count = elapsed / logIntervalMs; Assert.That(Interlocked.Read(ref loggerHandler.WarningCount), Is.InRange(count + 1, count + 2)); } }
private static void TimestampGeneratorLogDriftingTest(ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler) { // A little less than 3 seconds // It should generate a warning initially and then next 2 after 1 second each var maxElapsed = TimeSpan.FromSeconds(2.8); var counter = 0; TestHelper.ParallelInvoke(() => { var stopWatch = new Stopwatch(); stopWatch.Start(); while (stopWatch.Elapsed < maxElapsed) { for (var i = 0; i < 10000; i++) { generator.Next(); Interlocked.Increment(ref counter); } } }, 2); if (Volatile.Read(ref counter) < 5000000) { // if during this time, we weren't able to generate a lot of values, don't mind Assert.Ignore("It was not able to generate 5M values"); } Assert.AreEqual(3, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); }
private static void TimestampGeneratorLogAfterCooldownTest(ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler) { // It should generate a warning initially and then 1 more var maxElapsed = TimeSpan.FromSeconds(1.8); var counter = 0; Action action = () => { var stopWatch = new Stopwatch(); stopWatch.Start(); // ReSharper disable once AccessToModifiedClosure while (stopWatch.Elapsed < maxElapsed) { for (var i = 0; i < 5000; i++) { generator.Next(); Interlocked.Increment(ref counter); } } }; TestHelper.ParallelInvoke(action, 2); if (Volatile.Read(ref counter) < 5000000) { // if during this time, we weren't able to generate a lot of values, don't mind Assert.Ignore("It was not able to generate 5M values"); } Assert.AreEqual(2, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); // Cooldown: make current time > last generated value Thread.Sleep(3000); // It should generate a warning initially maxElapsed = TimeSpan.FromSeconds(0.8); TestHelper.ParallelInvoke(action, 2); Assert.AreEqual(1, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); }
private static void TimestampGeneratorLogAfterCooldownTest(ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler) { // It should generate a warning initially and then 1 more var maxElapsed = TimeSpan.FromSeconds(1.8); Action action = () => { var stopWatch = new Stopwatch(); stopWatch.Start(); // ReSharper disable once AccessToModifiedClosure while (stopWatch.Elapsed < maxElapsed) { for (var i = 0; i < 5000; i++) { generator.Next(); } } }; TestHelper.ParallelInvoke(action, 2); Assert.AreEqual(2, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); // Cooldown: make current time > last generated value Thread.Sleep(3000); // It should generate a warning initially maxElapsed = TimeSpan.FromSeconds(0.8); TestHelper.ParallelInvoke(action, 2); Assert.AreEqual(1, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); }
/// <summary> /// Initializes a new instance of the <see cref="S3Util"/> class using the /// library's private bucket which will be created if it doesn't exist and a 7 day lifecycle rule /// applied to prevent build-up of temporary objects. /// </summary> /// <param name="clientFactory">The AWS client factory.</param> /// <param name="context">The context.</param> public S3Util(IPSAwsClientFactory clientFactory, IPSCloudFormationContext context) { this.logger = context.Logger; this.clientFactory = clientFactory ?? throw new ArgumentNullException(nameof(clientFactory)); this.timestampGenerator = context.TimestampGenerator ?? new TimestampGenerator(); this.s3 = this.clientFactory.CreateS3Client(); this.GeneratePrivateBucketName(context); }
/// <summary> /// Gets the timestamp of the request or null if not defined. /// </summary> private static long?GetRequestTimestamp(BatchStatement statement, ITimestampGenerator timestampGenerator) { if (statement.Timestamp != null) { return(TypeSerializer.SinceUnixEpoch(statement.Timestamp.Value).Ticks / 10); } var timestamp = timestampGenerator.Next(); return(timestamp != long.MinValue ? (long?)timestamp : null); }
internal Policies(ILoadBalancingPolicy loadBalancingPolicy, IReconnectionPolicy reconnectionPolicy, IRetryPolicy retryPolicy, ISpeculativeExecutionPolicy speculativeExecutionPolicy, ITimestampGenerator timestampGenerator) { _loadBalancingPolicy = loadBalancingPolicy ?? DefaultLoadBalancingPolicy; _reconnectionPolicy = reconnectionPolicy ?? DefaultReconnectionPolicy; _retryPolicy = retryPolicy ?? DefaultRetryPolicy; _speculativeExecutionPolicy = speculativeExecutionPolicy ?? DefaultSpeculativeExecutionPolicy; _timestampGenerator = timestampGenerator ?? DefaultTimestampGenerator; }
private Policies( ILoadBalancingPolicy loadBalancingPolicy, IReconnectionPolicy reconnectionPolicy, IRetryPolicy retryPolicy, ISpeculativeExecutionPolicy speculativeExecutionPolicy, ITimestampGenerator timestampGenerator, IExtendedRetryPolicy extendedRetryPolicy) { _loadBalancingPolicy = loadBalancingPolicy ?? throw new ArgumentNullException(nameof(loadBalancingPolicy)); _reconnectionPolicy = reconnectionPolicy ?? throw new ArgumentNullException(nameof(reconnectionPolicy)); _retryPolicy = retryPolicy ?? throw new ArgumentNullException(nameof(retryPolicy)); _speculativeExecutionPolicy = speculativeExecutionPolicy ?? throw new ArgumentNullException(nameof(speculativeExecutionPolicy)); _timestampGenerator = timestampGenerator ?? throw new ArgumentNullException(nameof(timestampGenerator)); _extendedRetryPolicy = extendedRetryPolicy ?? throw new ArgumentNullException(nameof(extendedRetryPolicy)); }
private static void TimestampGeneratorMonitonicityTest(ITimestampGenerator generator) { // Use a set to determine the amount of different values const int iterations = 5000; const int threads = 8; var values = new ConcurrentDictionary <long, bool>(); TestHelper.ParallelInvoke(() => { var lastValue = 0L; for (var i = 0; i < iterations; i++) { var value = generator.Next(); Assert.Greater(value, lastValue); lastValue = value; values.TryAdd(value, true); } }, threads); Assert.AreEqual(iterations * threads, values.Count); }
private static void TimestampGeneratorLogDriftingTest(ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler) { // A little less than 3 seconds // It should generate a warning initially and then next 2 after 1 second each var maxElapsed = TimeSpan.FromSeconds(2.8); TestHelper.ParallelInvoke(() => { var stopWatch = new Stopwatch(); stopWatch.Start(); while (stopWatch.Elapsed < maxElapsed) { for (var i = 0; i < 10000; i++) { generator.Next(); } } }, 2); Assert.AreEqual(3, loggerHandler.DequeueAllMessages().Count(i => i.Item1 == "warning")); }
private static void TimestampGeneratorLogAfterCooldownTest(ITimestampGenerator generator, TestHelper.TestLoggerHandler loggerHandler) { // It should generate a warning initially and then 1 more var counter = 0; void Action(TimeSpan maxElapsed) { var stopWatch = new Stopwatch(); stopWatch.Start(); while (stopWatch.Elapsed < maxElapsed) { for (var i = 0; i < 5000; i++) { generator.Next(); // ReSharper disable once AccessToModifiedClosure Interlocked.Increment(ref counter); } } } TestHelper.ParallelInvoke(() => Action(TimeSpan.FromSeconds(1.8)), 2); if (Volatile.Read(ref counter) < 5000000) { // if during this time, we weren't able to generate a lot of values, don't mind Assert.Ignore("It was not able to generate 5M values"); } Assert.That(Interlocked.Read(ref loggerHandler.WarningCount), Is.GreaterThanOrEqualTo(2)); // Cooldown: make current time > last generated value Thread.Sleep(4000); // It should generate a warning initially TestHelper.ParallelInvoke(() => Action(TimeSpan.FromSeconds(0.8)), 2); Assert.That(Interlocked.Read(ref loggerHandler.WarningCount), Is.GreaterThanOrEqualTo(1)); }
/// <summary> /// Configures the generator that will produce the client-side timestamp sent with each query. /// <para> /// This feature is only available with protocol version 3 or above of the native protocol. /// With earlier versions, timestamps are always generated server-side, and setting a generator /// through this method will have no effect. /// </para> /// <para> /// If no generator is set through this method, the driver will default to client-side timestamps /// by using <see cref="AtomicMonotonicTimestampGenerator"/>. /// </para> /// </summary> /// <param name="generator">The generator to use.</param> /// <returns>This builder instance</returns> public Builder WithTimestampGenerator(ITimestampGenerator generator) { _timestampGenerator = generator; return(this); }
public InfluxDBClient(IRequestProcessor requestProcessor, ITimestampGenerator timestampGenerator, string database, Consistency defaultConsistency) : this(database, defaultConsistency) { RequestProcessor = requestProcessor; TimestampGenerator = timestampGenerator; }
public InfluxDBClient(string host, int port, bool useHttps, string username, string password, string database, ITimestampGenerator timestampGenerator, Consistency defaultConsistency) : this(database, defaultConsistency) { RequestProcessor = new HttpClientRequestProcessor(new RequestProcessorSettings(host, port, useHttps, username, password)); TimestampGenerator = timestampGenerator; }
/// <summary> /// Gets the timestamp of the request or null if not defined. /// </summary> /// <exception cref="NotSupportedException" /> private static long?GetRequestTimestamp(ProtocolVersion protocolVersion, BatchStatement statement, ITimestampGenerator timestampGenerator) { if (!protocolVersion.SupportsTimestamp()) { if (statement.Timestamp != null) { throw new NotSupportedException( "Timestamp for BATCH request is supported in Cassandra 2.1 or above."); } return(null); } if (statement.Timestamp != null) { return(TypeSerializer.SinceUnixEpoch(statement.Timestamp.Value).Ticks / 10); } var timestamp = timestampGenerator.Next(); return(timestamp != long.MinValue ? (long?)timestamp : null); }