public void ShouldUpdate()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });

            system.KeyValueStore.ServerCountSamples(new ServerCountSamples
            {
                Samples = new[] { new ServerCountSample {
                                      Count = 1
                                  } }
            });
            system.KeyValueStore.ServerCountSamples(new ServerCountSamples
            {
                Samples = new[] { new ServerCountSample {
                                      Count = 2
                                  } }
            });

            var sample = system.KeyValueStore.ServerCountSamples().Samples.Single();

            Assert.AreEqual(2, sample.Count);
        }
Example #2
0
    private void enqueuedJobOnWorker(string storageConnstring)
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions
        {
            ConnectionString     = ConnectionString,
            UpdateConfigurations = new[]
            {
                new UpdateStorageConfiguration
                {
                    ConnectionString = storageConnstring,
                    Name             = DefaultConfigurationName.Name()
                }
            }
        });
        system.UseRealHangfire();
        FakeJobService.Reset();

        var publisher = system.QueryPublishers().Single();

        publisher.BackgroundJobClient.Enqueue(() => FakeJobService.RunTheJob());
        WorkerEmulation.SingleIteration(publisher.JobStorage);

        FakeJobService.WasRun.Should().Be.True();
    }
        public void ShouldRead()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            var storage = system.ConfigurationStorage;

            storage.WriteConfiguration(new StoredConfiguration
            {
                ConnectionString = "connectionString",
                SchemaName       = "schemaName",
                GoalWorkerCount  = 3,
                Active           = true
            });

            var result = storage.ReadConfigurations().Single();

            Assert.AreEqual(1, result.Id);
            Assert.AreEqual("connectionString", result.ConnectionString);
            Assert.AreEqual("schemaName", result.SchemaName);
            Assert.AreEqual(3, result.GoalWorkerCount);
            Assert.AreEqual(true, result.Active);
        }
    private void runJobs(string storageConnectionString)
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions
        {
            ConnectionString     = ConnectionString,
            UpdateConfigurations = new[]
            {
                new UpdateStorageConfiguration
                {
                    ConnectionString = storageConnectionString,
                    Name             = DefaultConfigurationName.Name()
                }
            }
        })
        .UseServerOptions(new BackgroundJobServerOptions
        {
            Queues = _queues
        });
        system.UseRealHangfire();
        FakeJobService.Reset();

        var publisher = system.QueryPublishers().Single();

        publisher.BackgroundJobClient.Enqueue(() => FakeJobService.DefaultQueueJob());
        publisher.BackgroundJobClient.Enqueue(() => FakeJobService.AQueueJob());
        WorkerEmulation.SingleIteration(publisher.JobStorage, _queues);
        WorkerEmulation.SingleIteration(publisher.JobStorage, _queues);
    }
        public void ShouldUpdate()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            var storage = system.ConfigurationStorage;

            storage.WriteConfiguration(new StoredConfiguration());

            var existing = storage.ReadConfigurations().Single();

            existing.ConnectionString = "connection";
            existing.SchemaName       = "schema";
            existing.GoalWorkerCount  = 23;
            existing.Active           = true;
            storage.WriteConfiguration(existing);

            var configuration = storage.ReadConfigurations().Single();

            Assert.AreEqual("connection", configuration.ConnectionString);
            Assert.AreEqual("schema", configuration.SchemaName);
            Assert.AreEqual(23, configuration.GoalWorkerCount);
            Assert.AreEqual(true, configuration.Active);
        }
Example #6
0
    public void ShouldNotInsertMultiple()
    {
        Parallel.ForEach(Enumerable.Range(1, 10), _ =>
        {
            var system = new SystemUnderInfraTest();
            system.UseOptions(new ConfigurationOptions
            {
                ConnectionString     = ConnectionString,
                UpdateConfigurations = new[]
                {
                    new UpdateStorageConfiguration
                    {
                        ConnectionString = ConnectionString,
                        Name             = DefaultConfigurationName.Name()
                    }
                }
            });
            system.StartWorkerServers();
        });

        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions {
            ConnectionString = ConnectionString
        });
        var storage = system.ConfigurationStorage;

        storage.ReadConfigurations()
        .Should().Have.Count.EqualTo(1);
    }
Example #7
0
    public void ShouldThrowIfPrefixAndServerAlreadyExists()
    {
        var system = new SystemUnderInfraTest();

        system.RedisConfigurationVerifier.VerifyConfiguration("localhost", "{prefixet}:");         // bit of a hack - simulates an earlier entry

        Assert.Throws <ArgumentException>(() => { system.RedisConfigurationVerifier.VerifyConfiguration("localhost", "{prefixet}:"); });
    }
Example #8
0
    public void ShouldNotThrowIfPrefixAndServerAlreadyNotExists()
    {
        var system = new SystemUnderInfraTest();

        system.RedisConfigurationVerifier.VerifyConfiguration("localhost", "{another}:");         // bit of a hack - simulates an earlier entry

        Assert.DoesNotThrow(() => { system.RedisConfigurationVerifier.VerifyConfiguration("localhost", "{prefixet}:"); });
    }
Example #9
0
    public void ShouldThrowIfPrefixIsNotCorrect(string prefix)
    {
        var system = new SystemUnderInfraTest();

        Assert.Throws <ArgumentException>(() =>
        {
            system.RedisConfigurationVerifier.VerifyConfiguration("localhost", prefix);
        });
    }
