public void Migrate_DropNoBackup_Success() { using (var dbContext = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests")) { // ARRANGE dbContext.Client.DropDatabase(dbContext.Database.DatabaseNamespace.DatabaseName); SeedCollectionFromZipArchive(dbContext, Path.Combine("Migration", "Hangfire-Mongo-Schema-006.zip")); var storageOptions = new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Drop, BackupStrategy = MongoBackupStrategy.None } }; var migrationManager = new MongoMigrationManager(storageOptions, dbContext); // ACT migrationManager.Migrate(); // ASSERT AssertDataIntegrity(dbContext, assertCollectionHasItems: false); } }
private void FullMigration(string seedFile) { using (var connection = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests")) { // ARRANGE connection.Client.DropDatabase(connection.Database.DatabaseNamespace.DatabaseName); if (seedFile != null) { SeedCollectionFromZipArchive(connection, Path.Combine("Migration", seedFile)); } var storageOptions = new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Migrate, BackupStrategy = MongoBackupStrategy.None } }; var migrationManager = new MongoMigrationManager(storageOptions); // ACT migrationManager.Migrate(connection); // ASSERT } }
public MySqlMonitoringApiTests() { _connection = new MySqlConnection(ConnectionUtils.GetConnectionString()); _connection.Open(); var persistentJobQueueMonitoringApiMock = new Mock <IPersistentJobQueueMonitoringApi>(); persistentJobQueueMonitoringApiMock.Setup(m => m.GetQueues()).Returns(new[] { "default" }); var defaultProviderMock = new Mock <IPersistentJobQueueProvider>(); defaultProviderMock.Setup(m => m.GetJobQueueMonitoringApi()) .Returns(persistentJobQueueMonitoringApiMock.Object); var storageOptions = new MySqlStorageOptions { DashboardJobListLimit = _jobListLimit }; var mySqlStorageMock = new Mock <MySqlStorage>(_connection, storageOptions); mySqlStorageMock .Setup(m => m.QueueProviders) .Returns(new PersistentJobQueueProviderCollection(defaultProviderMock.Object)); _storage = mySqlStorageMock.Object; _sut = new MySqlMonitoringApi(_storage, storageOptions); }
public void Migrate_Full_Success(string seedFile, bool assertCollectionHasItems) { using (var dbContext = new HangfireDbContext(ConnectionUtils.GetConnectionString(), "Hangfire-Mongo-Migration-Tests")) { // ARRANGE dbContext.Client.DropDatabase(dbContext.Database.DatabaseNamespace.DatabaseName); if (seedFile != null) { SeedCollectionFromZipArchive(dbContext, Path.Combine("Migration", seedFile)); } var storageOptions = new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Migrate, BackupStrategy = MongoBackupStrategy.None } }; var migrationManager = new MongoMigrationManager(storageOptions, dbContext.Database); // ACT MongoMigrationManager.MigrateIfNeeded(storageOptions, dbContext.Database); // ASSERT AssertDataIntegrity(dbContext, assertCollectionHasItems); } }
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 MySqlJobQueueMonitoringApiTests() { _connection = new MySqlConnection(ConnectionUtils.GetConnectionString()); _connection.Open(); _storage = new MySqlStorage(_connection); _sut = new MySqlJobQueueMonitoringApi(_storage); }
public OracleJobQueueMonitoringApiTests() { _connection = new OracleConnection(ConnectionUtils.GetConnectionString()); _connection.Open(); _storage = new OracleStorage(_connection); _sut = new OracleJobQueueMonitoringApi(_storage); }
public MySqlJobQueueMonitoringApiTests() { _connection = new MySqlConnection(ConnectionUtils.GetConnectionString()); _connection.Open(); var storageOptions = new MySqlStorageOptions(); _storage = new ElasticStorage.ElasticStorage(_connection, storageOptions); _sut = new MySqlJobQueueMonitoringApi(_storage, storageOptions); }
public MySqlFetchedJobTests() { _fetchedJob = new FetchedJob() { Id = _id, JobId = JobId, Queue = Queue }; _connection = new Mock <IDbConnection>(); _storageOptions = new MySqlStorageOptions { PrepareSchemaIfNecessary = false }; _storage = new Mock <ElasticStorage.ElasticStorage>(ConnectionUtils.GetConnectionString(), _storageOptions); }
public OracleFetchedJobTests() { _fetchedJob = new FetchedJob() { Id = _id, JobId = JobId, Queue = Queue }; _connection = new Mock <IDbConnection>(); var options = new OracleStorageOptions { PrepareSchemaIfNecessary = false }; _storage = new Mock <OracleStorage>(ConnectionUtils.GetConnectionString(), options); }
public void CamelCaseConvention_HangfireMongoDtos_StillInPascal() { // ARRANGE var mongoStorage = new MongoStorage( MongoClientSettings.FromConnectionString(ConnectionUtils.GetConnectionString()), ConnectionUtils.GetDatabaseName(), new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Drop, BackupStrategy = MongoBackupStrategy.None } } ); var id = Guid.NewGuid(); var dbContext = ConnectionUtils.CreateDbContext(); JobStorage.Current = mongoStorage; bool jobScheduled; var conventionPack = new ConventionPack { new CamelCaseElementNameConvention() }; ConventionRegistry.Register("CamelCase", conventionPack, t => true); // ACT using (new BackgroundJobServer(new BackgroundJobServerOptions { SchedulePollingInterval = TimeSpan.FromMilliseconds(100) })) { BackgroundJob.Enqueue(() => Signal.Set(id)); jobScheduled = Signal.WaitOne(id, TimeSpan.FromSeconds(1)); } // ASSERT var jobGraphCollectionName = dbContext.JobGraph.CollectionNamespace.CollectionName; var jobDto = dbContext .Database .GetCollection <BsonDocument>(jobGraphCollectionName) .Find(new BsonDocument("expireAt", new BsonDocument("$exists", true))) .FirstOrDefault(); Assert.Null(jobDto); Assert.True(jobScheduled, "Expected job to be scheduled"); }
public void Migrate_MultipleInstances_ThereCanBeOnlyOne() { using (var dbContext = new HangfireDbContext(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName())) { // ARRANGE dbContext.Database.DropCollection(dbContext.Schema.CollectionNamespace.CollectionName); var storageOptions = new MongoStorageOptions { MigrationOptions = new MongoMigrationOptions { Strategy = MongoMigrationStrategy.Drop, BackupStrategy = MongoBackupStrategy.None } }; var signal = new ManualResetEvent(false); var signalToStart = new ManualResetEvent(false); var taskCount = 10; var tasks = new Task <bool> [taskCount]; var count = 0; // ACT for (int i = 0; i < taskCount; i++) { tasks[i] = Task.Factory.StartNew <bool>(() => { count++; if (count == taskCount) { signalToStart.Set(); } signal.WaitOne(); return(MongoMigrationManager.MigrateIfNeeded(storageOptions, dbContext.Database)); }, TaskCreationOptions.LongRunning); } signalToStart.WaitOne(); signal.Set(); Task.WaitAll(tasks); // ASSERT Assert.True(tasks.Select(t => t.Result).Single(b => b)); } }
private static void RecreateDatabaseAndInstallObjects() { //var recreateDatabaseSql = String.Format( // @"if db_id('{0}') is null create database [{0}] COLLATE SQL_Latin1_General_CP1_CS_AS", // ConnectionUtils.GetDatabaseName()); //using (var connection = new SqlConnection( // ConnectionUtils.GetMasterConnectionString())) //{ // connection.Execute(recreateDatabaseSql); //} if (File.Exists(ConnectionUtils.GetDatabaseName())) { File.Delete(ConnectionUtils.GetDatabaseName()); } using (var connection = new System.Data.SQLite.SQLiteConnection(ConnectionUtils.GetConnectionString())) { SQLiteObjectsInstaller.Install(connection); } }
public OracleMonitoringApiTests() { _connection = new OracleConnection(ConnectionUtils.GetConnectionString()); _connection.Open(); var persistentJobQueueMonitoringApiMock = new Mock <IPersistentJobQueueMonitoringApi>(); persistentJobQueueMonitoringApiMock.Setup(m => m.GetQueues()).Returns(new[] { "default" }); var defaultProviderMock = new Mock <IPersistentJobQueueProvider>(); defaultProviderMock.Setup(m => m.GetJobQueueMonitoringApi()) .Returns(persistentJobQueueMonitoringApiMock.Object); var OracleStorageMock = new Mock <OracleStorage>(_connection); OracleStorageMock .Setup(m => m.QueueProviders) .Returns(new PersistentJobQueueProviderCollection(defaultProviderMock.Object)); _storage = OracleStorageMock.Object; _sut = new OracleMonitoringApi(_storage, _jobListLimit); }
private SQLiteStorage CreateStorage() { return(new SQLiteStorage( ConnectionUtils.GetConnectionString(), _options)); }
public ExpirationManagerFacts() { _storage = new MongoStorage(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName()); _token = new CancellationToken(true); }
private static MongoStorage CreateStorage() { return(new MongoStorage(ConnectionUtils.GetConnectionString(), ConnectionUtils.GetDatabaseName())); }