Ejemplo n.º 1
0
        public async Task FahClientMessages_UpdateMessageAsync_PopulatesSlotWithSlotOptionsAfterReceivingAllSlotOptions()
        {
            // Arrange
            var fahClient = SetupFahClientForSendingMockCommands();
            var messages  = new FahClientMessages(fahClient);
            var slotInfo  = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" }, { \"id\": \"01\" } ]");
            // slot info must have already populated the SlotCollection
            await messages.UpdateMessageAsync(slotInfo);

            var slotOptions0 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }");
            var slotOptions1 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"1\" }");

            // Assert
            Assert.IsNull(messages.SlotCollection[0].SlotOptions);
            Assert.IsNull(messages.SlotCollection[1].SlotOptions);
            // Act
            await messages.UpdateMessageAsync(slotOptions0);

            // Assert
            Assert.IsNull(messages.SlotCollection[0].SlotOptions);
            Assert.IsNull(messages.SlotCollection[1].SlotOptions);
            // Act
            await messages.UpdateMessageAsync(slotOptions1);

            // Assert
            Assert.AreSame(messages.SlotOptionsCollection[0], messages.SlotCollection[0].SlotOptions);
            Assert.AreSame(messages.SlotOptionsCollection[1], messages.SlotCollection[1].SlotOptions);
        }
Ejemplo n.º 2
0
        public async Task FahClientMessages_UpdateMessageAsync_ReturnsNotificationThatSlotInformationHasChangedAfterReceivingAllSlotOptions()
        {
            // Arrange
            var fahClient = SetupFahClientForSendingMockCommands();
            var messages  = new FahClientMessages(fahClient);
            var slotInfo  = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" }, { \"id\": \"01\" } ]");
            // slot info must have already populated the SlotCollection
            await messages.UpdateMessageAsync(slotInfo);

            var slotOptions0 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }");
            var slotOptions1 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"1\" }");
            // Act
            var result = await messages.UpdateMessageAsync(slotOptions0);

            // Assert
            Assert.AreEqual(1, messages.SlotOptionsCollection.Count);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
            // Act
            result = await messages.UpdateMessageAsync(slotOptions1);

            // Assert
            Assert.AreEqual(2, messages.SlotOptionsCollection.Count);
            Assert.IsTrue(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 3
0
        public async Task FahClientMessages_UpdateMessageAsync_ReturnsNotificationThatClientDataShouldBeUpdatedWhenSlotInformationHasChangedAfterLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                var slotInfo  = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" } ]");
                await messages.UpdateMessageAsync(slotInfo);

                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                await messages.UpdateMessageAsync(logRestart);

                slotInfo = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\", \"description\": \"cpu:15\" } ]");
                var slotOptions = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }");
                // Act
                var result = await messages.UpdateMessageAsync(slotInfo);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsFalse(result.ExecuteRetrieval);
                // Act
                result = await messages.UpdateMessageAsync(slotOptions);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsTrue(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }
Ejemplo n.º 4
0
        public void FahClientMessages_IsHeartbeatOverdue_ReturnsFalseWhenThereIsNoHeartbeatMessage()
        {
            // Arrange
            var messages = new FahClientMessages(null);
            // Act
            var overdue = messages.IsHeartbeatOverdue();

            // Assert
            Assert.IsFalse(overdue);
        }
Ejemplo n.º 5
0
        public FahClient(ILogger logger, IPreferences preferences, IProteinBenchmarkService benchmarkService,
                         IProteinService proteinService, IWorkUnitRepository workUnitRepository) : base(logger, preferences, benchmarkService)
        {
            ProteinService     = proteinService;
            WorkUnitRepository = workUnitRepository;
            Messages           = new FahClientMessages(this);

            _slots     = new List <SlotModel>();
            _slotsLock = new ReaderWriterLockSlim();
        }
Ejemplo n.º 6
0
        public async Task FahClientMessages_SetupClientToSendMessageUpdatesAsync_ExecutesUpdateCommands()
        {
            // Arrange
            var fahClient  = SetupFahClientForSendingMockCommands();
            var connection = (MockFahClientConnection)fahClient.Connection;
            var messages   = new FahClientMessages(fahClient);
            // Act
            await messages.SetupClientToSendMessageUpdatesAsync();

            // Assert
            Assert.AreEqual(7, connection.Commands.Count);
            Assert.IsTrue(connection.Commands.All(x => x.Executed));
        }
