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 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
        }
Ejemplo n.º 2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void filtersSelf()
        public virtual void FiltersSelf()
        {
            // given
            string groupName = "groupName";
            Config config    = Config.defaults();

            TypicallyConnectToRandomReadReplicaStrategy typicallyConnectToRandomReadReplicaStrategy = new TypicallyConnectToRandomReadReplicaStrategy();

            typicallyConnectToRandomReadReplicaStrategy.Inject(new TopologyServiceThatPrioritisesItself(Myself, groupName), config, NullLogProvider.Instance, Myself);

            // when
            Optional <MemberId> found = typicallyConnectToRandomReadReplicaStrategy.UpstreamDatabase();

            // then
            assertTrue(found.Present);
            assertNotEquals(Myself, found);
        }
Ejemplo n.º 3
0
//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());
        }
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 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));
        }