public FabricMembershipOracleTests(ITestOutputHelper output)
        {
            this.Output      = output;
            this.siloDetails = new MockSiloDetails
            {
                Name        = Guid.NewGuid().ToString("N"),
                SiloAddress = SiloAddressUtils.NewLocalSiloAddress(SiloAddress.AllocateNewGeneration())
            };

            this.resolver = new MockResolver();
            var globalConfig = new ClusterConfiguration().Globals;

            globalConfig.MaxMultiClusterGateways = 2;
            globalConfig.ClusterId = "MegaGoodCluster";

            this.fabricMembershipOptions = new ServiceFabricMembershipOptions();
            this.unknownSiloMonitor      = new UnknownSiloMonitor(
                new OptionsWrapper <ServiceFabricMembershipOptions>(this.fabricMembershipOptions),
                new TestOutputLogger <UnknownSiloMonitor>(this.Output));
            this.oracle = new FabricMembershipOracle(
                this.siloDetails,
                globalConfig,
                this.resolver,
                new NullLogger <FabricMembershipOracle>(),
                this.unknownSiloMonitor);
        }
Beispiel #2
0
        public FabricMembershipOracleTests(ITestOutputHelper output)
        {
            this.Output      = output;
            this.siloDetails = new MockSiloDetails
            {
                Name        = Guid.NewGuid().ToString("N"),
                SiloAddress = SiloAddressUtils.NewLocalSiloAddress(SiloAddress.AllocateNewGeneration())
            };

            this.resolver = new MockResolver();
            var multiClusterOptions = new MultiClusterOptions
            {
                HasMultiClusterNetwork  = true,
                MaxMultiClusterGateways = 2
            };

            this.fabricClusteringOptions = new ServiceFabricClusteringOptions();
            this.unknownSiloMonitor      = new UnknownSiloMonitor(
                new OptionsWrapper <ServiceFabricClusteringOptions>(this.fabricClusteringOptions),
                new TestOutputLogger <UnknownSiloMonitor>(this.Output));
            this.oracle = new FabricMembershipOracle(
                this.siloDetails,
                this.resolver,
                new NullLogger <FabricMembershipOracle>(),
                this.unknownSiloMonitor,
                Options.Create(multiClusterOptions));
        }
Beispiel #3
0
        public FabricMembershipOracleTests(ITestOutputHelper output)
        {
            this.Output      = output;
            this.siloDetails = new MockSiloDetails
            {
                Name        = Guid.NewGuid().ToString("N"),
                SiloAddress = SiloAddress.NewLocalAddress(SiloAddress.AllocateNewGeneration())
            };

            this.resolver = new MockResolver();
            var globalConfig = new ClusterConfiguration().Globals;

            globalConfig.MaxMultiClusterGateways = 2;
            globalConfig.ClusterId = "MegaGoodCluster";

            this.oracle = new FabricMembershipOracle(
                this.siloDetails,
                globalConfig,
                this.resolver,
                name => new TestOutputLogger(this.Output, name));
        }
