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 expiryTimeShouldBeSetToCurrentTimePlusTimeout() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ExpiryTimeShouldBeSetToCurrentTimePlusTimeout()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
            TransactionHandle         handle   = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            // When
            long timesOutAt = registry.Release(id, handle);

            // Then
            assertThat(timesOutAt, equalTo(clock.Millis() + timeoutLength));

            // And when
            clock.Forward(1337, TimeUnit.MILLISECONDS);
            registry.Acquire(id);
            timesOutAt = registry.Release(id, handle);

            // Then
            assertThat(timesOutAt, equalTo(clock.Millis() + timeoutLength));
        }
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 candidateShouldLoseElectionAndRemainCandidate() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CandidateShouldLoseElectionAndRemainCandidate()
        {
            // Note the etcd implementation seems to diverge from the paper here, since the paper suggests that it should
            // remain as a candidate

            // given
            FakeClock    fakeClock = Clocks.fakeClock();
            TimerService timeouts  = new OnDemandTimerService(fakeClock);
            RaftMachine  raft      = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            timeouts.Invoke(RaftMachine.Timeouts.ELECTION);

            // when
            raft.Handle(voteResponse().from(_member1).term(1).deny().build());
            raft.Handle(voteResponse().from(_member2).term(1).deny().build());

            // then
            assertEquals(1, raft.Term());
            assertEquals(CANDIDATE, raft.CurrentRole());

            verify(_outbound, never()).send(eq(_member1), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request)));
            verify(_outbound, never()).send(eq(_member2), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request)));
        }
Esempio n. 3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void acquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void AcquiringATransactionThatHasAlreadyBeenAcquiredShouldThrowInvalidConcurrentTransactionAccess()
        {
            // Given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            registry.Release(id, handle);
            registry.Acquire(id);

            // When
            try
            {
                registry.Acquire(id);
                fail("Should have thrown exception");
            }
            catch (InvalidConcurrentTransactionAccess)
            {
                // expected
            }

            // then
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCacheInFlightEntriesUntilAfterRecovery() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotCacheInFlightEntriesUntilAfterRecovery()
        {
            // given
            FakeClock            fakeClock     = Clocks.fakeClock();
            InFlightCache        inFlightCache = new ConsecutiveInFlightCache(10, 10000, InFlightCacheMonitor.VOID, false);
            OnDemandTimerService timerService  = new OnDemandTimerService(fakeClock);
            RaftMachine          raft          = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).raftLog(_raftLog).inFlightCache(inFlightCache).build();

            _raftLog.append(new RaftLogEntry(0, new MemberIdSet(asSet(_myself, _member1, _member2))));

            // when
            raft.Handle(appendEntriesRequest().from(_member1).prevLogIndex(0).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, _data1)).build());

            // then
            assertEquals(_data1, readLogEntry(_raftLog, 1).content());
            assertNull(inFlightCache.Get(1L));

            // when
            raft.PostRecoveryActions();
            raft.Handle(appendEntriesRequest().from(_member1).prevLogIndex(1).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, _data2)).build());

            // then
            assertEquals(_data2, readLogEntry(_raftLog, 2).content());
            assertEquals(_data2, inFlightCache.Get(2L).content());
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testTimer()
        public virtual void TestTimer()
        {
            // GIVEN
            FakeClock fakeClock = Clocks.fakeClock(10000, TimeUnit.MILLISECONDS);

            // WHEN
            RotationTimerFactory timerFactory = new RotationTimerFactory(fakeClock, 1000);

            RotationTimerFactory.RotationTimer timer        = timerFactory.CreateTimer();
            RotationTimerFactory.RotationTimer anotherTimer = timerFactory.CreateTimer();

            // THEN
            assertFalse(timer.TimedOut);
            assertEquals(0, timer.ElapsedTimeMillis);
            assertNotSame("Factory should construct different timers", timer, anotherTimer);

            // WHEN
            fakeClock = Clocks.fakeClock();
            RotationTimerFactory fakeTimerFactory = new RotationTimerFactory(fakeClock, 1000);

            RotationTimerFactory.RotationTimer fakeTimer = fakeTimerFactory.CreateTimer();
            fakeClock.Forward(1001, TimeUnit.MILLISECONDS);

            assertTrue(fakeTimer.TimedOut);
            assertEquals(1001, fakeTimer.ElapsedTimeMillis);
        }
