Пример #1
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void switchToMasterShouldIgnoreWildcardInConfig() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SwitchToMasterShouldIgnoreWildcardInConfig()
        {
            // SwitchToMaster is used to advertise to the rest of the cluster and advertising 0.0.0.0 makes no sense

            // given
            Config config = Config.defaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), "0.0.0.0:6001"));
            URI    me     = new URI("ha://127.0.0.1");

            MasterServer masterServer = mock(typeof(MasterServer));

            // when
            when(masterServer.SocketAddress).thenReturn(new InetSocketAddress("192.168.1.1", 6001));

            URI result = SwitchToMaster.GetMasterUri(me, masterServer, config);

            // then
            assertEquals("Wrong address", "ha://192.168.1.1:6001?serverId=1", result.ToString());

            // when masterServer is 0.0.0.0
            when(masterServer.SocketAddress).thenReturn(new InetSocketAddress(6001));

            result = SwitchToMaster.GetMasterUri(me, masterServer, config);

            // then
            assertEquals("Wrong address", "ha://127.0.0.1:6001?serverId=1", result.ToString());
        }
Пример #2
0
        internal static URI GetMasterUri(URI me, MasterServer masterServer, Config config)
        {
            string            hostname            = config.Get(HaSettings.ha_server).Host;
            InetSocketAddress masterSocketAddress = masterServer.SocketAddress;

            if (string.ReferenceEquals(hostname, null) || IsWildcard(hostname))
            {
                InetAddress masterAddress = masterSocketAddress.Address;
                hostname = masterAddress.AnyLocalAddress ? me.Host : ServerUtil.getHostString(masterSocketAddress);
                hostname = EnsureWrapForIPv6Uri(hostname);
            }

            return(URI.create("ha://" + hostname + ":" + masterSocketAddress.Port + "?serverId=" + MyId(config)));
        }
Пример #3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void switchToMasterShouldUseIPv6ConfigSettingIfSuitable() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SwitchToMasterShouldUseIPv6ConfigSettingIfSuitable()
        {
            // given
            Config config = Config.defaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), "[fe80::1]:6001"));
            URI    me     = new URI("ha://[::1]");

            MasterServer masterServer = mock(typeof(MasterServer));

            // when
            when(masterServer.SocketAddress).thenReturn(new InetSocketAddress("[fe80::1]", 6001));

            URI result = SwitchToMaster.GetMasterUri(me, masterServer, config);

            // then
            assertEquals("Wrong address", "ha://[fe80::1]:6001?serverId=1", result.ToString());
        }
Пример #4
0
        /// <summary>
        /// Performs a switch to the master state. Starts communication endpoints, switches components to the master state
        /// and broadcasts the appropriate Master Is Available event. </summary>
        /// <param name="haCommunicationLife"> The LifeSupport instance to register communication endpoints. </param>
        /// <param name="me"> The URI that the communication endpoints should bind to </param>
        /// <returns> The URI at which the master communication was bound. </returns>
//JAVA TO C# CONVERTER NOTE: Members cannot have the same name as their enclosing type:
        public virtual URI SwitchToMasterConflict(LifeSupport haCommunicationLife, URI me)
        {
            _userLog.info("I am %s, moving to master", MyId(_config));

            // Do not wait for currently active transactions to complete before continuing switching.
            // - A master in a cluster is very important, without it the cluster cannot process any write requests
            // - Awaiting open transactions to complete assumes that this instance just now was a slave that is
            //   switching to master, which means the previous master where these active transactions were hosted
            //   is no longer available so these open transactions cannot continue and complete anyway,
            //   so what's the point waiting for them?
            // - Read transactions may still be able to complete, but the correct response to failures in those
            //   is to have them throw transient error exceptions hinting that they should be retried,
            //   at which point they may get redirected to another instance, or to this instance if it has completed
            //   the switch until then.

            _idGeneratorFactory.switchToMaster();
            NeoStoreDataSource dataSource = _dataSourceSupplier.get();

            dataSource.AfterModeSwitch();

            Locks locks = dataSource.DependencyResolver.resolveDependency(typeof(Locks));
            ConversationManager conversationManager = ConversationManagerFactory.apply(locks);
            Master master = MasterFactory.apply(conversationManager, haCommunicationLife);

            MasterServer masterServer = MasterServerFactory.apply(master, conversationManager);

            haCommunicationLife.Add(masterServer);
            _masterDelegateHandler.Delegate = master;

            haCommunicationLife.Start();

            URI masterHaURI = GetMasterUri(me, masterServer, _config);

            _clusterMemberAvailability.memberIsAvailable(MASTER, masterHaURI, dataSource.StoreId);
            _userLog.info("I am %s, successfully moved to master", MyId(_config));

            _slaveFactorySupplier.get().StoreId = dataSource.StoreId;

            return(masterHaURI);
        }
Пример #5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void switchToMasterShouldHandleNoIpInConfig() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void SwitchToMasterShouldHandleNoIpInConfig()
        {
            Config config = Config.defaults(stringMap(ClusterSettings.server_id.name(), "1", HaSettings.ha_server.name(), ":6001"));

            MasterServer masterServer = mock(typeof(MasterServer));
            URI          me           = new URI("ha://127.0.0.1");

            // when
            when(masterServer.SocketAddress).thenReturn(new InetSocketAddress("192.168.1.1", 6001));

            URI result = SwitchToMaster.GetMasterUri(me, masterServer, config);

            // then
            assertEquals("Wrong address", "ha://192.168.1.1:6001?serverId=1", result.ToString());

            // when masterServer is 0.0.0.0
            when(masterServer.SocketAddress).thenReturn(new InetSocketAddress(6001));

            result = SwitchToMaster.GetMasterUri(me, masterServer, config);

            // then
            assertEquals("Wrong address", "ha://127.0.0.1:6001?serverId=1", result.ToString());
        }