public async Task VerifyOrchestrationStateQueryByInstanceIdTest()
        {
            var instanceId = Guid.NewGuid().ToString("N");

            var values = Enum.GetValues(typeof(OrchestrationStatus)).Cast <OrchestrationStatus>().ToArray();

            var entities = new List <OrchestrationStateInstanceEntity>();

            entities.AddRange(Utils.InfiniteOrchestrationTestData().Take(values.Length));

            //ensure each status exists in the collection and they all have the same InstanceId
            entities.Select((e, i) => { e.State.OrchestrationStatus = values[i]; e.State.OrchestrationInstance.InstanceId = instanceId; return(e); }).ToList();

            await InstanceStore.WriteEntitiesAsync(entities);

            var actual = (await InstanceStore.GetOrchestrationStateAsync(instanceId, false)).ToList();

            Assert.AreEqual(1, actual.Count);

            var expectedState = entities
                                .Where(e => e.State.OrchestrationStatus != OrchestrationStatus.ContinuedAsNew)
                                .OrderBy(e => e.State.LastUpdatedTime)
                                .First();

            var actualState = actual.First();

            Assert.AreEqual(expectedState.State.OrchestrationInstance.ExecutionId, actualState.State.OrchestrationInstance.ExecutionId);
        }
Esempio n. 2
0
        public async Task VerifyWorkItemStatePersistedTest()
        {
            var entities = new List <InstanceEntityBase>();

            entities.Add(Utils.InfiniteWorkItemTestData(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")).First());

            await InstanceStore.WriteEntitiesAsync(entities);

            //second call should simply update each entity, not write new ones
            await InstanceStore.WriteEntitiesAsync(entities);

            await InstanceStore.DeleteEntitiesAsync(entities);

            using (var connection = GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = $"SELECT COUNT(1) FROM {Settings.WorkItemTableName}";

                    await connection.OpenAsync();

                    var count = (int)await command.ExecuteScalarAsync();

                    Assert.AreEqual(0, count, "Incorrect Work Item row count.");
                }
        }
Esempio n. 3
0
        public async Task VerifyOrchestrationStatePersistedTest()
        {
            var entities = new List <InstanceEntityBase>();

            entities.AddRange(Utils.InfiniteOrchestrationTestData().Take(5));

            await InstanceStore.WriteEntitiesAsync(entities);

            //second call should simply update each entity, not write new ones
            await InstanceStore.WriteEntitiesAsync(entities);

            await InstanceStore.DeleteEntitiesAsync(entities);

            using (var connection = GetConnection())
                using (var command = connection.CreateCommand())
                {
                    command.CommandText = $"SELECT COUNT(1) FROM {Settings.OrchestrationStateTableName}";

                    await connection.OpenAsync();

                    var count = (int)await command.ExecuteScalarAsync();

                    Assert.AreEqual(0, count, "Incorrect Orchestration Instance row count.");
                }
        }
Esempio n. 4
0
        public async Task PurgeByCompletedTimeTest()
        {
            var orchestrations = Utils.InfiniteOrchestrationTestData().Take(3).ToArray();

            var histories = orchestrations
                            .SelectMany(r => Utils.InfiniteWorkItemTestData(r.State.OrchestrationInstance.InstanceId, r.State.OrchestrationInstance.ExecutionId).Take(5))
                            .ToArray();

            int secondsToAdd = 0;

            foreach (var item in orchestrations)
            {
                item.State.CompletedTime = DateTime.UtcNow.AddSeconds(secondsToAdd++);
                item.State.CreatedTime   = item.State.LastUpdatedTime = DateTime.MaxValue;
            }

            await InstanceStore.WriteEntitiesAsync(orchestrations.Cast <InstanceEntityBase>().Concat(histories));

            var historyEntriesDeleted = await InstanceStore.PurgeOrchestrationHistoryEventsAsync(orchestrations.ElementAt(1).State.CompletedTime, OrchestrationStateTimeRangeFilterType.OrchestrationCompletedTimeFilter);

            Assert.AreEqual(10, historyEntriesDeleted);

            var instance = orchestrations.Last().State.OrchestrationInstance;
            var count    = (await InstanceStore.GetOrchestrationHistoryEventsAsync(instance.InstanceId, instance.ExecutionId)).Count();

            Assert.AreEqual(5, count);

            foreach (var item in orchestrations.Take(2))
            {
                instance = item.State.OrchestrationInstance;
                count    = (await InstanceStore.GetOrchestrationHistoryEventsAsync(instance.InstanceId, instance.ExecutionId)).Count();
                Assert.AreEqual(0, count);
            }
        }
        public async Task VerifyOrchestrationStateQueryTest()
        {
            var expectedOrchestrationState = Utils.InfiniteOrchestrationTestData().First();

            //additional data to ensure query doesn't return back more data than it should
            var extraOrchestrationState = Utils.InfiniteOrchestrationTestData().First();


            await InstanceStore.WriteEntitiesAsync(new InstanceEntityBase[] { expectedOrchestrationState, extraOrchestrationState });

            var actual = await InstanceStore.GetOrchestrationStateAsync(expectedOrchestrationState.State.OrchestrationInstance.InstanceId, expectedOrchestrationState.State.OrchestrationInstance.ExecutionId);

            Assert.AreEqual(expectedOrchestrationState.State.OrchestrationInstance.InstanceId, actual.State.OrchestrationInstance.InstanceId);
            Assert.AreEqual(expectedOrchestrationState.State.OrchestrationInstance.ExecutionId, actual.State.OrchestrationInstance.ExecutionId);
        }
        public async Task VerifyOrchestrationStateQueryByInstanceIdAllInstancesTest()
        {
            var instanceId = Guid.NewGuid().ToString("N");

            var values = Enum.GetValues(typeof(OrchestrationStatus)).Cast <OrchestrationStatus>().ToArray();

            var entities = new List <OrchestrationStateInstanceEntity>();

            entities.AddRange(Utils.InfiniteOrchestrationTestData().Take(values.Length));

            //ensure each status exists in the collection and they all have the same InstanceId
            entities.Select((e, i) => { e.State.OrchestrationStatus = values[i]; e.State.OrchestrationInstance.InstanceId = instanceId; return(e); }).ToList();

            await InstanceStore.WriteEntitiesAsync(entities);

            var actual = (await InstanceStore.GetOrchestrationStateAsync(instanceId, true)).ToList();

            Assert.AreEqual(entities.Count, actual.Count);
        }
        public async Task VerifyWorkItemQueryTest()
        {
            var expectedInstanceId  = Guid.NewGuid().ToString("N");
            var expectedExecutionId = Guid.NewGuid().ToString("N");

            var expectedWorkItemState = Utils.InfiniteWorkItemTestData(expectedInstanceId, expectedExecutionId).First();

            //additional data to ensure query doesn't return back more data than it should
            var extraWorkItemState = Utils.InfiniteWorkItemTestData(Guid.NewGuid().ToString("N"), Guid.NewGuid().ToString("N")).First();

            await InstanceStore.WriteEntitiesAsync(new InstanceEntityBase[] { expectedWorkItemState, extraWorkItemState });

            var actual = (await InstanceStore.GetOrchestrationHistoryEventsAsync(expectedInstanceId, expectedExecutionId)).ToList();

            Assert.AreEqual(1, actual.Count);

            var actualWorkItem = actual.First();

            Assert.AreEqual(expectedInstanceId, actualWorkItem.InstanceId);
            Assert.AreEqual(expectedExecutionId, actualWorkItem.ExecutionId);
        }
        public async Task VerifyWriteEntitiesFailsForUnexpectedType()
        {
            var state = new OrchestrationJumpStartInstanceEntity();

            await Assert.ThrowsExceptionAsync <InvalidOperationException>(() => InstanceStore.WriteEntitiesAsync(new[] { state }));
        }