Exemple #1
0
 public LeaderRole(
     IRoleCoordinator <TOperation> coordinator,
     ILogger logger,
     IPersistentLog <TOperation> journal,
     IStateMachine <TOperation> stateMachine,
     IRaftPersistentState persistentState,
     IRaftVolatileState volatileState,
     IGrainFactory grainFactory,
     RegisterTimerDelegate registerTimer,
     IServerIdentity identity,
     IMembershipProvider membershipProvider,
     ISettings settings)
 {
     this.coordinator        = coordinator;
     this.logger             = logger;
     this.journal            = journal;
     this.stateMachine       = stateMachine;
     this.persistentState    = persistentState;
     this.volatileState      = volatileState;
     this.grainFactory       = grainFactory;
     this.registerTimer      = registerTimer;
     this.identity           = identity;
     this.membershipProvider = membershipProvider;
     this.settings           = settings;
     this.heartbeatTimeout   = TimeSpan.FromMilliseconds(this.settings.HeartbeatTimeoutMilliseconds);
 }
 public CandidateRole(
     IRoleCoordinator <TOperation> local,
     ILogger logger,
     IPersistentLog <TOperation> journal,
     IRaftPersistentState persistentState,
     IRaftVolatileState volatileState,
     IRandom random,
     IGrainFactory grainFactory,
     RegisterTimerDelegate registerTimer,
     IServerIdentity identity,
     IMembershipProvider membershipProvider,
     ISettings settings)
 {
     this.local              = local;
     this.logger             = logger;
     this.journal            = journal;
     this.persistentState    = persistentState;
     this.volatileState      = volatileState;
     this.random             = random;
     this.grainFactory       = grainFactory;
     this.registerTimer      = registerTimer;
     this.identity           = identity;
     this.membershipProvider = membershipProvider;
     this.settings           = settings;
 }
Exemple #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> >();
        }
        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>>();
        }
 public StaticMembershipProvider(IServerIdentity identity)
 {
     this.identity = identity;
 }
 public StaticMembershipProvider(IServerIdentity identity)
 {
     this.identity = identity;
 }