Esempio n. 6
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void candidateShouldWinElectionAndBecomeLeader() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CandidateShouldWinElectionAndBecomeLeader()
        {
            // given
            FakeClock    fakeClock = Clocks.fakeClock();
            TimerService timeouts  = new OnDemandTimerService(fakeClock);
            RaftMachine  raft      = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            timeouts.Invoke(RaftMachine.Timeouts.ELECTION);

            // when
            raft.Handle(voteResponse().from(_member1).term(1).grant().build());
            raft.Handle(voteResponse().from(_member2).term(1).grant().build());

            // then
            assertEquals(1, raft.Term());
            assertEquals(LEADER, raft.CurrentRole());

            /*
             * We require atLeast here because RaftMachine has its own scheduled service, which can spuriously wake up and
             * send empty entries. These are fine and have no bearing on the correctness of this test, but can cause it
             * fail if we expect exactly 2 of these messages
             */
            verify(_outbound, atLeast(1)).send(eq(_member1), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request)));
            verify(_outbound, atLeast(1)).send(eq(_member2), isA(typeof(Org.Neo4j.causalclustering.core.consensus.RaftMessages_AppendEntries_Request)));
        }
Esempio n. 7
0
 private void InitializeInstanceFields()
 {
     _fileNames  = new FileNames(_bam);
     _readerPool = new ReaderPool(0, Instance, _fileNames, _fsa, Clocks.fakeClock());
     _segments   = new Segments(_fsa, _fileNames, _readerPool, emptyList(), mock(typeof(ChannelMarshal)), NullLogProvider.Instance, -1);
     _fsa.mkdir(_bam);
 }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _customConfig = Config.defaults(GraphDatabaseSettings.lock_acquisition_timeout, "100ms");
            _clock        = Clocks.fakeClock(100000, TimeUnit.MINUTES);
            _lockManager  = Suite.createLockManager(_customConfig, _clock);
            _client       = _lockManager.newClient();
            _client2      = _lockManager.newClient();
        }
Esempio n. 9
0
 public RaftOutbound(CoreTopologyService coreTopologyService, Outbound <AdvertisedSocketAddress, Message> outbound, System.Func <Optional <ClusterId> > clusterIdentity, LogProvider logProvider, long logThresholdMillis)
 {
     this._coreTopologyService = coreTopologyService;
     this._outbound            = outbound;
     this._clusterIdentity     = clusterIdentity;
     this._log = logProvider.getLog(this.GetType());
     this._unknownAddressMonitor = new UnknownAddressMonitor(_log, Clocks.systemClock(), logThresholdMillis);
 }
Esempio n. 10
0
        //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
        //ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            _master = mock( typeof( Master ), new LockedOnMasterAnswer() );
              _lockManager = new ForsetiLockManager( Config.defaults(), Clocks.systemClock(), ResourceTypes.values() );
              _requestContextFactory = mock( typeof( RequestContextFactory ) );
              _databaseAvailabilityGuard = new DatabaseAvailabilityGuard( GraphDatabaseSettings.DEFAULT_DATABASE_NAME, Clocks.systemClock(), mock(typeof(Log)) );

              when( _requestContextFactory.newRequestContext( Mockito.anyInt() ) ).thenReturn(RequestContext.anonymous(1));
        }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createDifferentCommunityLockManagers()
        internal virtual void CreateDifferentCommunityLockManagers()
        {
            CommunityLocksFactory factory = new CommunityLocksFactory();
            Locks locks1 = factory.NewInstance(Config.defaults(), Clocks.systemClock(), ResourceTypes.values());
            Locks locks2 = factory.NewInstance(Config.defaults(), Clocks.systemClock(), ResourceTypes.values());

            assertNotSame(locks1, locks2);
            assertThat(locks1, instanceOf(typeof(CommunityLockManger)));
            assertThat(locks2, instanceOf(typeof(CommunityLockManger)));
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void createLocksForAllResourceTypes()
        internal virtual void CreateLocksForAllResourceTypes()
        {
            LocksFactory lockFactory = mock(typeof(LocksFactory));
            Config       config      = Config.defaults();
            Clock        clock       = Clocks.systemClock();

            createLockManager(lockFactory, config, clock);

            verify(lockFactory).newInstance(eq(config), eq(clock), eq(ResourceTypes.values()));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Before public void setUp()
        public virtual void SetUp()
        {
            Config          = Config.defaults();
            Clock           = Clocks.fakeClock();
            LogPruning      = LogPruning.NO_PRUNING;
            LogProvider     = NullLogProvider.Instance;
            IntervalTx      = Config.get(GraphDatabaseSettings.check_point_interval_tx);
            IntervalTime    = Config.get(GraphDatabaseSettings.check_point_interval_time);
            TriggerConsumer = new LinkedBlockingQueue <string>();
            Triggered       = TriggerConsumer.offer;
            NotTriggered    = s => fail("Should not have triggered: " + s);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void testLogPruneThresholdsByType()
        public virtual void TestLogPruneThresholdsByType()
        {
            FileSystemAbstraction fsa = Mockito.mock(typeof(FileSystemAbstraction));
            Clock clock = Clocks.systemClock();

            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("files", 25), ""), instanceOf(typeof(FileCountThreshold)));
            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("size", 16000), ""), instanceOf(typeof(FileSizeThreshold)));
            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("txs", 4000), ""), instanceOf(typeof(EntryCountThreshold)));
            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("entries", 4000), ""), instanceOf(typeof(EntryCountThreshold)));
            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("hours", 100), ""), instanceOf(typeof(EntryTimespanThreshold)));
            assertThat(getThresholdByType(fsa, clock, new ThresholdConfigValue("days", 100_000), ""), instanceOf(typeof(EntryTimespanThreshold)));
        }