Beispiel #4
0
        internal async Task Run_ActivationSched_Test1(TaskScheduler scheduler, bool bounceToThreadPool)
        {
            var grainId = LegacyGrainId.GetGrainId(0, Guid.NewGuid());
            var silo    = new MockSiloDetails
            {
                SiloAddress = SiloAddressUtils.NewLocalSiloAddress(23)
            };
            var grain = NonReentrentStressGrainWithoutState.Create(grainId, new GrainRuntime(Options.Create(new ClusterOptions()), silo, null, null, null, null, null, NullLoggerFactory.Instance));

            await Task.Factory.StartNew(() => grain.OnActivateAsync(), CancellationToken.None, TaskCreationOptions.None, scheduler).Unwrap();

            Task        wrapped     = null;
            var         wrapperDone = new TaskCompletionSource <bool>();
            var         wrappedDone = new TaskCompletionSource <bool>();
            Task <Task> wrapper     = new Task <Task>(() =>
            {
                this.output.WriteLine("#0 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}",
                                      SynchronizationContext.Current, TaskScheduler.Current);

                Task t1 = grain.Test1();

                Action wrappedDoneAction = () => { wrappedDone.SetResult(true); };

                if (bounceToThreadPool)
                {
                    wrapped = t1.ContinueWith(_ => wrappedDoneAction(),
                                              CancellationToken.None,
                                              TaskContinuationOptions.ExecuteSynchronously,
                                              TaskScheduler.Default);
                }
                else
                {
                    wrapped = t1.ContinueWith(_ => wrappedDoneAction());
                }
                wrapperDone.SetResult(true);
                return(wrapped);
            });

            wrapper.Start(scheduler);
            await wrapper;

            var timeoutLimit = TimeSpan.FromSeconds(1);

            try
            {
                await wrapperDone.Task.WithTimeout(timeoutLimit);
            }
            catch (TimeoutException)
            {
                Assert.True(false, "Result did not arrive before timeout " + timeoutLimit);
            }
            bool done = wrapperDone.Task.Result;

            Assert.True(done, "Wrapper Task finished");
            Assert.True(wrapper.IsCompleted, "Wrapper Task completed");

            //done = wrapped.Wait(TimeSpan.FromSeconds(12));
            //Assert.True(done, "Wrapped Task not timeout");
            await wrapped;

            try
            {
                await wrappedDone.Task.WithTimeout(timeoutLimit);
            }
            catch (TimeoutException)
            {
                Assert.True(false, "Result did not arrive before timeout " + timeoutLimit);
            }
            done = wrappedDone.Task.Result;
            Assert.True(done, "Wrapped Task should be finished");
            Assert.True(wrapped.IsCompleted, "Wrapped Task completed");
        }
        internal async Task Run_ActivationSched_Test1(TaskScheduler scheduler, bool bounceToThreadPool)
        {
            var grainId = GrainId.GetGrainId(0, Guid.NewGuid());
            var silo = new MockSiloDetails
            {
                SiloAddress = SiloAddress.NewLocalAddress(23)
            };
            var grain = NonReentrentStressGrainWithoutState.Create(grainId, new GrainRuntime(new GlobalConfiguration(), silo, null, null, null, null, null, null));
            await grain.OnActivateAsync();

            Task wrapped = null;
            var wrapperDone = new TaskCompletionSource<bool>();
            var wrappedDone = new TaskCompletionSource<bool>();
            Task<Task> wrapper = new Task<Task>(() =>
            {
                output.WriteLine("#0 - new Task - SynchronizationContext.Current={0} TaskScheduler.Current={1}",
                    SynchronizationContext.Current, TaskScheduler.Current);

                Task t1 = grain.Test1();

                Action wrappedDoneAction = () => { wrappedDone.SetResult(true); };

                if (bounceToThreadPool)
                {
                    wrapped = t1.ContinueWith(_ => wrappedDoneAction(),
                        CancellationToken.None,
                        TaskContinuationOptions.ExecuteSynchronously,
                        TaskScheduler.Default);
                }
                else
                {
                    wrapped = t1.ContinueWith(_ => wrappedDoneAction());
                }
                wrapperDone.SetResult(true);
                return wrapped;
            });
            wrapper.Start(scheduler);
            await wrapper;
            
            var timeoutLimit = TimeSpan.FromSeconds(1);
            try
            {
                await wrapperDone.Task.WithTimeout(timeoutLimit);
            }
            catch (TimeoutException)
            {
                Assert.True(false, "Result did not arrive before timeout " + timeoutLimit);
            }
            bool done = wrapperDone.Task.Result;

            Assert.True(done, "Wrapper Task finished");
            Assert.True(wrapper.IsCompleted, "Wrapper Task completed");

            //done = wrapped.Wait(TimeSpan.FromSeconds(12));
            //Assert.True(done, "Wrapped Task not timeout");
            await wrapped;
            try
            {
                await wrappedDone.Task.WithTimeout(timeoutLimit);
            }
            catch (TimeoutException)
            {
                Assert.True(false, "Result did not arrive before timeout " + timeoutLimit);
            }
            done = wrappedDone.Task.Result;
            Assert.True(done, "Wrapped Task should be finished");
            Assert.True(wrapped.IsCompleted, "Wrapped Task completed");
        }