Ejemplo n.º 1
0
 public virtual void InstallSnapshot(ReplicatedLockTokenState snapshot)
 {
     lock (this)
     {
         _state = snapshot;
     }
 }
Ejemplo n.º 2
0
 private ReplicatedLockTokenState State()
 {
     if (_state == null)
     {
         _state = _storage.InitialState;
     }
     return(_state);
 }
Ejemplo n.º 3
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }
            ReplicatedLockTokenState that = ( ReplicatedLockTokenState )o;

            return(_ordinal == that._ordinal && Objects.Equals(_currentToken, that._currentToken));
        }
Ejemplo n.º 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPersistAndRecoverState() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPersistAndRecoverState()
        {
            // given
            EphemeralFileSystemAbstraction fsa = FileSystemRule.get();

            fsa.Mkdir(TestDir.directory());

            StateMarshal <ReplicatedLockTokenState> marshal = new ReplicatedLockTokenState.Marshal(new MemberId.Marshal());

            MemberId memberA = member(0);
            MemberId memberB = member(1);
            int      candidateId;

            DurableStateStorage <ReplicatedLockTokenState> storage = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance);

            using (Lifespan lifespan = new Lifespan(storage))
            {
                ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);

                // when
                candidateId = 0;
                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, candidateId), 0, r =>
                {
                });
                candidateId = 1;
                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberB, candidateId), 1, r =>
                {
                });

                stateMachine.Flush();
                fsa.Crash();
            }

            // then
            DurableStateStorage <ReplicatedLockTokenState> storage2 = new DurableStateStorage <ReplicatedLockTokenState>(fsa, TestDir.directory(), "state", marshal, 100, NullLogProvider.Instance);

            using (Lifespan lifespan = new Lifespan(storage2))
            {
                ReplicatedLockTokenState initialState = storage2.InitialState;

                assertEquals(memberB, initialState.Get().owner());
                assertEquals(candidateId, initialState.Get().id());
            }
        }
Ejemplo n.º 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetInitialPendingRequestToInitialState()
        public virtual void ShouldSetInitialPendingRequestToInitialState()
        {
            // Given
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") org.neo4j.causalclustering.core.state.storage.StateStorage<ReplicatedLockTokenState> storage = mock(org.neo4j.causalclustering.core.state.storage.StateStorage.class);
            StateStorage <ReplicatedLockTokenState> storage = mock(typeof(StateStorage));
            MemberId initialHoldingCoreMember     = member(0);
            ReplicatedLockTokenState initialState = new ReplicatedLockTokenState(123, new ReplicatedLockTokenRequest(initialHoldingCoreMember, 3));

            when(storage.InitialState).thenReturn(initialState);

            // When
            ReplicatedLockTokenStateMachine stateMachine = new ReplicatedLockTokenStateMachine(storage);

            // Then
            LockToken initialToken = stateMachine.CurrentToken();

            assertEquals(initialState.Get().owner(), initialToken.Owner());
            assertEquals(initialState.Get().id(), initialToken.Id());
        }