Ejemplo 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());
            }
        }
Ejemplo n.º 2
0
        private void CreateDurableState <T>(string name, StateMarshal <T> marshal)
        {
            DurableStateStorage <T> storage = new DurableStateStorage <T>(Fsa.get(), _clusterStateDirectory.get(), name, marshal, 1024, NullLogProvider.Instance);

            //noinspection EmptyTryBlock: Will create initial state.
            using (Lifespan ignored = new Lifespan(storage))
            {
            }
        }
Ejemplo n.º 3
0
        private void DumpState <T1>(string name, StateMarshal <T1> marshal)
        {
            int rotationSize = Config.defaults().get(CausalClusteringSettings.replicated_lock_token_state_size);
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.causalclustering.core.state.storage.DurableStateStorage<?> storage = new org.neo4j.causalclustering.core.state.storage.DurableStateStorage<>(fs, clusterStateDirectory, name, marshal, rotationSize, org.neo4j.logging.NullLogProvider.getInstance());
            DurableStateStorage <object> storage = new DurableStateStorage <object>(_fs, _clusterStateDirectory, name, marshal, rotationSize, NullLogProvider.Instance);

            if (storage.Exists())
            {
                using (Lifespan ignored = new Lifespan(storage))
                {
                    @out.println(name + ": " + storage.InitialState);
                }
            }
        }
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());
            }
        }