Ejemplo n.º 7
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLatestHeartbeat()
        {
            // Arrange
            var messages  = new FahClientMessages(null);
            var heartbeat = CreateMessage(FahClientMessageType.Heartbeat, String.Empty);
            // Act
            var result = await messages.UpdateMessageAsync(heartbeat);

            // Assert
            Assert.AreEqual(heartbeat, messages.Heartbeat);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 8
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLatestInfo()
        {
            // Arrange
            var messages = new FahClientMessages(null);
            var info     = CreateMessage(FahClientMessageType.Info, "[ ]");
            // Act
            var result = await messages.UpdateMessageAsync(info);

            // Assert
            Assert.IsNotNull(messages.Info);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 9
0
        public async Task FahClientMessages_IsHeartbeatOverdue_ReturnsTrueWhenHeartbeatHasNotBeenReceivedAfterLongPeriodOfTime()
        {
            // Arrange
            var messages  = new FahClientMessages(null);
            var heartbeat = new FahClientMessage(new FahClientMessageIdentifier(FahClientMessageType.Heartbeat, DateTime.UtcNow.Subtract(TimeSpan.FromMinutes(5))), null);
            await messages.UpdateMessageAsync(heartbeat);

            // Act
            var overdue = messages.IsHeartbeatOverdue();

            // Assert
            Assert.IsTrue(overdue);
        }
Ejemplo n.º 10
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLatestOptions()
        {
            // Arrange
            var messages = new FahClientMessages(null);
            var options  = CreateMessage(FahClientMessageType.Options, "{ }");
            // Act
            var result = await messages.UpdateMessageAsync(options);

            // Assert
            Assert.IsNotNull(messages.Options);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 11
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLatestUnitCollection()
        {
            // Arrange
            var messages  = new FahClientMessages(null);
            var queueInfo = CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0 }, { \"id\": \"00\", \"slot\": 1 } ]");
            // Act
            var result = await messages.UpdateMessageAsync(queueInfo);

            // Assert
            Assert.IsNotNull(messages.UnitCollection);
            Assert.AreEqual(2, messages.UnitCollection.Count);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 12
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLatestSlotCollection()
        {
            // Arrange
            var fahClient = SetupFahClientForSendingMockCommands();
            var messages  = new FahClientMessages(fahClient);
            var slotInfo  = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" }, { \"id\": \"01\" } ]");
            // Act
            var result = await messages.UpdateMessageAsync(slotInfo);

            // Assert
            Assert.IsNotNull(messages.SlotCollection);
            Assert.AreEqual(2, messages.SlotCollection.Count);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 13
0
        public async Task FahClientMessages_UpdateMessageAsync_LogIsNotRetrievedUntilMessageLengthIsNotLarge()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logText    = new String(Enumerable.Repeat('a', UInt16.MaxValue).ToArray());
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, $"\"{logText}\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.IsFalse(messages.LogIsRetrieved);
            }
        }
Ejemplo n.º 14
0
        public async Task FahClientMessages_UpdateMessageAsync_WritesLogMessagesToCachedClientLogFile()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                string path = Path.Combine(fahClient.Preferences.Get <string>(Preference.CacheDirectory), fahClient.Settings.ClientLogFileName);
                Assert.IsTrue(File.Exists(path));
            }
        }
