Esempio n. 1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldSetDiscoveryHeaderProperly() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldSetDiscoveryHeaderProperly()
        {
            // 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.JoiningInstances).thenReturn(singletonList(Uri(2)));

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

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

            TrackingMessageHolder outgoing = new TrackingMessageHolder();

            ClusterMessage.ConfigurationTimeoutState timeoutState = new ClusterMessage.ConfigurationTimeoutState(3);
            Message <ClusterMessage> message = @internal(configurationTimeout, timeoutState);
            string discoveryHeader           = "1,2,3";

            when(context.GenerateDiscoveryHeader()).thenReturn(discoveryHeader);

            // 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
            assertEquals(discoveryHeader, outgoing.First().getHeader(DISCOVERED));
        }
Esempio n. 2
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));
        }
Esempio n. 3
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));
        }
Esempio n. 4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldNotDenyJoinToInstanceThatRejoinsBeforeTimingOut() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldNotDenyJoinToInstanceThatRejoinsBeforeTimingOut()
        {
            // GIVEN
            ClusterContext context = mock(typeof(ClusterContext));
            IDictionary <InstanceId, URI> existingMembers = Members(1, 2);

            when(context.IsCurrentlyAlive(Id(2))).thenReturn(true);
            when(context.Members).thenReturn(existingMembers);
            when(context.Configuration).thenReturn(ClusterConfiguration(existingMembers));
            when(context.GetLog(any(typeof(Type)))).thenReturn(NullLog.Instance);
            when(context.GetUriForId(Id(2))).thenReturn(Uri(2));
            TrackingMessageHolder    outgoing = new TrackingMessageHolder();
            Message <ClusterMessage> message  = to(configurationRequest, Uri(1), Configuration(2)).setHeader(Message.HEADER_FROM, Uri(2).ToString());

            // WHEN the join denial actually takes effect (signaled by a join timeout locally)
            ClusterState.Entered.handle(context, message, outgoing);

            // THEN assert that the failure contains the received configuration
//JAVA TO C# CONVERTER WARNING: Java wildcard generics have no direct equivalent in .NET:
//ORIGINAL LINE: org.neo4j.cluster.com.message.Message<? extends org.neo4j.cluster.com.message.MessageType> response = outgoing.single();
            Message <MessageType> response = outgoing.Single();

            assertEquals(ClusterMessage.ConfigurationResponse, response.MessageType);
        }