예제 #1
0
        public async Task CanCreateAndDropSchema(bool isDatabaseMissing)
        {
            using TestDatabase testDb = this.CreateTestDb(!isDatabaseMissing);
            IOrchestrationService service = this.CreateServiceWithTestDb(testDb);

            // Create the DB schema for the first time
            await service.CreateAsync(recreateInstanceStore : true);

            LogAssert.NoWarningsOrErrors(this.logProvider);
            LogAssert
            .For(this.logProvider)
            .Expect(
                LogAssert.CheckedDatabase())
            .ExpectIf(
                isDatabaseMissing,
                LogAssert.CommandCompleted($"CREATE DATABASE [{testDb.Name}]"),
                LogAssert.CreatedDatabase(testDb.Name))
            .Expect(
                LogAssert.AcquiredAppLock(),
                LogAssert.ExecutedSqlScript("drop-schema.sql"),
                LogAssert.ExecutedSqlScript("schema-0.2.0.sql"),
                LogAssert.ExecutedSqlScript("logic.sql"),
                LogAssert.ExecutedSqlScript("permissions.sql"),
                LogAssert.SprocCompleted("dt._UpdateVersion"))
            .EndOfLog();

            ValidateDatabaseSchema(testDb);

            // Create the DB schema again - should be a no-op since it already exists
            this.logProvider.Clear();
            await service.CreateIfNotExistsAsync();

            ValidateDatabaseSchema(testDb);

            // The subsequent execution should run exactly one sproc and no scripts.
            // It's important to verify this to ensure the overhead of CreateIfNotExistsAsync is very small.
            LogAssert.NoWarningsOrErrors(this.logProvider);
            LogAssert.Sequence(
                this.logProvider,
                LogAssert.CheckedDatabase(),
                LogAssert.AcquiredAppLock(),
                LogAssert.SprocCompleted("dt._GetVersions"));

            // Delete the database and validate
            this.logProvider.Clear();
            await service.DeleteAsync();

            LogAssert.NoWarningsOrErrors(this.logProvider);
            LogAssert.Sequence(
                this.logProvider,
                LogAssert.AcquiredAppLock(),
                LogAssert.ExecutedSqlScript("drop-schema.sql"));

            // The previous schema validation ensures all objects are in the "dt" schema.
            // We know that all objects were successfully removed if the "dt" no longer exists.
            Assert.DoesNotContain("dt", testDb.GetSchemas());
        }
예제 #2
0
        /// <summary>
        /// Creates the instance of the host.
        /// </summary>
        /// <param name="orchestrationService"></param>
        /// <param name="orchestrationClient"></param>
        /// <param name="instanceStore"></param>
        /// <param name="resetHub"></param>
        /// <param name="loggerFactory"></param>
        /// <param name="scopes">List of scopes, which will be appended to logger scopes, every time</param>
        public ServiceHost(IOrchestrationService orchestrationService,
                           IOrchestrationServiceClient orchestrationClient,
                           IOrchestrationServiceInstanceStore instanceStore,
                           bool resetHub = false,
                           ILoggerFactory loggerFactory = null)
        {
            m_HubClient                 = new TaskHubClient(orchestrationClient);
            this.m_TaskHubWorker        = new TaskHubWorker(orchestrationService);
            this.m_InstanceStoreService = instanceStore;

            if (loggerFactory != null)
            {
                m_LoggerFactory = loggerFactory;
                m_Logger        = m_LoggerFactory.CreateLogger <ServiceHost>();
            }

            if (resetHub)
            {
                orchestrationService.DeleteAsync().Wait();
            }

            int n = 10;

            while (--n > 0)
            {
                try
                {
                    orchestrationService.CreateIfNotExistsAsync().Wait();
                    break;
                }
                catch (AggregateException aggEx)
                {
                    if (n <= 0)
                    {
                        throw;
                    }

                    if (aggEx.InnerException.Message.Contains("409"))
                    {
                        Thread.Sleep(10000);
                    }
                }
            }
        }
예제 #3
0
 public Task DeleteAsync()
 {
     return(_innerOrchestrationService.DeleteAsync());
 }