示例#1
0
//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);
        }
示例#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);
        }
示例#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);
        }