Esempio n. 15
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(expected = org.neo4j.server.rest.transactional.error.InvalidTransactionId.class) public void gettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId() throws org.neo4j.server.rest.transactional.error.TransactionLifecycleException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GettingInterruptHandlerForUnknownIdShouldThrowErrorInvalidTransactionId()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);

            // When
            registry.Terminate(456);
        }
Esempio n. 16
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotAchieveGoalIfBeyondRoundTimeout()
        public virtual void ShouldNotAchieveGoalIfBeyondRoundTimeout()
        {
            FakeClock clock = Clocks.fakeClock();
            StubLog   log   = new StubLog(this);

            log.AppendIndex = 10;
            CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);

            clock.Forward(ROUND_TIMEOUT + 5, TimeUnit.MILLISECONDS);
            catchupGoalTracker.UpdateProgress((new FollowerState()).onSuccessResponse(10));

            assertFalse(catchupGoalTracker.GoalAchieved);
            assertFalse(catchupGoalTracker.Finished);
        }
Esempio n. 17
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGenerateTransactionId()
        public virtual void ShouldGenerateTransactionId()
        {
            // given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            // when
            long id1 = registry.Begin(handle);
            long id2 = registry.Begin(handle);

            // then
            assertNotEquals(id1, id2);
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 18
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldPersistAtSpecifiedLogIndex() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldPersistAtSpecifiedLogIndex()
        {
            // given
            FakeClock            fakeClock    = Clocks.fakeClock();
            OnDemandTimerService timerService = new OnDemandTimerService(fakeClock);
            RaftMachine          raft         = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).raftLog(_raftLog).build();

            _raftLog.append(new RaftLogEntry(0, new MemberIdSet(asSet(_myself, _member1, _member2))));

            // when
            raft.Handle(appendEntriesRequest().from(_member1).prevLogIndex(0).prevLogTerm(0).leaderTerm(0).logEntry(new RaftLogEntry(0, _data1)).build());
            // then
            assertEquals(1, _raftLog.appendIndex());
            assertEquals(_data1, readLogEntry(_raftLog, 1).content());
        }
Esempio n. 19
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private static Authentication createAuthentication(int maxFailedAttempts) throws Exception
        private static Authentication CreateAuthentication(int maxFailedAttempts)
        {
            UserRepository users  = new InMemoryUserRepository();
            PasswordPolicy policy = mock(typeof(PasswordPolicy));

            Config config = Config.defaults(GraphDatabaseSettings.auth_max_failed_attempts, maxFailedAttempts.ToString());

            BasicAuthManager manager        = new BasicAuthManager(users, policy, Clocks.systemClock(), users, config);
            Authentication   authentication = new BasicAuthentication(manager, manager);

            manager.NewUser("bob", UTF8.encode("secret"), true);
            manager.NewUser("mike", UTF8.encode("secret2"), false);

            return(authentication);
        }
