Esempio n. 1
0
        public void MultiThreadedMemoizedInvocationWithClearing2_Memoizer(
            //[Values(1, 2, 4, 10, 30, 60, 100, 200, 400, 800, 1000, 1200)] int numberOfConcurrentWorkerThreads
            [Values(1, 100)] int numberOfConcurrentWorkerThreads,
            [Values(1, 3)] int iterations
            )
        {
            try
            {
                int NUMBER_OF_ITERATIONS = iterations;

                TwoPhaseExecutionContext twoPhaseExecutionContext1 =
                    this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: numberOfConcurrentWorkerThreads,
                                                                              iterations: NUMBER_OF_ITERATIONS,
                                                                              memoize: true,
                                                                              instrumentation: false);
                Action reallySlowNetworkInvocation1a_cacheClearing =
                    () => this.reallySlowNetworkInvocation1a.RemoveFromCache <string, long, string>("yo", 13);

                //TwoPhaseExecutionContext twoPhaseExecutionContext2 =
                //    reallySlowNetworkInvocation1a_cacheClearing.CreateExecutionContext(threads: 1))

                //twoPhaseExecutionContext1.And(twoPhaseExecutionContext2).TestUsingArguments("yo", 13);
            }
            finally
            {
                // Clean-up: must remove memoized function from registry when doing several test method iterations
                this.reallySlowNetworkInvocation1a.UnMemoize();
                //this.reallySlowNetworkInvocation1d.UnMemoize();
            }
        }
Esempio n. 2
0
        public void MultiThreadedMemoizedInvocation_DifferentInvocations_Conjunction_2(
            //[Values(1, 2, 4, 10, 30, 60, 100, 200, 400, 800, 1000, 1200)] int numberOfConcurrentWorkerThreads
            [Values(1, 20)] int numberOfConcurrentWorkerThreads
            //,[Values(2)] int iterations
            )
        {
            try
            {
                //int NUMBER_OF_ITERATIONS = iterations;

                Interlocked.Exchange(ref reallySlowNetworkInvocation1a_INVOCATION_COUNTER, 0);
                //Interlocked.Exchange(ref reallySlowNetworkInvocation1d_INVOCATION_COUNTER, 0);

                TwoPhaseExecutionContext twoPhaseExecutionContext1 =
                    this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: numberOfConcurrentWorkerThreads,
                                                                              iterations: NUMBER_OF_ITERATIONS,
                                                                              memoize: true,
                                                                              instrumentation: false);

                TwoPhaseExecutionContext twoPhaseExecutionContext2 =
                    this.reallySlowNetworkInvocation1d.CreateExecutionContext(threads: 1,
                                                                              iterations: 100,                // N/A as it is merged into another TwoPhaseExecutionContext
                                                                              concurrent: false,              // Not implemented / N/A only 'concurrent: true is supported so far
                                                                              memoize: false,
                                                                                                              //memoizerClearing: false,
                                                                              functionLatency: default(long), // N/A as it is merged into another TwoPhaseExecutionContext
                                                                              instrumentation: false);

                /*TwoPhaseExecutionContext<string, long, string> mergedTwoPhaseExecutionContext = */
                twoPhaseExecutionContext1.And(twoPhaseExecutionContext2);
                //mergedTwoPhaseExecutionContext.Test();
                //twoPhaseExecutionContext1.Test();

                Assert.That(reallySlowNetworkInvocation1a_INVOCATION_COUNTER, Is.EqualTo(twoPhaseExecutionContext1.GetExpectedFunctionInvocationCountFor(this.reallySlowNetworkInvocation1a)));
                //Assert.That(reallySlowNetworkInvocation1a_INVOCATION_COUNTER, Is.EqualTo(twoPhaseExecutionContext1.ExpectedFunctionInvocationCount));
                ////Assert.That(reallySlowNetworkInvocation1a_INVOCATION_COUNTER, Is.EqualTo(mergedTwoPhaseExecutionContext.ExpectedFunctionInvocationCount));
                ////Assert.That(reallySlowNetworkInvocation1d_INVOCATION_COUNTER, Is.EqualTo(mergedTwoPhaseExecutionContext.ExpectedFunctionInvocationCount));
            }
            finally
            {
                // Clean-up: must remove memoized function from registry when doing several test method iterations
                this.reallySlowNetworkInvocation1a.UnMemoize();
                //this.reallySlowNetworkInvocation1d.UnMemoize();
            }
        }
Esempio n. 3
0
        public void MultiThreadedDirectInvocation()
        {
            // Original test
            //this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: NUMBER_OF_CONCURRENT_TASKS, iterations: NUMBER_OF_ITERATIONS).Test();

            TwoPhaseExecutionContext t =
                this.reallySlowNetworkInvocation1a.CreateExecutionContext(iterations: NUMBER_OF_ITERATIONS,
                                                                          threads: NUMBER_OF_CONCURRENT_TASKS
                                                                          //args: new dynamic[] { "yo", 876876 },
                                                                          //memoize: false,
                                                                          //instrumentation: false
                                                                          //tag: "#1"
                                                                          );

            //TwoPhaseExecutionContext t = this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: NUMBER_OF_CONCURRENT_TASKS,
            //                                                                                     iterations: NUMBER_OF_ITERATIONS);
            t.Execute(/*report:true*/);

            //// Inject expected execution state, and verify execution
            //IDictionary<string, object> results = new Dictionary<string, object>
            //{
            //    { HashHelper.CreateFunctionHash(this.reallySlowNetworkInvocation1a, "yoyo", 1313), "VeryExpensiveMethodResponseForyoyo1313" },
            //    { HashHelper.CreateFunctionHash(this.reallySlowNetworkInvocation1a, "yo", 13), "VeryExpensiveMethodResponseForyo13" }
            //};

            //IDictionary<string, long> functionInvocationCounts = new Dictionary<string, long>
            //{
            //    { HashHelper.CreateFunctionHash(this.reallySlowNetworkInvocation1a), reallySlowNetworkInvocation1a_INVOCATION_COUNTER }
            //};

            t.Verify(//report: true,
                     //listResults: false,
                     //expectedResults: null,
                     //expectedMinimumLatency: 0L,
                     //expectedMaximumLatency: t.NumberOfIterations * NETWORK_RESPONSE_LATENCY_IN_MILLIS + 100
                     //actualFunctionInvocationCounts: functionInvocationCounts // For memoizer testing mostly...
                );
        }
Esempio n. 4
0
        public void EqualTwoPhaseExecutionContextShouldReplaceOneAnotherWhenAddingTogetherContexts()
        {
            TwoPhaseExecutionContext twoPhaseExecutionContext = this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: 1, args: new dynamic[] { "yo", 13 }, memoize: true, instrumentation: true);

            twoPhaseExecutionContext.And(twoPhaseExecutionContext).Having(iterations: 1);
        }
Esempio n. 5
0
        //[Test, ExpectedException(typeof(ArgumentException), ExpectedMessage = "An item with the same key has already been added.", MatchType = MessageMatch.Exact)]
        public void EqualTwoPhaseExecutionContextShouldNotBeAccepted()
        {
            TwoPhaseExecutionContext twoPhaseExecutionContext = this.reallySlowNetworkInvocation1a.CreateExecutionContext(threads: 1, args: new dynamic[] { "yo", 13 }, memoize: true, instrumentation: true);

            twoPhaseExecutionContext.And(twoPhaseExecutionContext).Having(iterations: 1);
        }