Пример #1
0
        public void GetInfoTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
            {
                Connect(fahClient);

                var buffer = fahClient.InternalBuffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithClientInfoData1)).Repeat.Once();
                _stream.Expect(x => x.DataAvailable).Return(true).Repeat.Once();
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithClientInfoData2)).Repeat.Once();
                _stream.Expect(x => x.DataAvailable).Return(true).Repeat.Once();
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithClientInfoData3)).Repeat.Once();

                MessageUpdatedEventArgs e = null;
                fahClient.MessageUpdated += (sender, args) => e = args;
                fahClient.SocketTimerElapsed(null, null);

                Assert.AreEqual(JsonMessageKey.Info, e.Key);
                Assert.AreEqual(typeof(Info), e.DataType);
                var info = fahClient.GetMessage <Info>();
                Assert.IsNotNull(info);
                Assert.AreEqual(0, info.Errors.Count());
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Пример #2
0
        public void GetInfoTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
             {
            Connect(fahClient);

            var buffer = fahClient.InternalBuffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithClientInfoData1));
            _stream.Expect(x => x.DataAvailable).Return(true);
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithClientInfoData2));
            _stream.Expect(x => x.DataAvailable).Return(true);
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithClientInfoData3));

            MessageUpdatedEventArgs e = null;
            fahClient.MessageUpdated += (sender, args) => e = args;
            fahClient.SocketTimerElapsed(null, null);

            Assert.AreEqual(JsonMessageKey.Info, e.Key);
            Assert.AreEqual(typeof(Info), e.DataType);
            var info = fahClient.GetMessage<Info>();
            Assert.IsNotNull(info);
            Assert.AreEqual(0, info.Errors.Count());
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Пример #3
0
        public void GetLogUpdateTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
            {
                Connect(fahClient);

                var buffer = new byte[70 * 1024];
                fahClient.InternalBuffer = buffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithLogUpdateData));

                MessageUpdatedEventArgs e = null;
                fahClient.MessageUpdated += (sender, args) => e = args;
                fahClient.SocketTimerElapsed(null, null);

                Assert.AreEqual(JsonMessageKey.LogUpdate, e.Key);
                Assert.AreEqual(typeof(LogUpdate), e.DataType);
                var logUpdate = fahClient.GetMessage <LogUpdate>();
                Assert.IsNotNull(logUpdate);
                Assert.AreEqual('s', logUpdate.Value[0]);
                Assert.IsFalse(logUpdate.Value.EndsWith('\"'));
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Пример #4
0
        public void GetUnitDerivedCollectionTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
            {
                Connect(fahClient);

                var buffer = fahClient.InternalBuffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithUnitsData)).Repeat.Once();

                MessageUpdatedEventArgs e = null;
                fahClient.MessageUpdated += (sender, args) => e = args;
                fahClient.SocketTimerElapsed(null, null);

                Assert.AreEqual(JsonMessageKey.QueueInfo, e.Key);
                Assert.AreEqual(typeof(UnitCollection), e.DataType);
                var unitCollection = fahClient.GetMessage <UnitCollection, UnitDerived>();
                Assert.IsNotNull(unitCollection);
                Assert.AreEqual(0, unitCollection.Errors.Count());
                Assert.AreEqual(1, unitCollection.Count);
                Assert.AreEqual(1, unitCollection[0].Errors.Count());
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
        public void ClientSettingsManager_Write_WritesTheClientSettingsToDisk()
        {
            // Arrange
            const string testFile = "..\\..\\TestFiles\\new.ext";

            var client = new FahClient();

            client.Settings = new ClientSettings {
                Name = "test"
            };
            // TODO: Implement ArtifactFolder
            var manager = new ClientSettingsManager();

            // Act
            try
            {
                manager.Write(new[] { client.Settings }, testFile, 1);
                // Assert
                Assert.AreEqual("..\\..\\TestFiles\\new.ext", manager.FileName);
                Assert.AreEqual(1, manager.FilterIndex);
                Assert.AreEqual(".ext", manager.FileExtension);
            }
            finally
            {
                try
                {
                    File.Delete(testFile);
                }
                catch (Exception)
                {
                    // do nothing
                }
            }
        }