Example #10
0
    public void ShouldNotThrowIfPresentServer()
    {
        var system = new SystemUnderInfraTest();

        Assert.DoesNotThrow(() =>
        {
            system.RedisConfigurationVerifier.VerifyConfiguration("localhost,ConnectTimeout=100", "{hangfire}:");
        });
    }
Example #11
0
    public void ShouldThrowIfUnknownServer()
    {
        var system = new SystemUnderInfraTest();

        Assert.Throws <RedisConnectionException>(() =>
        {
            system.RedisConfigurationVerifier.VerifyConfiguration("UnknownServer,ConnectTimeout=100", "{hangfire}:");
        });
    }
        public void ShouldReadEmptyConfiguration()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            var storage = system.ConfigurationStorage;

            Assert.IsEmpty(storage.ReadConfigurations());
        }
        public void ShouldReadEmpty()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });

            var sample = system.KeyValueStore.ServerCountSamples();

            Assert.IsEmpty(sample.Samples);
        }
    public void ShouldWriteMaxWorkersPerServer()
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions {
            ConnectionString = ConnectionString
        });

        system.ConfigurationStorage.WriteConfiguration(new StoredConfiguration {
            MaxWorkersPerServer = 5
        });

        Assert.AreEqual(5, system.ConfigurationStorage.ReadConfigurations().Single().MaxWorkersPerServer);
    }
Example #15
0
    public void ShouldWriteGoalWorkerCount()
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions {
            ConnectionString = ConnectionString
        });
        var storage = system.ConfigurationStorage;

        storage.WriteConfiguration(new StoredConfiguration {
            GoalWorkerCount = 1
        });

        Assert.AreEqual(1, storage.ReadConfigurations().Single().GoalWorkerCount);
    }
Example #16
0
        public void ShouldReadValueMatchingKey()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            system.KeyValueStore.Write("firstKey", "1");
            system.KeyValueStore.Write("secondKey", "2");

            var value1 = system.KeyValueStore.Read("firstKey");
            var value2 = system.KeyValueStore.Read("secondKey");

            Assert.AreEqual("1", value1);
            Assert.AreEqual("2", value2);
        }
    public void ShouldStartServerWithWorkers()
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions
        {
            ConnectionString     = ConnectionString,
            UpdateConfigurations = new[]
            {
                new UpdateStorageConfiguration
                {
                    ConnectionString = ConnectionString,
                    Name             = DefaultConfigurationName.Name()
                }
            }
        });
        system.StartWorkerServers();
    }
        public void ShouldWriteName()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            var storage = system.ConfigurationStorage;

            storage.WriteConfiguration(new StoredConfiguration
            {
                Name = "name",
            });

            var configuration = storage.ReadConfigurations().Single();

            Assert.AreEqual("name", configuration.Name);
        }
        public void ShouldWrite()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });

            system.KeyValueStore.ServerCountSamples(new ServerCountSamples
            {
                Samples = new[] { new ServerCountSample {
                                      Timestamp = "2020-12-02 12:00".Utc(), Count = 1
                                  } }
            });

            var sample = system.KeyValueStore.ServerCountSamples().Samples.Single();

            Assert.AreEqual("2020-12-02 12:00".Utc(), sample.Timestamp);
            Assert.AreEqual(1, sample.Count);
        }
Example #20
0
    public void ShouldWriteNullGoalWorkerCount()
    {
        var system = new SystemUnderInfraTest();

        system.UseOptions(new ConfigurationOptions {
            ConnectionString = ConnectionString
        });
        var storage = system.ConfigurationStorage;

        storage.WriteConfiguration(new StoredConfiguration {
            GoalWorkerCount = 1
        });

        var configuration = storage.ReadConfigurations().Single();

        configuration.GoalWorkerCount = null;
        storage.WriteConfiguration(configuration);

        Assert.Null(storage.ReadConfigurations().Single().GoalWorkerCount);
    }
        public void ShouldWrite()
        {
            var system = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            var storage = system.ConfigurationStorage;

            storage.WriteConfiguration(new StoredConfiguration
            {
                ConnectionString = "connection string",
                SchemaName       = "schema name",
                Active           = false
            });

            var configuration = storage.ReadConfigurations().Single();

            Assert.AreEqual("connection string", configuration.ConnectionString);
            Assert.AreEqual("schema name", configuration.SchemaName);
            Assert.AreEqual(false, configuration.Active);
        }
Example #22
0
        public void ShouldReturnCorrectNumberOfWorkServersConcurrently()
        {
            const int storageCount = 500;
            var       system       = new SystemUnderInfraTest();

            system.UseOptions(new ConfigurationOptions {
                ConnectionString = ConnectionString
            });
            Enumerable.Range(1, storageCount)
            .ForEach(_ => { system.ConfigurationStorage.WriteConfiguration(new StoredConfiguration {
                    ConnectionString = ConnectionString
                }); });

            var hangfireConfiguration = system.StartWorkerServers();
            var run = new ConcurrencyRunner();

            run.InParallel(() =>
            {
                var actual = hangfireConfiguration.QueryAllWorkerServers().Count();
                Assert.AreEqual(storageCount, actual);
            })
            .Times(100)
            .Wait();
        }