protected override void SetUp()
        {
            var browser1 = new UserAgent("test", "test 1", 1);
            var browser2 = new UserAgent("test", "test 2", 2);
            var browser3 = new UserAgent("another", "another 1", 3);

            _client1 = browser1.SpawnNewClient(null, null);
            _client2 = browser2.SpawnNewClient(null, null);
            _client3a = browser3.SpawnNewClient(null, null);
            _client3b = browser3.SpawnNewClient(null, null);

            Save(browser1, browser2, browser3, _client1, _client2, _client3a, _client3b);

            WithDbContext(context =>
                              {
                                  _createJobResult =
                                      new CreateJobHandler(context, new UserAgentCache(() => context)).Handle(new CreateJob
                                          {
                                              Name = "job",
                                              SuiteId = "testSuite",
                                              Runs = new[]
                                                  {
                                                      new CreateJob.CreateNewRun {Name = "C", Url = "foo"},
                                                      new CreateJob.CreateNewRun {Name = "A", Url = "foo"},
                                                      new CreateJob.CreateNewRun {Name = "B", Url = "foo"},
                                                      new CreateJob.CreateNewRun {Name = "D", Url = "foo"},
                                                  }
                                          });
                                  context.SaveChanges();
                                  context.All<Client>().Count().ShouldEqual(4);
                              });
        }
Пример #2
0
        public Run GetNext(Client client)
        {
            var userAgentId = client.UserAgentId;

            var run = _cache[userAgentId];

            if (run == null)
            {
                return null;
            }

            var databaseRun = GetRun(run);
            databaseRun.BeginClientRun(client);
            _context.SaveChanges();

            return databaseRun;
        }
Пример #3
0
        public void BeginClientRun(Client client)
        {
            client.Updated = SystemTime.NowThunk();

            if (RunStatus == RunStatusType.NotStarted)
            {
                RunStatus = RunStatusType.Running;
            }

            var clientRun = new ClientRun(client, this);
            clientRun.Start();

            ClientRuns.Add(clientRun);

            RunUserAgent runUserAgent = GetRunUserAgent(client);
            if (runUserAgent != null) runUserAgent.StartOrContinue(client);

            Job.StartOrContinue();
        }
Пример #4
0
 RunUserAgent GetRunUserAgent(Client client)
 {
     return RunUserAgents.SingleOrDefault(rua => Equals(rua.UserAgent, client.UserAgent));
 }
Пример #5
0
 public ClientRun(Client client, Run run)
 {
     Client = client;
     Run = run;
 }
Пример #6
0
        protected override void SetUp()
        {
            StructureMap.Inject(typeof(IEventPublisher), new NoOpEventPublisher());

            var browser1 = new UserAgent("test", "test 1", 1);
            var browser2 = new UserAgent("test", "test 2", 2);
            var browser3 = new UserAgent("another", "another 1", 3);

            _client1 = browser1.SpawnNewClient(null, null);
            _client2 = browser2.SpawnNewClient(null, null);
            _client3 = browser3.SpawnNewClient(null, null);

            Save(browser1, browser2, browser3, _client1, _client2, _client3);

            WithDbContext(context =>
                              {
                                  var userAgentCache = new UserAgentCache(() => context);
                                  var newJobCreator = new CreateJobHandler(context, userAgentCache);
                                  newJobCreator.Handle(new CreateJob
                                      {
                                          Name = "job",
                                          Runs = new[]
                                              {
                                                  new CreateJob.CreateNewRun {Name = "C", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "A", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "B", Url = "foo"},
                                                  new CreateJob.CreateNewRun {Name = "D", Url = "foo"},
                                              }
                                      });
                                  context.SaveChanges();
                                  context.All<Client>().Count().ShouldEqual(3);
                              });

            WithDbContext(context =>
                              {
                                  for (int i = 0; i < 4; i++)
                                  {
                                      foreach (var client in new[]{_client1, _client2, _client3})
                                      {
                                          var nextRunQuery = new NextRunQuery(client.Id);
                                          var handler = GetInstance<NextRunQueryHandler>();
                                          var nextRunResult = handler.Handle(nextRunQuery);

                                          var runCompleted = new CompleteRun {Client_Id = client.Id, Run_id = nextRunResult.id, Total = 1};
                                          GetInstance<CompleteRunHandler>().Handle(runCompleted);
                                      }
                                  }
                              });

            long jobId = 0;

            WithDbContext(context =>
                              {
                                  var job = context.Jobs.Single();
                                  jobId = job.Id;

                                  job.Status.ShouldEqual(JobStatusType.Complete);

                              });

            WithDbContext(context =>
                              {
                                  var resetJob = new ResetJob(jobId);

                                  var resetJobHandler = new ResetJobHandler(context, S<IOutputCacheInvalidator>());

                                  resetJobHandler.Handle(resetJob);
                              });
        }
Пример #7
0
 public void StartOrContinue(Client client)
 {
     ActiveClientId = client.Id;
     RunStatus = RunStatusType.Running;
     Result.InProgress();
 }