Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(timeout = 10_000) public void shouldProcessAllBatchesOnSingleCoreSystems() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProcessAllBatchesOnSingleCoreSystems()
        {
            // GIVEN
            StageControl control    = mock(typeof(StageControl));
            int          processors = 1;

            int            batches    = 10;
            BatchProcessor step       = new BatchProcessor(control, processors);
            TrackingStep   downstream = new TrackingStep();

            step.Downstream = downstream;

            // WHEN
            step.Start(0);
            for (int i = 1; i <= batches; i++)
            {
                step.Receive(i, new Batch(processors));
            }
            step.EndOfUpstream();
            step.AwaitCompleted();
            step.Close();

            // THEN
            assertEquals(batches, downstream.Received.get());
        }
Пример #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void mustNotDetachProcessorsFromBatchChains() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void MustNotDetachProcessorsFromBatchChains()
        {
            // GIVEN
            StageControl control    = mock(typeof(StageControl));
            int          processors = 1;

            int            batches    = 10;
            BatchProcessor step       = new BatchProcessor(control, processors);
            TrackingStep   downstream = new TrackingStep();

            step.Downstream = downstream;
            int delta = processors - step.Processors(0);

            step.Processors(delta);

            // WHEN
            step.Start(0);
            for (int i = 1; i <= batches; i++)
            {
                step.Receive(i, new Batch(processors));
            }
            step.EndOfUpstream();
            step.AwaitCompleted();
            step.Close();

            // THEN
            assertEquals(batches, downstream.Received.get());
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProcessAllMultiThreadedAndWithChangingProcessorCount() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProcessAllMultiThreadedAndWithChangingProcessorCount()
        {
            // GIVEN
            StageControl   control             = mock(typeof(StageControl));
            int            availableProcessors = Runtime.Runtime.availableProcessors();
            BatchProcessor step       = new BatchProcessor(control, availableProcessors);
            TrackingStep   downstream = new TrackingStep();

            step.Downstream = downstream;

            // WHEN
            step.Start(0);
            AtomicLong nextTicket = new AtomicLong();

            Thread[]      submitters = new Thread[3];
            AtomicBoolean end        = new AtomicBoolean();

            for (int i = 0; i < submitters.Length; i++)
            {
                submitters[i] = new Thread(() =>
                {
                    ThreadLocalRandom random = ThreadLocalRandom.current();
                    while (!end.get())
                    {
                        lock ( nextTicket )
                        {
                            if (random.nextFloat() < 0.1)
                            {
                                step.Processors(random.Next(-2, 4));
                            }
                            long ticket = nextTicket.incrementAndGet();
                            Batch batch = new Batch(step.Processors(0));
                            step.Receive(ticket, batch);
                        }
                    }
                });
                submitters[i].Start();
            }

            while (downstream.Received.get() < 200)
            {
                Thread.Sleep(10);
            }
            end.set(true);
            foreach (Thread submitter in submitters)
            {
                submitter.Join();
            }
            step.EndOfUpstream();
            step.Close();
        }