Esempio n. 20
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldFailToAchieveGoalDueToCatchupTimeoutExpiringEvenThoughWeDoEventuallyAchieveTarget()
        public virtual void ShouldFailToAchieveGoalDueToCatchupTimeoutExpiringEvenThoughWeDoEventuallyAchieveTarget()
        {
            FakeClock clock = Clocks.fakeClock();
            StubLog   log   = new StubLog(this);

            log.AppendIndex = 10;
            CatchupGoalTracker catchupGoalTracker = new CatchupGoalTracker(log, clock, ROUND_TIMEOUT, CATCHUP_TIMEOUT);

            // when
            clock.Forward(CATCHUP_TIMEOUT + 10, TimeUnit.MILLISECONDS);
            catchupGoalTracker.UpdateProgress((new FollowerState()).onSuccessResponse(10));

            // then
            assertFalse(catchupGoalTracker.GoalAchieved);
            assertTrue(catchupGoalTracker.Finished);
        }
Esempio n. 21
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCheckMultipleMonitors()
        public virtual void ShouldCheckMultipleMonitors()
        {
            // GIVEN
            FakeClock             clock        = Clocks.fakeClock();
            TestableMonitor       first        = new TestableMonitor(clock, 100, MILLISECONDS, "first");
            TestableMonitor       other        = new TestableMonitor(clock, 250, MILLISECONDS, "other");
            MultiExecutionMonitor multiMonitor = new MultiExecutionMonitor(clock, first, other);

            // WHEN/THEN
            clock.Forward(110, MILLISECONDS);
            ExpectCallsToCheck(multiMonitor, first, 1, other, 0);
            clock.Forward(100, MILLISECONDS);
            ExpectCallsToCheck(multiMonitor, first, 2, other, 0);
            clock.Forward(45, MILLISECONDS);
            ExpectCallsToCheck(multiMonitor, first, 2, other, 1);
        }
Esempio n. 22
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void candidateShouldVoteForTheSameCandidateInTheSameTerm() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void CandidateShouldVoteForTheSameCandidateInTheSameTerm()
        {
            // given
            FakeClock    fakeClock = Clocks.fakeClock();
            TimerService timeouts  = new OnDemandTimerService(fakeClock);
            RaftMachine  raft      = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).outbound(_outbound).timerService(timeouts).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));

            // when
            raft.Handle(voteRequest().from(_member1).candidate(_member1).term(1).build());
            raft.Handle(voteRequest().from(_member1).candidate(_member1).term(1).build());

            // then
            verify(_outbound, times(2)).send(_member1, voteResponse().term(1).grant().build());
        }
Esempio n. 23
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldStoreSuspendedTransaction() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldStoreSuspendedTransaction()
        {
            // Given
            AssertableLogProvider     logProvider = new AssertableLogProvider();
            TransactionHandleRegistry registry    = new TransactionHandleRegistry(Clocks.fakeClock(), 0, logProvider);
            TransactionHandle         handle      = mock(typeof(TransactionHandle));

            long id = registry.Begin(handle);

            // When
            registry.Release(id, handle);
            TransactionHandle acquiredHandle = registry.Acquire(id);

            // Then
            assertSame(handle, acquiredHandle);
            logProvider.AssertNoLoggingOccurred();
        }
Esempio n. 24
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotCloseAnyRecentlyActiveChannels()
        public virtual void ShouldNotCloseAnyRecentlyActiveChannels()
        {
            // given
            FakeClock         clock             = Clocks.fakeClock();
            ChannelCloser     channelCloser     = mock(typeof(ChannelCloser));
            IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, _noLogging, clock, THRESHOLD);

            Channel channel = mock(typeof(Channel));

            idleChannelReaper.Add(channel, DummyRequestContext());

            // when
            idleChannelReaper.Run();

            // then
            verifyNoMoreInteractions(channelCloser);
        }
Esempio n. 25
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotBecomeLeaderByVotesFromOldTerm() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotBecomeLeaderByVotesFromOldTerm()
        {
            // Given
            FakeClock            fakeClock    = Clocks.fakeClock();
            OnDemandTimerService timerService = new OnDemandTimerService(fakeClock);
            RaftMachine          raft         = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            timerService.Invoke(ELECTION);
            // When
            raft.Handle(voteResponse().from(_member1).term(0).grant().build());
            raft.Handle(voteResponse().from(_member2).term(0).grant().build());

            // Then
            assertThat(raft.Leader, @is(false));
        }
