Пример #1
0
        public void Test_AddJob()
        {
            User user = new User("Test User", "Test Password");
            _tmDAO.AddUser(user);
            Job job = new Job(user, 100, 5, s => 50);

            _tmDAO.AddJob(job);
        }
Пример #2
0
        public void OwnerLongTest()
        {
            int length = 100;
            string name = "";
            for (int index = 0; index < length; index++)
                name += "a";

            User owner = new User(name, "");
        }
Пример #3
0
        public AClient(string clientName, string password, BenchmarkServiceClient benchmarkService)
        {
            Console.WriteLine(clientName + " started...");

            _user = new User(clientName, password);
            _benchmarkService = benchmarkService;

            _jobs = new Queue<Job>();
            _jobsAdded = 0;
            _jobsDone = 0;
            _random = new Random();
        }
Пример #4
0
        public void CancelJobTest()
        {
            User user = new User("test", "");
            Job job = new Job(user, 100, 1, s => 0);
            _b.SubmitJob(job);

            //If job does anything else than runs or cancels...
            job.JobDone += delegate { Assert.Fail();};
            job.JobFailed += delegate { Assert.Fail(); };
            job.JobTerminated += delegate { Assert.Fail(); };

            _b.CancelJob(job);

            Assert.AreEqual(job.State, JobState.Cancelled);
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the Users EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToUsers(User user)
 {
     base.AddObject("Users", user);
 }
Пример #6
0
 public void OwnerShortTest()
 {
     User owner = new User("a", "");
 }
Пример #7
0
        /// <summary>
        /// Add user to the database
        /// </summary>
        /// <param name="user">The user to add</param>
        public void AddUser(User user)
        {
            Debug.WriteLine("1 - Inside AddUser(); userId: " + user.UserId);
            if (user == null)
                throw new ArgumentNullException("user was null");

            if (user.UserId != 0) return;

            lock (_objectLock)
            {
                _dbContext.Users.AddObject(user);
                Debug.WriteLine("2 - Inside AddUser(); userId: " + user.UserId);
                _dbContext.SaveChanges();
            }
        }
        public ActionResult EditUser(User user)
        {
            ViewBag.Positions = PositionsHandler.PositionsSelectList();
            ViewBag.Roles = rolesHandler.RolesSelectList();

            if (ModelState.IsValid)
            {
                UsersHandler.Update(user);
            }
            return RedirectToAction("Users");
        }
Пример #9
0
        /// <summary>
        /// Get jobs that is owned by the owner
        /// </summary>
        /// <param name="owner">Owner of the jobs</param>
        /// <returns>The jobs that is owned by the owner</returns>
        public IEnumerable<Job> GetJobs(User owner)
        {
            Contract.Requires(owner != null);

            List<Job> list;
            lock (_activityLock)
                list = _jobs.ContainsKey(owner) ? _jobs[owner] : new List<Job>(0);

            return list;
        }
Пример #10
0
        public void StoreJobTest()
        {
            int expectedTime = 100; //Milliseconds
            User owner = new User("test", "");
            Job job = new Job(owner, (uint)expectedTime, 1, s => 0);
            _b.SubmitJob(job);

            IEnumerable<Job> jobs = _b.GetJobs(owner);

            if(!jobs.Contains(job)) Assert.Fail("The job was not stored!");
        }
Пример #11
0
        public void ExecuteAllTest()
        {
            //Also tests StartNextJob()
            uint numbOfJobs = 100;

            //Using the event from this job to see when all jobs are handled
            Job lastJob = null;

            User owner = new User("test", "");
            for (uint index = 0; index < numbOfJobs; index++)
            {
                Job job = new Job(owner, 100, 1, s => 0);
                _b.SubmitJob(job);
                lastJob = job;
            }

            IEnumerable jobs = _b.GetJobs(owner);

            uint counterDone = 0;
            uint counterUndone = 0;

            foreach (Job j in jobs)
                if (JobState.Done == j.State)
                    counterDone++;
                else
                    counterUndone++;

            //No jobs should be done
            Assert.AreEqual((uint)0, counterDone);
            Assert.AreEqual(numbOfJobs, counterUndone);

            _b.ExecuteAll();

            //Will let the test try to finish for 5 second, which should be more than enough!
            int counter = 0;
            while (_b.Status != BSStatus.Ready)
            {
                if (counter++ > 50) Assert.Fail("Benchmark was unable to reach the state: Ready");
                Thread.Sleep(100);
            }

            counterDone = 0;
            counterUndone = 0;

            foreach (Job j in jobs)
                if (j.State == JobState.Done)
                    counterDone++;
                else
                    counterUndone++;

            Assert.AreEqual(numbOfJobs, counterDone);
            Assert.AreEqual((uint)0, counterUndone);
        }
Пример #12
0
 public void GetJobsTest()
 {
     User owner = new User("test", "");
     Job job = new Job(owner, 1000, 1, s => 0);
     _b.SubmitJob(job);
     _b.ExecuteAll();
     IEnumerable<Job> jobs = _b.GetJobs(owner);
     if (!jobs.Contains(job)) Assert.Fail();
 }
Пример #13
0
        public void Test_GetJobsFromUserWithinDays()
        {
            User user = new User("Test User", "Test Password");
            _tmDAO.AddUser(user);

            // Create 10 jobs on different days
            Job job = null;
            List<TimeSpan> timespans = new List<TimeSpan>();
            for (int i = 0; i < 10; i++)
            {
                timespans.Add(new TimeSpan(i, 0, 0, 0));
                job = new Job(user, 100, 5, s => 50);
                job.TimeSubmitted = DateTime.Now.Subtract(timespans[i]);

                _tmDAO.AddJob(job);
                _tmDAO.AddLog(job, DateTime.Now.Subtract(timespans[i]));
            }

            foreach (TimeSpan timespan in timespans)
            {
                IEnumerable<Job> jobs = _tmDAO.GetJobsFromUserInPeriod(user.UserId, DateTime.Now.Subtract(timespan), DateTime.Now);
                Assert.AreEqual(timespan.TotalDays, jobs.Count());
            }
        }
 /// <summary>
 /// Create a new User object.
 /// </summary>
 /// <param name="userName">Initial value of the UserName property.</param>
 /// <param name="password">Initial value of the Password property.</param>
 /// <param name="userId">Initial value of the UserId property.</param>
 public static User CreateUser(global::System.String userName, global::System.String password, global::System.Int32 userId)
 {
     User user = new User();
     user.UserName = userName;
     user.Password = password;
     user.UserId = userId;
     return user;
 }
Пример #15
0
 public void Test_GetJobsFromUserNoExist()
 {
     User user = new User("Test User", "Test Password");
     _tmDAO.AddUser(user);
     IEnumerable<Job> jobs = _tmDAO.GetJobsFromUser(user.UserId);
     Assert.AreEqual(0, jobs.Count());
 }
Пример #16
0
        public void Test_GetJobsFromUserInPeriodOrderedInvalidTimespan()
        {
            DateTime start = new DateTime(2012, 1, 1);
            DateTime end = new DateTime(2013, 1, 1);

            User user = new User("Test user", "test password");
            _tmDAO.AddUser(user);

            try
            {
                _tmDAO.GetJobsFromUserInPeriodOrdered(user.UserId, end, start);
                Assert.Fail("Possible to collect a list from a 'negative' timespan");
            }
            catch (ArgumentException)
            {
                // This is good
            }
        }
Пример #17
0
        public void Test_GetJobsFromUserInPeriodOrdered()
        {
            Benchmark b = new Benchmark();
            DateTime startTime = new DateTime(2020, 1, 1);
            DateTime endTime = new DateTime(2020, 12, 31);
            User user = new User("Test User", "A secret password");

            _tmDAO.AddUser(user);
            int jobQuantity = 30;
            Job job = null;
            for (int index = 1; index <= jobQuantity; index++)
            {
                DateTime t1 = new DateTime(2020, 3, index);

                job = new Job(user, 100, 5, s => 38);
                _tmDAO.AddJob(job);
                _tmDAO.AddLog(job, t1);
                if (index % 2 == 0)
                {
                    job.Process(new String[] { "test" });
                    _tmDAO.AddLog(job, t1.AddHours(1));
                }
            }
            List<Job> jobsRequested = new List<Job>(_tmDAO.GetJobsFromUserInPeriodOrdered(user.UserId, startTime, endTime));

            for (int i = 0; i < jobsRequested.Count - 1; i++)
            {
                if (jobsRequested[i].CompareTo(jobsRequested[i + 1]) == 1)
                {
                    Assert.Fail("The order is no correct. JobId: " + jobsRequested[i] + " was larger than JobId: " + jobsRequested[i + 1]);
                }
            }

            Assert.AreEqual(jobQuantity, jobsRequested.Count);
        }
Пример #18
0
        public void Test_GetJobsFromUser()
        {
            User user = new User("Test User", "Test Password");
            _tmDAO.AddUser(user);
            Job job = new Job(user, 100, 5, s => 50);
            _tmDAO.AddJob(job);

            IEnumerable<Job> jobs = _tmDAO.GetJobsFromUser(user.UserId);
            Assert.AreEqual(1, jobs.Count());
        }
Пример #19
0
 public void Test_AddUser()
 {
     User user = new User("Test user", "test password");
     _tmDAO.AddUser(user);
 }