Example #1
0
        public UpstreamDatabaseStrategySelector(UpstreamDatabaseSelectionStrategy defaultStrategy, IEnumerable <UpstreamDatabaseSelectionStrategy> otherStrategies, LogProvider logProvider)
        {
            this._log = logProvider.getLog(this.GetType());

            if (otherStrategies != null)
            {
                foreach (UpstreamDatabaseSelectionStrategy otherStrategy in otherStrategies)
                {
                    _strategies.add(otherStrategy);
                }
            }
            _strategies.add(defaultStrategy);
        }
Example #2
0
//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);
        }
Example #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldReturnTheMemberIdFromFirstSuccessfulStrategy() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldReturnTheMemberIdFromFirstSuccessfulStrategy()
        {
            // given
            UpstreamDatabaseSelectionStrategy badOne = mock(typeof(UpstreamDatabaseSelectionStrategy));

            when(badOne.UpstreamDatabase()).thenReturn(null);

            UpstreamDatabaseSelectionStrategy anotherBadOne = mock(typeof(UpstreamDatabaseSelectionStrategy));

            when(anotherBadOne.UpstreamDatabase()).thenReturn(null);

            UpstreamDatabaseSelectionStrategy goodOne = mock(typeof(UpstreamDatabaseSelectionStrategy));
            MemberId theMemberId = new MemberId(System.Guid.randomUUID());

            when(goodOne.UpstreamDatabase()).thenReturn(theMemberId);

            UpstreamDatabaseStrategySelector selector = new UpstreamDatabaseStrategySelector(badOne, iterable(goodOne, anotherBadOne), NullLogProvider.Instance);

            // when
            MemberId result = selector.BestUpstreamDatabase();

            // then
            assertEquals(theMemberId, result);
        }
Example #4
0
 public UpstreamDatabaseStrategySelector(UpstreamDatabaseSelectionStrategy defaultStrategy) : this(defaultStrategy, empty(), NullLogProvider.Instance)
 {
 }