public void CountersAggregatorExecutesProperly()
        {
            var storage = ConnectionUtils.CreateStorage();

            using (var connection = (LiteDbConnection)storage.GetConnection())
            {
                // Arrange
                connection.Database.StateDataCounter.Insert(new Counter
                {
                    Key      = "key",
                    Value    = 1L,
                    ExpireAt = DateTime.Now.AddHours(1)
                });

                var aggregator = new CountersAggregator(storage, TimeSpan.Zero);
                var cts        = new CancellationTokenSource();
                cts.Cancel();

                // Act
                aggregator.Execute(cts.Token);

                // Assert
                Assert.Equal(1, connection.Database.StateDataAggregatedCounter.Count());
            }
        }
Ejemplo n.º 2
0
        public void CountersAggregatorExecutesProperly()
        {
            var storage = new MongoStorage(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName());
            using (var connection = (MongoConnection)storage.GetConnection())
            {
                using (var database = ConnectionUtils.CreateConnection())
                {
                    // Arrange
                    database.Counter.InsertOne(new CounterDto
                    {
                        Key = "key",
                        Value = 1,
                        ExpireAt = DateTime.UtcNow.AddHours(1)
                    });

                    var aggregator = new CountersAggregator(storage, TimeSpan.Zero);
                    var cts = new CancellationTokenSource();
                    cts.Cancel();

                    // Act
                    aggregator.Execute(cts.Token);

                    // Assert
                    Assert.Equal(1, database.AggregatedCounter.Count(new BsonDocument()));
                }
            }
        }
        public void CountersAggregatorExecutesProperly()
        {
            var storage = new MongoStorage(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName());

            using (var connection = (MongoConnection)storage.GetConnection())
            {
                using (var database = ConnectionUtils.CreateConnection())
                {
                    // Arrange
                    AsyncHelper.RunSync(() => database.Counter.InsertOneAsync(new CounterDto
                    {
                        Key      = "key",
                        Value    = 1,
                        ExpireAt = DateTime.UtcNow.AddHours(1)
                    }));

                    var aggregator = new CountersAggregator(storage, TimeSpan.Zero);
                    var cts        = new CancellationTokenSource();
                    cts.Cancel();

                    // Act
                    aggregator.Execute(cts.Token);

                    // Assert
                    Assert.Equal(1, AsyncHelper.RunSync(() => database.AggregatedCounter.CountAsync(new BsonDocument())));
                }
            }
        }
        public void CountersAggregatorExecutesProperly()
        {
            var storage = ConnectionUtils.CreateStorage();

            using (var connection = (HangfireSQLiteConnection)storage.GetConnection())
            {
                // Arrange
                connection.DbContext.Database.Insert(new Counter
                {
                    Id       = Guid.NewGuid().ToString(),
                    Key      = "key",
                    Value    = 1L,
                    ExpireAt = DateTime.UtcNow.AddHours(1)
                });

                var aggregator = new CountersAggregator(storage, TimeSpan.Zero);
                var cts        = new CancellationTokenSource();
                cts.Cancel();

                // Act
                aggregator.Execute(cts.Token);

                // Assert
                Assert.Equal(1, connection.DbContext.AggregatedCounterRepository.Count());
            }
        }
        public void CountersAggregatorExecutesProperly()
        {
            var storage = ConnectionUtils.CreateStorage();

            using (var connection = (MongoConnection)storage.GetConnection())
            {
                // Arrange
                connection.Database.StateData.InsertOne(new CounterDto
                {
                    Key      = "key",
                    Value    = 1L,
                    ExpireAt = DateTime.UtcNow.AddHours(1)
                });

                var aggregator = new CountersAggregator(storage, TimeSpan.Zero);

                // Act
                using (var cts = new CancellationTokenSource())
                {
                    cts.Cancel();
                    aggregator.Execute(cts.Token);
                }

                // Assert
                Assert.Equal(1, connection.Database.StateData.OfType <AggregatedCounterDto>().Count(new BsonDocument()));
            }
        }
Ejemplo n.º 6
0
    public void Execute_DoWorkCorrectly()
    {
        UseContextSavingChanges(context =>
        {
            for (int i = 0; i < 10; i++)
            {
                context.Add(new HangfireCounter
                {
                    Key   = "counter1",
                    Value = 1
                });
            }

            for (int i = 0; i < 20; i++)
            {
                context.Add(new HangfireCounter
                {
                    Key   = "counter2",
                    Value = -1
                });
            }

            for (int i = 0; i < 5; i++)
            {
                context.Add(new HangfireCounter
                {
                    Key   = "counter3",
                    Value = 20
                });
            }

            context.Add(new HangfireCounter
            {
                Key   = "counter3",
                Value = -1
            });
        });

        var storage = new EFCoreStorage(OptionsAction, new EFCoreStorageOptions
        {
            CountersAggregationInterval = new TimeSpan(1),
        });
        var instance = new CountersAggregator(storage);
        var source   = new CancellationTokenSource();

        instance.Execute(source.Token);

        UseContext(context =>
        {
            var result = context.Set <HangfireCounter>().ToArray();

            Assert.Equal(3, result.Length);
            Assert.Equal(10, result.Single(x => x.Key == "counter1").Value);
            Assert.Equal(-20, result.Single(x => x.Key == "counter2").Value);
            Assert.Equal(99, result.Single(x => x.Key == "counter3").Value);
        });
    }
Ejemplo n.º 7
0
    public void Execute_Throws_WhenCancellationTokenRequested()
    {
        var storage = new EFCoreStorage(OptionsAction, new EFCoreStorageOptions
        {
            CountersAggregationInterval = new TimeSpan(1),
        });

        storage.RegisterDatabaseInitializer(context => context.Database.EnsureCreated());
        var instance = new CountersAggregator(storage);
        var source   = new CancellationTokenSource(0);

        Assert.Throws <OperationCanceledException>(
            () => instance.Execute(source.Token));
    }
Ejemplo n.º 8
0
        public void CountersAggregatorExecutesProperly()
        {
            const string createSql = @"insert into HANGFIRE_COUNTER (KEY, VALUE, ExpireAt) values ('key', 1, :expireAt)";

            _storage.UseConnection(connection =>
            {
                // Arrange
                connection.Execute(createSql, new { expireAt = DateTime.UtcNow.AddHours(1) });

                var cts = new CancellationTokenSource();
                cts.Cancel();

                // Act
                _sut.Execute(cts.Token);

                // Assert
                Assert.Equal(1, connection.Query <int>(@"select count(*) from HANGFIRE_AGGREGATEDCOUNTER").Single());
            });
        }
        public void CountersAggregatorExecutesProperly()
        {
            _storage.UseStatelessSession(connection =>
            {
                //Arrange
                connection.Insert(new _Counter {
                    Key = "key", Value = 1, ExpireAt = _storage.UtcNow.AddHours(1)
                });


                var cts = new CancellationTokenSource();
                cts.Cancel();

                // Act
                _countersAggregator.Execute(cts.Token);

                // Assert
                Assert.Equal(1, connection.Query <_AggregatedCounter>().Count());
            });
        }