Пример #1
0
 public HostIndexer(IHostIndexManager hostIndexManager, IFunctionIndexManager functionIndexManager,
     IFunctionIndexVersionManager functionIndexVersionManager)
 {
     _hostIndexManager = hostIndexManager;
     _functionIndexManager = functionIndexManager;
     _functionIndexVersionManager = functionIndexVersionManager;
 }
Пример #2
0
        private static HostIndexer CreateProductUnderTest(IHostIndexManager hostIndexManager,
                                                          IFunctionIndexManager functionIndexManager)
        {
            IFunctionIndexVersionManager functionIndexVersionManager = CreateStubFunctionIndexVersionManager();

            return(CreateProductUnderTest(hostIndexManager, functionIndexManager, functionIndexVersionManager));
        }
Пример #3
0
 public HostIndexer(IHostIndexManager hostIndexManager, IFunctionIndexManager functionIndexManager,
                    IFunctionIndexVersionManager functionIndexVersionManager)
 {
     _hostIndexManager            = hostIndexManager;
     _functionIndexManager        = functionIndexManager;
     _functionIndexVersionManager = functionIndexVersionManager;
 }
Пример #4
0
        private static HostIndexer CreateProductUnderTest(IFunctionIndexVersionManager functionIndexVersionManager)
        {
            IHostIndexManager hostIndexManager = CreateStubHostIndexManager(existingSnapshot: null,
                                                                            persistSucceeds: false);
            IFunctionIndexManager functionIndexManager = CreateStubFunctionIndexManager();

            return(CreateProductUnderTest(hostIndexManager, functionIndexManager, functionIndexVersionManager));
        }
Пример #5
0
 private static void AddFunctionToIndex(IFunctionIndexManager functionIndexManager, string hostId,
                                        string hostFunctionId, DateTimeOffset hostVersion)
 {
     Assert.True(functionIndexManager.CreateOrUpdateIfLatest(new FunctionSnapshot
     {
         Id             = hostId + "_" + hostFunctionId,
         HostFunctionId = hostFunctionId,
         QueueName      = hostId,
         HostVersion    = hostVersion
     }));
 }
Пример #6
0
        public void ProcessHostStarted_IfHostConcurrentlyUpdated_DeletesKnownFunctionsIfLatest()
        {
            // Arrange
            const string hostId = "host";

            string[]          originalFunctionIds = new string[] { "a", "b" };
            string[]          finalFunctionIds    = new string[] { "b", "d" };
            IHostIndexManager concurrentlyRemoveFunctionsHostIndexManager = CreateStubHostIndexManager(
                existingSnapshot: CreateHostSnapshot(DateTimeOffset.MaxValue, finalFunctionIds), persistSucceeds: true);
            IFunctionIndexManager functionIndexManager = CreateFakeFunctionIndexManager();
            DateTimeOffset        earlierHostVersion   = DateTimeOffset.MinValue;

            AddFunctionToIndex(functionIndexManager, hostId, originalFunctionIds[0], earlierHostVersion);
            AddFunctionToIndex(functionIndexManager, hostId, originalFunctionIds[1], earlierHostVersion);
            IHostIndexer product = CreateProductUnderTest(concurrentlyRemoveFunctionsHostIndexManager,
                                                          functionIndexManager);
            HostStartedMessage message = new HostStartedMessage
            {
                SharedQueueName = hostId,
                EnqueuedOn      = DateTimeOffset.Now,
                Functions       = new FunctionDescriptor[]
                {
                    new FunctionDescriptor {
                        Id = originalFunctionIds[0]
                    },
                    new FunctionDescriptor {
                        Id = originalFunctionIds[1]
                    },
                    new FunctionDescriptor {
                        Id = "c"
                    },
                    new FunctionDescriptor {
                        Id = "d"
                    }
                }
            };

            // Act
            product.ProcessHostStarted(message);

            // Assert
            IEnumerable <VersionedMetadata> functions = functionIndexManager.List(hostId);

            Assert.NotNull(functions); // Guard
            IEnumerable <string> functionIds = functions.Select(f => f.Id).ToArray();

            Assert.Equal(finalFunctionIds, functionIds);
        }