Esempio n. 26
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldCloseAnyChannelsThatHaveBeenIdleForLongerThanThreshold()
        public virtual void ShouldCloseAnyChannelsThatHaveBeenIdleForLongerThanThreshold()
        {
            // given
            FakeClock         clock             = Clocks.fakeClock();
            ChannelCloser     channelCloser     = mock(typeof(ChannelCloser));
            IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, _noLogging, clock, THRESHOLD);

            Channel channel = mock(typeof(Channel));

            idleChannelReaper.Add(channel, DummyRequestContext());

            // when
            clock.Forward(THRESHOLD + 1, TimeUnit.MILLISECONDS);
            idleChannelReaper.Run();

            // then
            verify(channelCloser).tryToCloseChannel(channel);
        }
Esempio n. 27
0
        /// <summary>
        /// Executes a number of stages simultaneously, letting the given {@code monitor} get insight into the
        /// execution.
        /// </summary>
        /// <param name="monitor"> <seealso cref="ExecutionMonitor"/> to get insight into the execution. </param>
        /// <param name="stage"> <seealso cref="Stage stages"/> to execute. </param>
        public static void SuperviseExecution(ExecutionMonitor monitor, Stage stage)
        {
            ExecutionSupervisor supervisor = new ExecutionSupervisor(Clocks.systemClock(), monitor);
            StageExecution      execution  = null;

            try
            {
                execution = stage.Execute();
                supervisor.Supervise(execution);
            }
            finally
            {
                stage.Close();
                if (execution != null)
                {
                    execution.AssertHealthy();
                }
            }
        }
Esempio n. 28
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldVoteFalseForCandidateInOldTerm() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldVoteFalseForCandidateInOldTerm()
        {
            // Given
            FakeClock                fakeClock    = Clocks.fakeClock();
            OnDemandTimerService     timerService = new OnDemandTimerService(fakeClock);
            OutboundMessageCollector messages     = new OutboundMessageCollector();

            RaftMachine raft = (new RaftMachineBuilder(_myself, 3, RaftTestMemberSetBuilder.INSTANCE)).timerService(timerService).clock(fakeClock).outbound(messages).build();

            raft.InstallCoreState(new RaftCoreState(new MembershipEntry(0, asSet(_myself, _member1, _member2))));
            raft.PostRecoveryActions();

            // When
            raft.Handle(voteRequest().from(_member1).term(-1).candidate(_member1).lastLogIndex(0).lastLogTerm(-1).build());

            // Then
            assertThat(messages.SentTo(_member1).Count, equalTo(1));
            assertThat(messages.SentTo(_member1), hasItem(voteResponse().from(_myself).term(0).deny().build()));
        }
Esempio n. 29
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldProvideInterruptHandlerForActiveTransaction() throws org.neo4j.server.rest.transactional.error.TransactionLifecycleException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldProvideInterruptHandlerForActiveTransaction()
        {
            // Given
            AssertableLogProvider logProvider = new AssertableLogProvider();
            FakeClock             clock       = Clocks.fakeClock();
            int timeoutLength = 123;

            TransactionHandleRegistry registry = new TransactionHandleRegistry(clock, timeoutLength, logProvider);
            TransactionHandle         handle   = mock(typeof(TransactionHandle));

            // Active Tx in Registry
            long id = registry.Begin(handle);

            // When
            registry.Terminate(id);

            // Then
            verify(handle, times(1)).terminate();
            verifyNoMoreInteractions(handle);
        }
Esempio n. 30
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotTryToCloseAChannelThatWasRecentlyActive()
        public virtual void ShouldNotTryToCloseAChannelThatWasRecentlyActive()
        {
            // given
            FakeClock         clock             = Clocks.fakeClock();
            ChannelCloser     channelCloser     = mock(typeof(ChannelCloser));
            IdleChannelReaper idleChannelReaper = new IdleChannelReaper(channelCloser, _noLogging, clock, THRESHOLD);

            Channel        channel = mock(typeof(Channel));
            RequestContext request = DummyRequestContext();

            idleChannelReaper.Add(channel, request);

            // when
            clock.Forward(THRESHOLD + 100, TimeUnit.MILLISECONDS);
            idleChannelReaper.Update(channel);
            idleChannelReaper.Run();

            // then
            verifyNoMoreInteractions(channelCloser);
        }