Пример #6
0
        public MainForm()
        {
            _fahClient = new FahClient();
             _fahClient.MessageUpdated += FahClientMessageUpdated;
             _fahClient.ConnectedChanged += FahClientConnectedChanged;
             _fahClient.DataLengthSent += FahClientDataLengthSent;
             _fahClient.DataLengthReceived += FahClientDataLengthReceived;
             _fahClient.StatusMessage += FahClientStatusMessage;

             InitializeComponent();

             base.Text = String.Format("HFM Client Tool v{0}", Core.Application.VersionWithRevision);
        }
Пример #7
0
      public void UpdateBenchmarkDataTest()
      {
         // setup
         var benchmarkCollection = new ProteinBenchmarkCollection();
         var database = MockRepository.GenerateMock<IUnitInfoDatabase>();
         var fahClient = new FahClient(MockRepository.GenerateStub<IMessageConnection>()) { BenchmarkCollection = benchmarkCollection, UnitInfoDatabase = database };

         var unitInfo1 = new UnitInfo();
         unitInfo1.OwningClientName = "Owner";
         unitInfo1.OwningClientPath = "Path";
         unitInfo1.OwningSlotId = 0;
         unitInfo1.ProjectID = 2669;
         unitInfo1.ProjectRun = 1;
         unitInfo1.ProjectClone = 2;
         unitInfo1.ProjectGen = 3;
         unitInfo1.FinishedTime = new DateTime(2010, 1, 1);
         unitInfo1.QueueIndex = 0;
         var currentUnitInfo = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1 };

         var unitInfo1Clone = unitInfo1.DeepClone();
         unitInfo1Clone.FramesObserved = 4;
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2 });
         unitInfo1Clone.SetUnitFrame(new UnitFrame { TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3 });
         unitInfo1Clone.UnitResult = WorkUnitResult.FinishedUnit;
         var unitInfoLogic1 = new UnitInfoModel { CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone };

         var parsedUnits = new[] { unitInfoLogic1 };

         // arrange
         database.Stub(x => x.Connected).Return(true);
         database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(1);

         var benchmarkClient = new BenchmarkClient("Owner Slot 00", "Path");

         // assert before act
         Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient));
         Assert.AreEqual(false, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
         Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData));

         // act
         fahClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 0);

         // assert after act
         Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient));
         Assert.AreEqual(true, new List<int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
         Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime);

         database.VerifyAllExpectations();
      }
Пример #8
0
        internal static LogLineType GetLogLineType(string line, FahLogType fahLogType)
        {
            var logLineType = Common.DetermineLineType(line);

            if (logLineType == LogLineType.Unknown)
            {
                switch (fahLogType)
                {
                case FahLogType.Legacy:
                    logLineType = Legacy.DetermineLineType(line);
                    break;

                case FahLogType.FahClient:
                    logLineType = FahClient.DetermineLineType(line);
                    break;
                }
            }
            return(logLineType);
        }
Пример #9
0
        public void GetHeartbeatTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
             {
            Connect(fahClient);

            var buffer = fahClient.InternalBuffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithHeartbeatData));

            MessageUpdatedEventArgs e = null;
            fahClient.MessageUpdated += (sender, args) => e = args;
            fahClient.SocketTimerElapsed(null, null);

            Assert.AreEqual(JsonMessageKey.Heartbeat, e.Key);
            Assert.AreEqual(typeof(Heartbeat), e.DataType);
            var heartbeat = fahClient.GetMessage<Heartbeat>();
            Assert.IsNotNull(heartbeat);
            Assert.AreEqual(0, heartbeat.Errors.Count());
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Пример #10
0
        public void GetHeartbeatTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
            {
                Connect(fahClient);

                var buffer = fahClient.InternalBuffer;
                _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
                    new Func <byte[], int, int, int>(FillBufferWithHeartbeatData));

                MessageUpdatedEventArgs e = null;
                fahClient.MessageUpdated += (sender, args) => e = args;
                fahClient.SocketTimerElapsed(null, null);

                Assert.AreEqual(JsonMessageKey.Heartbeat, e.Key);
                Assert.AreEqual(typeof(Heartbeat), e.DataType);
                var heartbeat = fahClient.GetMessage <Heartbeat>();
                Assert.IsNotNull(heartbeat);
                Assert.AreEqual(0, heartbeat.Errors.Count());
            }

            _tcpClient.VerifyAllExpectations();
            _stream.VerifyAllExpectations();
        }