Пример #7
0
        public void ProcessHostStarted_UpdatesExistingFunctionsIfLatest()
        {
            // Arrange
            const string   hostId          = "host";
            DateTimeOffset expectedVersion = DateTimeOffset.Now;

            string[]          expectedFunctionIds = new string[] { "a", "b", "c" };
            IHostIndexManager hostIndexManager    = CreateStubHostIndexManager(
                CreateHostSnapshot(expectedVersion, expectedFunctionIds), persistSucceeds: true);
            IFunctionIndexManager functionIndexManager = CreateFakeFunctionIndexManager();
            DateTimeOffset        earlierHostVersion   = DateTimeOffset.MinValue;

            AddFunctionToIndex(functionIndexManager, hostId, expectedFunctionIds[0], earlierHostVersion);
            AddFunctionToIndex(functionIndexManager, hostId, expectedFunctionIds[1], earlierHostVersion);
            AddFunctionToIndex(functionIndexManager, hostId, expectedFunctionIds[2], earlierHostVersion);
            IHostIndexer       product = CreateProductUnderTest(hostIndexManager, functionIndexManager);
            HostStartedMessage message = new HostStartedMessage
            {
                SharedQueueName = hostId,
                EnqueuedOn      = expectedVersion,
                Functions       = new FunctionDescriptor[]
                {
                    new FunctionDescriptor {
                        Id = expectedFunctionIds[0]
                    },
                    new FunctionDescriptor {
                        Id = expectedFunctionIds[1]
                    },
                    new FunctionDescriptor {
                        Id = expectedFunctionIds[2]
                    }
                }
            };

            // Act
            product.ProcessHostStarted(message);

            // Assert
            IEnumerable <VersionedMetadata> functions = functionIndexManager.List(hostId);

            Assert.NotNull(functions); // Guard
            IEnumerable <string> functionIds = functions.Select(f => f.Id).ToArray();

            Assert.Equal(expectedFunctionIds, functionIds);
            IEnumerable <DateTimeOffset> versions = functions.Select(f => f.Version).ToArray();

            Assert.Equal(new DateTimeOffset[] { expectedVersion, expectedVersion, expectedVersion }, versions);
        }
Пример #8
0
        public void ProcessHostStarted_IfHostPreviouslyRemovedButProcessingAborted_DeletesKnownFunctionsIfLatest()
        {
            // Arrange
            const string   hostId      = "host";
            DateTimeOffset hostVersion = DateTimeOffset.Now;

            string[]          previouslyProcessedFunctionIds = new string[] { "a", "b", "c" };
            IHostIndexManager concurrentlyRemoveFunctionsHostIndexManager = CreateStubHostIndexManager(
                existingSnapshot: null, persistSucceeds: false);
            IFunctionIndexManager functionIndexManager = CreateFakeFunctionIndexManager();

            AddFunctionToIndex(functionIndexManager, hostId, previouslyProcessedFunctionIds[0], hostVersion);
            AddFunctionToIndex(functionIndexManager, hostId, previouslyProcessedFunctionIds[1], hostVersion);
            AddFunctionToIndex(functionIndexManager, hostId, previouslyProcessedFunctionIds[2], hostVersion);
            IHostIndexer product = CreateProductUnderTest(concurrentlyRemoveFunctionsHostIndexManager,
                                                          functionIndexManager);
            HostStartedMessage message = new HostStartedMessage
            {
                SharedQueueName = hostId,
                EnqueuedOn      = hostVersion,
                Functions       = new FunctionDescriptor[]
                {
                    new FunctionDescriptor {
                        Id = previouslyProcessedFunctionIds[0]
                    },
                    new FunctionDescriptor {
                        Id = previouslyProcessedFunctionIds[1]
                    },
                    new FunctionDescriptor {
                        Id = previouslyProcessedFunctionIds[2]
                    }
                }
            };

            // Act
            product.ProcessHostStarted(message);

            // Assert
            IEnumerable <VersionedMetadata> functions = functionIndexManager.List(hostId);

            Assert.NotNull(functions); // Guard
            IEnumerable <string> functionIds = functions.Select(f => f.Id).ToArray();

            Assert.Equal(new string[0], functionIds);
        }
 private static HostIndexer CreateProductUnderTest(IHostIndexManager hostIndexManager,
     IFunctionIndexManager functionIndexManager, IFunctionIndexVersionManager functionIndexVersionManager)
 {
     return new HostIndexer(hostIndexManager, functionIndexManager, functionIndexVersionManager);
 }
 private static HostIndexer CreateProductUnderTest(IHostIndexManager hostIndexManager,
     IFunctionIndexManager functionIndexManager)
 {
     IFunctionIndexVersionManager functionIndexVersionManager = CreateStubFunctionIndexVersionManager();
     return CreateProductUnderTest(hostIndexManager, functionIndexManager, functionIndexVersionManager);
 }
 private static void AddFunctionToIndex(IFunctionIndexManager functionIndexManager, string hostId,
     string hostFunctionId, DateTimeOffset hostVersion)
 {
     Assert.True(functionIndexManager.CreateOrUpdateIfLatest(new FunctionSnapshot
     {
         Id = hostId + "_" + hostFunctionId,
         HostFunctionId = hostFunctionId,
         QueueName = hostId,
         HostVersion = hostVersion
     }));
 }
Пример #12
0
 private static HostIndexer CreateProductUnderTest(IHostIndexManager hostIndexManager,
                                                   IFunctionIndexManager functionIndexManager, IFunctionIndexVersionManager functionIndexVersionManager)
 {
     return(new HostIndexer(hostIndexManager, functionIndexManager, functionIndexVersionManager));
 }