Ejemplo n.º 15
0
        public async Task FahClientMessages_UpdateMessageAsync_ExecutesSlotOptionsCommandForEachSlotInSlotCollection()
        {
            // Arrange
            var fahClient  = SetupFahClientForSendingMockCommands();
            var connection = (MockFahClientConnection)fahClient.Connection;
            var messages   = new FahClientMessages(fahClient);
            var slotInfo   = CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" }, { \"id\": \"01\" } ]");
            // Act
            var result = await messages.UpdateMessageAsync(slotInfo);

            // Assert
            Assert.AreEqual(2, connection.Commands.Count);
            Assert.IsTrue(connection.Commands.All(x => x.Executed));
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 16
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresLogMessagesInFahClientLog()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                var result = await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.AreEqual(1, messages.Log.ClientRuns[0].LogLines.Count);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }
Ejemplo n.º 17
0
        public async Task FahClientMessages_Clear_RemovesAllMessageData()
        {
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Heartbeat, String.Empty));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Info, "[ ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.Options, "{ }"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.SlotInfo, "[ { \"id\": \"00\" } ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0 } ]"));

                await messages.UpdateMessageAsync(CreateMessage(FahClientMessageType.LogRestart, "\"Log\""));

                // Assert (pre-condition)
                Assert.IsNotNull(messages.Heartbeat);
                Assert.IsNotNull(messages.Info);
                Assert.IsNotNull(messages.Options);
                Assert.IsNotNull(messages.SlotCollection);
                Assert.AreNotEqual(0, messages.SlotOptionsCollection.Count);
                Assert.IsNotNull(messages.UnitCollection);
                Assert.AreNotEqual(0, messages.Log.ClientRuns.Count);
                Assert.IsTrue(messages.LogIsRetrieved);
                // Act
                messages.Clear();
                // Assert
                Assert.IsNull(messages.Heartbeat);
                Assert.IsNull(messages.Info);
                Assert.IsNull(messages.Options);
                Assert.IsNull(messages.SlotCollection);
                Assert.AreEqual(0, messages.SlotOptionsCollection.Count);
                Assert.IsNull(messages.UnitCollection);
                Assert.AreEqual(0, messages.Log.ClientRuns.Count);
                Assert.IsFalse(messages.LogIsRetrieved);
            }
        }
Ejemplo n.º 18
0
        public async Task FahClientMessages_UpdateMessageAsync_ExecutesQueueInfoCommandWhenLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient  = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var connection = (MockFahClientConnection)fahClient.Connection;
                var messages   = new FahClientMessages(fahClient);
                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                // Act
                await messages.UpdateMessageAsync(logRestart);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.AreEqual(1, connection.Commands.Count);
                var command = connection.Commands[0];
                Assert.AreEqual("queue-info", command.CommandText);
                Assert.IsTrue(command.Executed);
            }
        }
Ejemplo n.º 19
0
        public async Task FahClientMessages_UpdateMessageAsync_StoresEachSlotOptionsMessage()
        {
            // Arrange
            var messages     = new FahClientMessages(null);
            var slotOptions0 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"0\" }");
            var slotOptions1 = CreateMessage(FahClientMessageType.SlotOptions, "{ \"machine-id\": \"1\" }");
            // Act
            var result = await messages.UpdateMessageAsync(slotOptions0);

            // Assert
            Assert.AreEqual(1, messages.SlotOptionsCollection.Count);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
            // Act
            result = await messages.UpdateMessageAsync(slotOptions1);

            // Assert
            Assert.AreEqual(2, messages.SlotOptionsCollection.Count);
            Assert.IsFalse(result.SlotsUpdated);
            Assert.IsFalse(result.ExecuteRetrieval);
        }
Ejemplo n.º 20
0
        public async Task FahClientMessages_UpdateMessageAsync_ReturnsNotificationThatClientDataShouldBeUpdatedWhenUnitInformationHasChangedAfterLogIsRetrieved()
        {
            // Arrange
            using (var artifacts = new ArtifactFolder())
            {
                var fahClient = SetupFahClientForHandlingLogMessages(artifacts.Path);
                var messages  = new FahClientMessages(fahClient);
                var queueInfo = CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0, \"percentdone\": \"8%\" } ]");
                await messages.UpdateMessageAsync(queueInfo);

                var logRestart = CreateMessage(FahClientMessageType.LogRestart, "\"Log\"");
                await messages.UpdateMessageAsync(logRestart);

                queueInfo = CreateMessage(FahClientMessageType.QueueInfo, "[ { \"id\": \"01\", \"slot\": 0, \"percentdone\": \"9%\" } ]");
                // Act
                var result = await messages.UpdateMessageAsync(queueInfo);

                // Assert
                Assert.IsTrue(messages.LogIsRetrieved);
                Assert.IsFalse(result.SlotsUpdated);
                Assert.IsTrue(result.ExecuteRetrieval);
            }
        }