//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldConnectToCoreOneInTenTimesByDefault() public virtual void ShouldConnectToCoreOneInTenTimesByDefault() { // given MemberId theCoreMemberId = new MemberId(System.Guid.randomUUID()); TopologyService topologyService = fakeTopologyService(fakeCoreTopology(theCoreMemberId), fakeReadReplicaTopology(memberIDs(100))); Config config = mock(typeof(Config)); when(config.Get(CausalClusteringSettings.database)).thenReturn("default"); TypicallyConnectToRandomReadReplicaStrategy connectionStrategy = new TypicallyConnectToRandomReadReplicaStrategy(2); connectionStrategy.Inject(topologyService, config, NullLogProvider.Instance, Myself); IList <MemberId> responses = new List <MemberId>(); // when for (int i = 0; i < 3; i++) { for (int j = 0; j < 2; j++) { responses.Add(connectionStrategy.UpstreamDatabase().get()); } assertThat(responses, hasItem(theCoreMemberId)); responses.Clear(); } // then }
public UpstreamDatabaseStrategiesLoader(TopologyService topologyService, Config config, MemberId myself, LogProvider logProvider) { this._topologyService = topologyService; this._config = config; this._myself = myself; this._log = logProvider.getLog(this.GetType()); this._logProvider = logProvider; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public void init(org.neo4j.causalclustering.discovery.TopologyService topologyService, org.neo4j.causalclustering.core.consensus.LeaderLocator leaderLocator, org.neo4j.logging.LogProvider logProvider, org.neo4j.kernel.configuration.Config config) throws InvalidFilterSpecification public override void Init(TopologyService topologyService, LeaderLocator leaderLocator, LogProvider logProvider, Config config) { this._topologyService = topologyService; this._leaderLocator = leaderLocator; this._timeToLive = config.Get(CausalClusteringSettings.cluster_routing_ttl).toMillis(); this._allowReadsOnFollowers = config.Get(CausalClusteringSettings.cluster_allow_reads_on_followers); this._policies = load(config, PLUGIN_NAME, logProvider.getLog(this.GetType())); }
public GetRoutersForDatabaseProcedure(TopologyService topologyService, Config config) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._topologyService = topologyService; this._timeToLiveMillis = config.Get(CausalClusteringSettings.cluster_routing_ttl).toMillis(); }
internal ReadReplicaStatus(OutputFormat output, ReadReplicaGraphDatabase db) : base(output) { this._output = output; DependencyResolver dependencyResolver = Db.DependencyResolver; this._commandIndexTracker = dependencyResolver.ResolveDependency(typeof(CommandIndexTracker)); this._topologyService = dependencyResolver.ResolveDependency(typeof(TopologyService)); this._dbHealth = dependencyResolver.ResolveDependency(typeof(DatabaseHealth)); }
private Optional <MemberId> RandomCoreMember() { IList <MemberId> coreMembersNotSelf = TopologyService.localCoreServers().members().Keys.Where(not(Myself.equals)).ToList(); Collections.shuffle(coreMembersNotSelf); if (coreMembersNotSelf.Count == 0) { return(null); } return(coreMembersNotSelf[0]); }
internal ReadReplicaStartupProcess(RemoteStore remoteStore, LocalDatabase localDatabase, Lifecycle txPulling, UpstreamDatabaseStrategySelector selectionStrategy, TimeoutStrategy timeoutStrategy, LogProvider debugLogProvider, LogProvider userLogProvider, StoreCopyProcess storeCopyProcess, TopologyService topologyService) { this._remoteStore = remoteStore; this._localDatabase = localDatabase; this._txPulling = txPulling; this._selectionStrategy = selectionStrategy; this._timeoutStrategy = timeoutStrategy; this._debugLog = debugLogProvider.getLog(this.GetType()); this._userLog = userLogProvider.getLog(this.GetType()); this._storeCopyProcess = storeCopyProcess; this._topologyService = topologyService; }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static LoadBalancingProcessor load(org.neo4j.causalclustering.discovery.TopologyService topologyService, org.neo4j.causalclustering.core.consensus.LeaderLocator leaderLocator, org.neo4j.logging.LogProvider logProvider, org.neo4j.kernel.configuration.Config config) throws Throwable public static LoadBalancingProcessor Load( TopologyService topologyService, LeaderLocator leaderLocator, LogProvider logProvider, Config config ) { LoadBalancingPlugin plugin = FindPlugin( config ); plugin.Init( topologyService, leaderLocator, logProvider, config ); if ( config.Get( CausalClusteringSettings.load_balancing_shuffle ) ) { return new ServerShufflingProcessor( plugin ); } return plugin; }
public GetServersProcedureForSingleDC(TopologyService topologyService, LeaderLocator leaderLocator, Config config, LogProvider logProvider) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._topologyService = topologyService; this._leaderLocator = leaderLocator; this._config = config; this._log = logProvider.getLog(this.GetType()); }
// Service loader can't inject via the constructor public virtual void Inject(TopologyService topologyService, Config config, LogProvider logProvider, MemberId myself) { this.TopologyService = topologyService; this.Config = config; this.Log = logProvider.getLog(this.GetType()); this.Myself = myself; this.DbName = config.Get(CausalClusteringSettings.database); ReadableName = StreamSupport.stream(Keys.spliterator(), false).collect(Collectors.joining(", ")); Log.info("Using upstream selection strategy " + ReadableName); Init(); }
public LegacyGetServersProcedure(TopologyService topologyService, LeaderLocator leaderLocator, Config config, LogProvider logProvider) { if (!InstanceFieldsInitialized) { InitializeInstanceFields(); InstanceFieldsInitialized = true; } this._topologyService = topologyService; this._leaderLocator = leaderLocator; this._config = config; this._log = logProvider.getLog(this.GetType()); this._dbName = config.Get(CausalClusteringSettings.database); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptyIfNoGroupsInConfig() public virtual void ShouldReturnEmptyIfNoGroupsInConfig() { // given MemberId[] myGroupMemberIds = memberIDs(10); TopologyService topologyService = GetTopologyService(Collections.singletonList("my_server_group"), myGroupMemberIds, Arrays.asList("x", "y", "z")); ConnectRandomlyToServerGroupImpl strategy = new ConnectRandomlyToServerGroupImpl(Collections.emptyList(), topologyService, null); // when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, empty()); }
internal CoreStatus(OutputFormat output, CoreGraphDatabase db) : base(output) { this._output = output; this._db = db; DependencyResolver dependencyResolver = Db.DependencyResolver; this._raftMembershipManager = dependencyResolver.ResolveDependency(typeof(RaftMembershipManager)); this._databaseHealth = dependencyResolver.ResolveDependency(typeof(DatabaseHealth)); this._topologyService = dependencyResolver.ResolveDependency(typeof(TopologyService)); this._raftMachine = dependencyResolver.ResolveDependency(typeof(RaftMachine)); this._raftMessageTimerResetMonitor = dependencyResolver.ResolveDependency(typeof(DurationSinceLastMessageMonitor)); _commandIndexTracker = dependencyResolver.ResolveDependency(typeof(CommandIndexTracker)); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public java.util.Optional<org.neo4j.causalclustering.identity.MemberId> upstreamDatabase() throws org.neo4j.causalclustering.upstream.UpstreamDatabaseSelectionException public override Optional <MemberId> UpstreamDatabase() { //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final org.neo4j.causalclustering.discovery.CoreTopology coreTopology = topologyService.localCoreServers(); CoreTopology coreTopology = TopologyService.localCoreServers(); if (coreTopology.Members().Count == 0) { throw new UpstreamDatabaseSelectionException("No core servers available"); } int skippedServers = _random.Next(coreTopology.Members().Count); return(coreTopology.Members().Keys.Skip(skippedServers).First()); }
public CatchupPollingProcess(LogProvider logProvider, LocalDatabase localDatabase, Suspendable enableDisableOnSoreCopy, CatchUpClient catchUpClient, UpstreamDatabaseStrategySelector selectionStrategy, TimerService timerService, long txPullIntervalMillis, BatchingTxApplier applier, Monitors monitors, StoreCopyProcess storeCopyProcess, System.Func <DatabaseHealth> databaseHealthSupplier, TopologyService topologyService) { this._localDatabase = localDatabase; this._log = logProvider.getLog(this.GetType()); this._enableDisableOnStoreCopy = enableDisableOnSoreCopy; this._catchUpClient = catchUpClient; this._selectionStrategy = selectionStrategy; this._timerService = timerService; this._txPullIntervalMillis = txPullIntervalMillis; this._applier = applier; this._pullRequestMonitor = monitors.NewMonitor(typeof(PullRequestMonitor)); this._storeCopyProcess = storeCopyProcess; this._databaseHealthSupplier = databaseHealthSupplier; this._topologyService = topologyService; }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptyIfInvalidFilterSpecification() public virtual void ShouldReturnEmptyIfInvalidFilterSpecification() { // given TopologyService topologyService = FakeTopologyService(fakeCoreTopology(new MemberId(System.Guid.randomUUID())), FakeReadReplicaTopology(MemberIDs(100), this.noEastGroupGenerator)); UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy(); Config config = ConfigWithFilter("invalid filter specification"); strategy.Inject(topologyService, config, NullLogProvider.Instance, null); //when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPickTheFirstMatchingServerIfCore() public virtual void ShouldPickTheFirstMatchingServerIfCore() { // given MemberId theCoreMemberId = new MemberId(System.Guid.randomUUID()); TopologyService topologyService = FakeTopologyService(fakeCoreTopology(theCoreMemberId), FakeReadReplicaTopology(MemberIDs(100), this.noEastGroupGenerator)); UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy(); Config config = Config.defaults(CausalClusteringSettings.user_defined_upstream_selection_strategy, "groups(east); groups(core); halt()"); strategy.Inject(topologyService, config, NullLogProvider.Instance, null); //when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, contains(theCoreMemberId)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldSelectAnyFromMultipleServerGroups() public virtual void ShouldSelectAnyFromMultipleServerGroups() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> myServerGroups = java.util.Arrays.asList("a", "b", "c"); IList <string> myServerGroups = Arrays.asList("a", "b", "c"); MemberId[] myGroupMemberIds = memberIDs(10); TopologyService topologyService = GetTopologyService(myServerGroups, myGroupMemberIds, Arrays.asList("x", "y", "z")); ConnectRandomlyToServerGroupImpl strategy = new ConnectRandomlyToServerGroupImpl(myServerGroups, topologyService, myGroupMemberIds[0]); // when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, contains(isIn(myGroupMemberIds))); }
public override Optional <MemberId> UpstreamDatabase() { if (_counter.shouldReturnCoreMemberId()) { return(RandomCoreMember()); } else { // shuffled members IList <MemberId> readReplicaMembers = new List <MemberId>(TopologyService.localReadReplicas().members().Keys); Collections.shuffle(readReplicaMembers); IList <MemberId> coreMembers = new List <MemberId>(TopologyService.localCoreServers().members().Keys); Collections.shuffle(coreMembers); return(Stream.concat(readReplicaMembers.stream(), coreMembers.stream()).filter(not(Myself.equals)).findFirst()); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void onCounterTriggerFiltersSelf() public virtual void OnCounterTriggerFiltersSelf() { // given counter always triggers to get a core member TypicallyConnectToRandomReadReplicaStrategy connectionStrategy = new TypicallyConnectToRandomReadReplicaStrategy(1); // and requesting core member will return self and another member MemberId otherCoreMember = new MemberId(new System.Guid(12, 34)); TopologyService topologyService = fakeTopologyService(fakeCoreTopology(Myself, otherCoreMember), fakeReadReplicaTopology(memberIDs(2))); connectionStrategy.Inject(topologyService, Config.defaults(), NullLogProvider.Instance, Myself); // when Optional <MemberId> found = connectionStrategy.UpstreamDatabase(); // then assertTrue(found.Present); assertNotEquals(Myself, found.get()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldStayWithinGivenSingleServerGroup() public virtual void ShouldStayWithinGivenSingleServerGroup() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> myServerGroup = java.util.Collections.singletonList("my_server_group"); IList <string> myServerGroup = Collections.singletonList("my_server_group"); MemberId[] myGroupMemberIds = memberIDs(10); TopologyService topologyService = GetTopologyService(myServerGroup, myGroupMemberIds, Collections.singletonList("your_server_group")); ConnectRandomlyToServerGroupImpl strategy = new ConnectRandomlyToServerGroupImpl(myServerGroup, topologyService, myGroupMemberIds[0]); // when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, contains(isIn(myGroupMemberIds))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptyIfGroupOnlyContainsSelf() public virtual void ShouldReturnEmptyIfGroupOnlyContainsSelf() { // given //JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final': //ORIGINAL LINE: final java.util.List<String> myServerGroup = java.util.Collections.singletonList("group"); IList <string> myServerGroup = Collections.singletonList("group"); MemberId[] myGroupMemberIds = memberIDs(1); TopologyService topologyService = GetTopologyService(myServerGroup, myGroupMemberIds, Arrays.asList("x", "y", "z")); ConnectRandomlyToServerGroupImpl strategy = new ConnectRandomlyToServerGroupImpl(myServerGroup, topologyService, myGroupMemberIds[0]); // when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnEmptyIfNoMatchingServers() public virtual void ShouldReturnEmptyIfNoMatchingServers() { // given MemberId[] readReplicaIds = MemberIDs(100); TopologyService topologyService = FakeTopologyService(fakeCoreTopology(new MemberId(System.Guid.randomUUID())), FakeReadReplicaTopology(readReplicaIds, this.noEastGroupGenerator)); UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy(); string wantedGroup = _eastGroup; Config config = ConfigWithFilter("groups(" + wantedGroup + "); halt()"); strategy.Inject(topologyService, config, NullLogProvider.Instance, null); //when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, empty()); }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public java.util.Optional<org.neo4j.causalclustering.identity.MemberId> upstreamDatabase() throws org.neo4j.causalclustering.upstream.UpstreamDatabaseSelectionException public override Optional <MemberId> UpstreamDatabase() { IDictionary <MemberId, RoleInfo> memberRoles = TopologyService.allCoreRoles(); if (memberRoles.Count == 0) { throw new UpstreamDatabaseSelectionException("No core servers available"); } foreach (KeyValuePair <MemberId, RoleInfo> entry in memberRoles.SetOfKeyValuePairs()) { RoleInfo role = entry.Value; if (role == RoleInfo.LEADER && !Objects.Equals(Myself, entry.Key)) { return(entry.Key); } } return(null); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldNotReturnSelf() public virtual void ShouldNotReturnSelf() { // given string wantedGroup = _eastGroup; MemberId[] readReplicaIds = MemberIDs(1); TopologyService topologyService = FakeTopologyService(fakeCoreTopology(new MemberId(System.Guid.randomUUID())), FakeReadReplicaTopology(readReplicaIds, memberId => asSet(wantedGroup))); UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy(); Config config = ConfigWithFilter("groups(" + wantedGroup + "); halt()"); strategy.Inject(topologyService, config, NullLogProvider.Instance, readReplicaIds[0]); //when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, empty()); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void randomCoreDoesNotReturnSameCoreTwice() public virtual void RandomCoreDoesNotReturnSameCoreTwice() { // given counter always core member TypicallyConnectToRandomReadReplicaStrategy connectionStrategy = new TypicallyConnectToRandomReadReplicaStrategy(1); // and MemberId firstOther = new MemberId(new System.Guid(12, 34)); MemberId secondOther = new MemberId(new System.Guid(56, 78)); TopologyService topologyService = fakeTopologyService(fakeCoreTopology(Myself, firstOther, secondOther), fakeReadReplicaTopology(memberIDs(2))); connectionStrategy.Inject(topologyService, Config.defaults(), NullLogProvider.Instance, Myself); // when we collect enough results to feel confident of random values IList <MemberId> found = IntStream.range(0, 20).mapToObj(i => connectionStrategy.UpstreamDatabase()).filter(Optional.isPresent).map(Optional.get).collect(Collectors.toList()); // then assertFalse(found.Contains(Myself)); assertTrue(found.Contains(firstOther)); assertTrue(found.Contains(secondOther)); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldDefaultToRandomCoreServerIfNoOtherStrategySpecified() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldDefaultToRandomCoreServerIfNoOtherStrategySpecified() { // given TopologyService topologyService = mock(typeof(TopologyService)); MemberId memberId = new MemberId(System.Guid.randomUUID()); when(topologyService.LocalCoreServers()).thenReturn(new CoreTopology(new ClusterId(System.Guid.randomUUID()), false, MapOf(memberId, mock(typeof(CoreServerInfo))))); ConnectToRandomCoreServerStrategy defaultStrategy = new ConnectToRandomCoreServerStrategy(); defaultStrategy.Inject(topologyService, Config.defaults(), NullLogProvider.Instance, null); UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(defaultStrategy); // when MemberId instance = selector.BestUpstreamDatabase(); // then assertEquals(memberId, instance); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldPickTheFirstMatchingServerIfReadReplica() public virtual void ShouldPickTheFirstMatchingServerIfReadReplica() { // given MemberId[] readReplicaIds = MemberIDs(100); TopologyService topologyService = FakeTopologyService(fakeCoreTopology(new MemberId(System.Guid.randomUUID())), FakeReadReplicaTopology(readReplicaIds, this.noEastGroupGenerator)); UserDefinedConfigurationStrategy strategy = new UserDefinedConfigurationStrategy(); string wantedGroup = _noEastGroup[1]; Config config = ConfigWithFilter("groups(" + wantedGroup + "); halt()"); strategy.Inject(topologyService, config, NullLogProvider.Instance, null); //when Optional <MemberId> memberId = strategy.UpstreamDatabase(); // then assertThat(memberId, contains(isIn(readReplicaIds))); assertThat(memberId.map(this.noEastGroupGenerator), contains(equalTo(asSet(wantedGroup)))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldUseSpecifiedStrategyInPreferenceToDefault() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldUseSpecifiedStrategyInPreferenceToDefault() { // given TopologyService topologyService = mock(typeof(TopologyService)); MemberId memberId = new MemberId(System.Guid.randomUUID()); when(topologyService.LocalCoreServers()).thenReturn(new CoreTopology(new ClusterId(System.Guid.randomUUID()), false, MapOf(memberId, mock(typeof(CoreServerInfo))))); ConnectToRandomCoreServerStrategy shouldNotUse = mock(typeof(ConnectToRandomCoreServerStrategy)); UpstreamDatabaseSelectionStrategy mockStrategy = mock(typeof(UpstreamDatabaseSelectionStrategy)); when(mockStrategy.UpstreamDatabase()).thenReturn((new MemberId(System.Guid.randomUUID()))); UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(shouldNotUse, iterable(mockStrategy), NullLogProvider.Instance); // when selector.BestUpstreamDatabase(); // then verifyZeroInteractions(shouldNotUse); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldConnectToRandomCoreServer() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldConnectToRandomCoreServer() { // given MemberId memberId1 = new MemberId(System.Guid.randomUUID()); MemberId memberId2 = new MemberId(System.Guid.randomUUID()); MemberId memberId3 = new MemberId(System.Guid.randomUUID()); TopologyService topologyService = mock(typeof(TopologyService)); when(topologyService.LocalCoreServers()).thenReturn(FakeCoreTopology(memberId1, memberId2, memberId3)); ConnectToRandomCoreServerStrategy connectionStrategy = new ConnectToRandomCoreServerStrategy(); connectionStrategy.Inject(topologyService, Config.defaults(), NullLogProvider.Instance, null); // when Optional <MemberId> memberId = connectionStrategy.UpstreamDatabase(); // then assertTrue(memberId.Present); assertThat(memberId.get(), anyOf(equalTo(memberId1), equalTo(memberId2), equalTo(memberId3))); }