Exemple #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldIncrementNumberOfProcessorsWhenRunning()
        public virtual void ShouldIncrementNumberOfProcessorsWhenRunning()
        {
            // GIVEN
            TaskExecutor <Void> executor = new DynamicTaskExecutor <Void>(1, 0, 5, _park, this.GetType().Name);
            ControlledTask      task1    = new ControlledTask();
            TestTask            task2    = new TestTask();

            // WHEN
            executor.Submit(task1);
            task1.Latch.waitForAllToStart();
            executor.Submit(task2);
            executor.Processors(1);                 // now at 2
            //noinspection StatementWithEmptyBody
            while (task2.Executed == 0)
            {               // With one additional worker, the second task can execute even if task one is still executing
            }
            task1.Latch.finish();
            //noinspection StatementWithEmptyBody
            while (task1.Executed == 0)
            {               // Busy loop
            }
            executor.Close();

            // THEN
            assertEquals(1, task1.Executed);
            assertEquals(1, task2.Executed);
        }
Exemple #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldDecrementNumberOfProcessorsWhenRunning() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldDecrementNumberOfProcessorsWhenRunning()
        {
            // GIVEN
            TaskExecutor <Void> executor = new DynamicTaskExecutor <Void>(2, 0, 5, _park, this.GetType().Name);
            ControlledTask      task1    = new ControlledTask();
            ControlledTask      task2    = new ControlledTask();
            ControlledTask      task3    = new ControlledTask();
            TestTask            task4    = new TestTask();

            // WHEN
            executor.Submit(task1);
            executor.Submit(task2);
            task1.Latch.waitForAllToStart();
            task2.Latch.waitForAllToStart();
            executor.Submit(task3);
            executor.Submit(task4);
            executor.Processors(-1);                 // it started at 2 ^^^
            task1.Latch.finish();
            task2.Latch.finish();
            task3.Latch.waitForAllToStart();
            Thread.Sleep(200);                 // gosh, a Thread.sleep...
            assertEquals(0, task4.Executed);
            task3.Latch.finish();
            executor.Close();

            // THEN
            assertEquals(1, task1.Executed);
            assertEquals(1, task2.Executed);
            assertEquals(1, task3.Executed);
            assertEquals(1, task4.Executed);
        }
Exemple #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRespectMaxProcessors()
        public virtual void ShouldRespectMaxProcessors()
        {
            // GIVEN
            int maxProcessors = 4;
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final TaskExecutor<Void> executor = new DynamicTaskExecutor<>(1, maxProcessors, 10, PARK, getClass().getSimpleName());
            TaskExecutor <Void> executor = new DynamicTaskExecutor <Void>(1, maxProcessors, 10, _park, this.GetType().Name);

            // WHEN/THEN
            assertEquals(1, executor.Processors(0));
            assertEquals(2, executor.Processors(1));
            assertEquals(4, executor.Processors(3));
            assertEquals(4, executor.Processors(0));
            assertEquals(4, executor.Processors(1));
            assertEquals(3, executor.Processors(-1));
            assertEquals(1, executor.Processors(-2));
            assertEquals(1, executor.Processors(-2));
            assertEquals(1, executor.Processors(0));
            executor.Close();
        }
Exemple #4
0
        public virtual void ShouldCopeWithConcurrentIncrementOfProcessorsAndShutdown()
        {
            // GIVEN
            TaskExecutor <Void> executor = new DynamicTaskExecutor <Void>(1, 2, 2, _park, "test");
            Race race = (new Race()).withRandomStartDelays();

            race.AddContestant(executor.close);
            race.AddContestant(() => executor.Processors(1));

            // WHEN
            race.Go(10, SECONDS);

            // THEN we should be able to do so, there was a recent fix here and before that fix
            // shutdown() would hang, that's why we wait for 10 seconds here to cap it if there's an issue.
        }