Пример #11
0
        public void GetUnitDerivedCollectionTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
             {
            Connect(fahClient);

            var buffer = fahClient.InternalBuffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithUnitsData));

            MessageUpdatedEventArgs e = null;
            fahClient.MessageUpdated += (sender, args) => e = args;
            fahClient.SocketTimerElapsed(null, null);

            Assert.AreEqual(JsonMessageKey.QueueInfo, e.Key);
            Assert.AreEqual(typeof(UnitCollection), e.DataType);
            var unitCollection = fahClient.GetMessage<UnitCollection, UnitDerived>();
            Assert.IsNotNull(unitCollection);
            Assert.AreEqual(0, unitCollection.Errors.Count());
            Assert.AreEqual(1, unitCollection.Count);
            Assert.AreEqual(1, unitCollection[0].Errors.Count());
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Пример #12
0
        public void GetLogUpdateTest()
        {
            using (var fahClient = new FahClient(CreateClientFactory()))
             {
            Connect(fahClient);

            var buffer = new byte[70 * 1024];
            fahClient.InternalBuffer = buffer;
            _stream.Expect(x => x.Read(buffer, 0, buffer.Length)).Do(
               new Func<byte[], int, int, int>(FillBufferWithLogUpdateData));

            MessageUpdatedEventArgs e = null;
            fahClient.MessageUpdated += (sender, args) => e = args;
            fahClient.SocketTimerElapsed(null, null);

            Assert.AreEqual(JsonMessageKey.LogUpdate, e.Key);
            Assert.AreEqual(typeof(LogUpdate), e.DataType);
            var logUpdate = fahClient.GetMessage<LogUpdate>();
            Assert.IsNotNull(logUpdate);
            Assert.AreEqual('s', logUpdate.Value[0]);
            Assert.IsFalse(logUpdate.Value.EndsWith('\"'));
             }

             _tcpClient.VerifyAllExpectations();
             _stream.VerifyAllExpectations();
        }
Пример #13
0
        public void UpdateBenchmarkDataTest()
        {
            // setup
            var benchmarkCollection = new ProteinBenchmarkService();
            var database            = MockRepository.GenerateMock <IUnitInfoDatabase>();
            var fahClient           = new FahClient(MockRepository.GenerateStub <IMessageConnection>())
            {
                BenchmarkService = benchmarkCollection, UnitInfoDatabase = database
            };

            var unitInfo1 = new UnitInfo();

            unitInfo1.OwningClientName = "Owner";
            unitInfo1.OwningClientPath = "Path";
            unitInfo1.OwningSlotId     = 0;
            unitInfo1.ProjectID        = 2669;
            unitInfo1.ProjectRun       = 1;
            unitInfo1.ProjectClone     = 2;
            unitInfo1.ProjectGen       = 3;
            unitInfo1.FinishedTime     = new DateTime(2010, 1, 1);
            unitInfo1.QueueIndex       = 0;
            var currentUnitInfo = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1
            };

            var unitInfo1Clone = unitInfo1.DeepClone();

            unitInfo1Clone.FramesObserved = 4;
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(0), FrameID = 0
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(5), FrameID = 1
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(10), FrameID = 2
            });
            unitInfo1Clone.SetUnitFrame(new UnitFrame {
                TimeOfFrame = TimeSpan.FromMinutes(15), FrameID = 3
            });
            unitInfo1Clone.UnitResult = WorkUnitResult.FinishedUnit;
            var unitInfoLogic1 = new UnitInfoModel {
                CurrentProtein = new Protein(), UnitInfoData = unitInfo1Clone
            };

            var parsedUnits = new[] { unitInfoLogic1 };

            // arrange
            database.Stub(x => x.Connected).Return(true);
            database.Expect(x => x.Insert(null)).IgnoreArguments().Repeat.Times(1);

            var benchmarkClient = new ProteinBenchmarkSlotIdentifier("Owner Slot 00", "Path");

            // assert before act
            Assert.AreEqual(false, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(false, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.IsNull(benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData));

            // act
            fahClient.UpdateBenchmarkData(currentUnitInfo, parsedUnits, 0);

            // assert after act
            Assert.AreEqual(true, benchmarkCollection.Contains(benchmarkClient));
            Assert.AreEqual(true, new List <int>(benchmarkCollection.GetBenchmarkProjects(benchmarkClient)).Contains(2669));
            Assert.AreEqual(TimeSpan.FromMinutes(5), benchmarkCollection.GetBenchmark(currentUnitInfo.UnitInfoData).AverageFrameTime);

            database.VerifyAllExpectations();
        }