Beispiel #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void discoveredInstancesShouldBeOnlyOnesWeHaveContactedDirectly() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DiscoveredInstancesShouldBeOnlyOnesWeHaveContactedDirectly()
        {
            // GIVEN
            ClusterContext context = mock(typeof(ClusterContext));

            when(context.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);
            when(context.GetUriForId(Id(2))).thenReturn(Uri(2));

            IList <ConfigurationRequestState> discoveredInstances = new LinkedList <ConfigurationRequestState>();

            when(context.DiscoveredInstances).thenReturn(discoveredInstances);
            when(context.ShouldFilterContactingInstances()).thenReturn(true);

            MessageHolder             outgoing = mock(typeof(MessageHolder));
            ConfigurationRequestState configurationRequestFromTwo = Configuration(2);
            Message <ClusterMessage>  message = to(configurationRequest, Uri(1), configurationRequestFromTwo).setHeader(Message.HEADER_FROM, Uri(2).ToString());

            // WHEN
            // We receive a configuration request from an instance which we haven't contacted
            ClusterState.Discovery.handle(context, message, outgoing);

            // THEN
            // It shouldn't be added to the discovered instances
            assertTrue(discoveredInstances.Count == 0);

            // WHEN
            // It subsequently contacts us
            when(context.HaveWeContactedInstance(configurationRequestFromTwo)).thenReturn(true);
            ClusterState.Discovery.handle(context, message, outgoing);

            // Then
            assertTrue(discoveredInstances.Contains(configurationRequestFromTwo));
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void discoveredInstancesShouldNotFilterByDefault() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void DiscoveredInstancesShouldNotFilterByDefault()
        {
            // GIVEN
            ClusterContext context = mock(typeof(ClusterContext));

            when(context.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);
            when(context.GetUriForId(Id(2))).thenReturn(Uri(2));
            when(context.GetUriForId(Id(3))).thenReturn(Uri(3));

            IList <ConfigurationRequestState> discoveredInstances = new LinkedList <ConfigurationRequestState>();

            when(context.DiscoveredInstances).thenReturn(discoveredInstances);

            MessageHolder             outgoing = mock(typeof(MessageHolder));
            ConfigurationRequestState configurationRequestFromTwo = Configuration(2);
            Message <ClusterMessage>  messageFromTwo = to(configurationRequest, Uri(1), configurationRequestFromTwo).setHeader(Message.HEADER_FROM, Uri(2).ToString());
            ConfigurationRequestState configurationRequestFromThree = Configuration(3);
            Message <ClusterMessage>  messageFromThree = to(configurationRequest, Uri(1), configurationRequestFromThree).setHeader(Message.HEADER_FROM, Uri(3).ToString());

            // WHEN
            // We receive a configuration request from an instance which we haven't contacted
            ClusterState.Discovery.handle(context, messageFromTwo, outgoing);

            // THEN
            // Since the setting is on, it should be added to the list anyway
            assertTrue(discoveredInstances.Contains(configurationRequestFromTwo));

            // WHEN
            // Another contacts us as well
            ClusterState.Discovery.handle(context, messageFromThree, outgoing);

            // Then
            // That should be in as well
            assertTrue(discoveredInstances.Contains(configurationRequestFromTwo));
            assertTrue(discoveredInstances.Contains(configurationRequestFromThree));
        }