Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeIdempotent()
        public virtual void ShouldBeIdempotent()
        {
            // given
            EphemeralFileSystemAbstraction fsa = FileSystemRule.get();

            fsa.Mkdir(TestDir.directory());

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

            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);

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

                stateMachine.ApplyCommand(new ReplicatedLockTokenRequest(memberA, 0), 3, r =>
                {
                });

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

                // then
                assertEquals(memberA, stateMachine.CurrentToken().owner());
            }
        }
Esempio n. 2
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());
            }
        }