public static void ThrowIfDisposedOrDisposing(VolatileState state, string valueName)
 {
     if (state.IsDisposedOrDisposing)
     {
         ThrowObjectDisposedException(valueName);
     }
 }
示例#2
0
        public FollowerRoleTests(ITestOutputHelper output)
        {
            var builder = new AutoSubstitute();

            builder.Provide <ILogger>(new TestLogger(output));

            this.volatileState = new VolatileState();
            builder.Provide <IRaftVolatileState>(this.volatileState);

            // Configure settings
            this.settings = builder.Resolve <ISettings>();
            this.settings.ApplyEntriesOnFollowers.Returns(true);
            this.settings.MinElectionTimeoutMilliseconds.Returns(MinElectionTime);
            this.settings.MaxElectionTimeoutMilliseconds.Returns(MaxElectionTime);

            // Rig random number generator to always return the same value.
            this.random = builder.Resolve <IRandom>();
            this.random.Next(Arg.Any <int>(), Arg.Any <int>()).Returns(RiggedRandomResult);

            this.coordinator  = builder.Resolve <IRoleCoordinator <int> >();
            this.stateMachine = builder.Resolve <IStateMachine <int> >();

            this.timers = new MockTimers();
            builder.Provide <RegisterTimerDelegate>(this.timers.RegisterTimer);

            this.persistentState = Substitute.ForPartsOf <InMemoryPersistentState>();
            builder.Provide <IRaftPersistentState>(this.persistentState);

            this.journal = Substitute.ForPartsOf <InMemoryLog <int> >();
            builder.Provide <IPersistentLog <int> >(this.journal);

            // After the container is configured, resolve required services.
            this.role = builder.Resolve <FollowerRole <int> >();
        }
示例#3
0
        public LeaderRoleTests(ITestOutputHelper output)
        {
            var builder =
                new AutoSubstitute(cb => cb.Register(_ => Substitute.For <IRaftGrain <int> >()).InstancePerDependency());

            builder.Provide <ILogger>(new TestLogger(output));

            this.volatileState = new VolatileState();
            builder.Provide <IRaftVolatileState>(this.volatileState);

            this.coordinator = builder.Resolve <IRoleCoordinator <int> >();
            this.coordinator.StepDownIfGreaterTerm(Arg.Any <IMessage>())
            .Returns(
                info => Task.FromResult(((IMessage)info[0]).Term > this.persistentState.CurrentTerm));
            var currentRole = builder.Resolve <IRaftRole <int> >();

            currentRole.RequestVote(Arg.Any <RequestVoteRequest>())
            .Returns(Task.FromResult(new RequestVoteResponse {
                Term = 1, VoteGranted = true
            }));
            currentRole.Append(Arg.Any <AppendRequest <int> >())
            .Returns(Task.FromResult(new AppendResponse {
                Term = 1, Success = true
            }));
            this.coordinator.Role.Returns(currentRole);

            this.timers = new MockTimers();
            builder.Provide <RegisterTimerDelegate>(this.timers.RegisterTimer);

            this.persistentState = Substitute.ForPartsOf <InMemoryPersistentState>();
            builder.Provide <IRaftPersistentState>(this.persistentState);

            this.journal = Substitute.ForPartsOf <InMemoryLog <int> >();
            builder.Provide <IPersistentLog <int> >(this.journal);

            this.identity = Substitute.For <IServerIdentity>();
            this.identity.Id.Returns(Guid.NewGuid().ToString());
            builder.Provide(this.identity);

            this.members = builder.Resolve <StaticMembershipProvider>();
            this.members.SetServers(new[] { this.identity.Id, "other1", "other2", "other3", "other4" });
            builder.Provide <IMembershipProvider>(this.members);

            this.grainFactory = new FakeGrainFactory(builder.Container);
            builder.Provide <IGrainFactory>(this.grainFactory);
            this.OnRaftGrainCreated =
                (id, grain) =>
                grain.RequestVote(Arg.Any <RequestVoteRequest>())
                .Returns(Task.FromResult(new RequestVoteResponse {
                VoteGranted = true
            }));

            // After the container is configured, resolve required services.
            this.role = builder.Resolve <LeaderRole <int> >();
        }
示例#4
0
        // Constructors
        public UiActiveSession(IUiElement element)
            : base(element)
        {
            this.chart = new VolatileState <UiChart>(
                () => new UiChart(base.Find(By.ClassName(UiChart.ClassName))));

            this.devTimeBar = new VolatileState <UiDevTimeBar>(
                () => new UiDevTimeBar(base.Find(By.ClassName(UiDevTimeBar.ClassName))));

            this.taskSelector = new VolatileState <UiComboBox>(
                () => new UiComboBox(base.Find("TaskListView")));
        }
示例#5
0
        // Constructors
        public UiDevTimeBar(IUiElement element)
            : base(element)
        {
            this.fastForwardButton = new VolatileState <UiElement>(
                () => new UiElement(base.Find("FastForwardButton")));

            this.jumpAmountButtonTextBox = new VolatileState <UiElement>(
                () => new UiElement(base.Find("JumpAmountTextBox")));

            this.removeLastIntervalButton = new VolatileState <UiElement>(
                () => new UiElement(base.Find("RemoveLastIntervalButton")));

            this.rewindButton = new VolatileState <UiElement>(
                () => new UiElement(base.Find("RewindButton")));
        }
示例#6
0
        // Constructors
        public UiApp(IUiSession uiSession)
        {
            this.externalUiSession = uiSession;

            this.activeSession = new VolatileState <UiActiveSession>(
                () =>
            {
                this.Navigate(UiNavigation.Content.ActiveSession);
                return(new UiActiveSession(this.externalUiSession.Find(By.ClassName(UiActiveSession.ClassName))));
            });

            this.settings = new VolatileState <UiSettings>(
                () =>
            {
                this.Navigate(UiNavigation.Content.Settings);
                return(new UiSettings(this.externalUiSession.Find(By.ClassName(UiSettings.ClassName))));
            });
        }
示例#7
0
    public static void AssertNotDisposedOrDisposingTest()
    {
        var state = new VolatileState();

        Assert.That(() => AssertionUtilities.AssertNotDisposedOrDisposing(state),
                    Throws.Nothing
                    );

        _ = state.BeginDispose();

        Assert.That(() => AssertionUtilities.AssertNotDisposedOrDisposing(state),
                    Configuration.AssertionsEnabled ? Throws.Exception : Throws.Nothing
                    );

        state.EndDispose();

        Assert.That(() => AssertionUtilities.AssertNotDisposedOrDisposing(state),
                    Configuration.AssertionsEnabled ? Throws.Exception : Throws.Nothing
                    );
    }
示例#8
0
 public static void AssertNotDisposedOrDisposing(VolatileState state)
 => Assert(AssertionsEnabled && state.IsNotDisposedOrDisposing);
示例#9
0
 public static void AssertDisposing(VolatileState state)
 => Assert(AssertionsEnabled && (state == VolatileState.Disposing));
示例#10
0
 public VolatileEntry(object owner)
     : base(owner)
 {
     RuntimeState = VolatileState.None;
 }