Esempio n. 1
0
        public override URI BoltURI()
        {
            IList <BoltConnector> connectors = _server.Config.enabledBoltConnectors();

            BoltConnector defaultConnector = null;
            BoltConnector firstConnector   = null;

            foreach (BoltConnector connector in connectors)
            {
                if (DEFAULT_BOLT_CONNECTOR_KEY.Equals(connector.Key()))
                {
                    defaultConnector = connector;
                }
                if (firstConnector == null)
                {
                    firstConnector = connector;
                }
            }

            if (defaultConnector != null)
            {
                // bolt connector with default key is configured, return its address
                return(ConnectorUri("bolt", defaultConnector));
            }
            if (firstConnector != null)
            {
                // some bolt connector is configured, return its address
                return(ConnectorUri("bolt", firstConnector));
            }

            throw new System.InvalidOperationException("Bolt connector is not configured");
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldStillSupportCustomNameForBoltConnector()
        internal virtual void ShouldStillSupportCustomNameForBoltConnector()
        {
            Config config = Config.defaults(stringMap("dbms.connector.random_name_that_will_be_unsupported.type", "BOLT", "dbms.connector.random_name_that_will_be_unsupported.enabled", "true", "dbms.connector.random_name_that_will_be_unsupported.listen_address", ":8000"));

            // when
            BoltConnector boltConnector = config.BoltConnectors()[0];

            // then
            assertEquals(new ListenSocketAddress("127.0.0.1", 8000), config.Get(boltConnector.ListenAddress));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldDeriveBoltListenAddressFromDefaultListenAddressAndSpecifiedPort()
        internal virtual void ShouldDeriveBoltListenAddressFromDefaultListenAddressAndSpecifiedPort()
        {
            // given
            Config config = Config.defaults(stringMap("dbms.connectors.default_listen_address", "0.0.0.0", "dbms.connector.bolt.enabled", "true", "dbms.connector.bolt.listen_address", ":8000"));

            BoltConnector boltConnector = config.BoltConnectors()[0];

            // then
            assertEquals(new ListenSocketAddress("0.0.0.0", 8000), config.Get(boltConnector.ListenAddress));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldBeAbleToOverrideBoltListenAddressesWithJustOneParameter()
        internal virtual void ShouldBeAbleToOverrideBoltListenAddressesWithJustOneParameter()
        {
            // given
            Config config = Config.defaults(stringMap("dbms.connector.bolt.enabled", "true", "dbms.connector.bolt.listen_address", ":8000"));

            BoltConnector boltConnector = config.BoltConnectors()[0];

            // then
            assertEquals(new ListenSocketAddress("127.0.0.1", 8000), config.Get(boltConnector.ListenAddress));
        }
Esempio n. 5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldLookupBoltPortInRegisterIfConfiguredTo0() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldLookupBoltPortInRegisterIfConfiguredTo0()
        {
            BoltConnector         bolt     = new BoltConnector("honestJakesBoltConnector");
            ConnectorPortRegister register = new ConnectorPortRegister();

            register.Register(bolt.Key(), new InetSocketAddress(1337));

            DiscoverableURIs uris = communityDiscoverableURIs(Config.builder().withSetting(bolt.AdvertisedAddress, "apple.com:0").withSetting(bolt.Enabled, "true").withSetting(bolt.Type, BoltConnector.ConnectorType.BOLT.name()).build(), register);

            assertEquals("bolt://apple.com:1337", ToMap(uris)["bolt"]);
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldSupportMultipleBoltConnectorsWithDefaultAndCustomName()
        internal virtual void ShouldSupportMultipleBoltConnectorsWithDefaultAndCustomName()
        {
            Config config = Config.defaults(stringMap("dbms.connector.bolt.type", "BOLT", "dbms.connector.bolt.enabled", "true", "dbms.connector.bolt.listen_address", ":8000", "dbms.connector.bolt2.type", "BOLT", "dbms.connector.bolt2.enabled", "true", "dbms.connector.bolt2.listen_address", ":9000"));

            // when
            BoltConnector boltConnector1 = config.BoltConnectors()[0];
            BoltConnector boltConnector2 = config.BoltConnectors()[1];

            // then
            assertEquals(new ListenSocketAddress("127.0.0.1", 8000), config.Get(boltConnector1.ListenAddress));
            assertEquals(new ListenSocketAddress("127.0.0.1", 9000), config.Get(boltConnector2.ListenAddress));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldEnableBoltByDefault()
        internal virtual void ShouldEnableBoltByDefault()
        {
            // given
            Config config = Config.builder().withServerDefaults().build();

            // when
            BoltConnector       boltConnector       = config.BoltConnectors()[0];
            ListenSocketAddress listenSocketAddress = config.Get(boltConnector.ListenAddress);

            // then
            assertEquals(new ListenSocketAddress("127.0.0.1", 7687), listenSocketAddress);
        }
Esempio n. 8
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldExposeBoltRoutingIfCore() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldExposeBoltRoutingIfCore()
        {
            // Given
            BoltConnector bolt   = new BoltConnector("honestJakesBoltConnector");
            Config        config = Config.builder().withSetting(EnterpriseEditionSettings.mode, EnterpriseEditionSettings.Mode.CORE.name()).withSetting(bolt.Enabled, "true").withSetting(bolt.Type, BoltConnector.ConnectorType.BOLT.name()).build();

            // When
            IDictionary <string, object> asd = ToMap(EnterpriseDiscoverableURIs.EnterpriseDiscoverableURIsConflict(config, new ConnectorPortRegister()));

            // Then
            assertThat(asd["bolt_routing"], equalTo("bolt+routing://localhost:7687"));
        }
Esempio n. 9
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void loadOfflineConfigShouldDisableBolt()
        public virtual void LoadOfflineConfigShouldDisableBolt()
        {
            // given
            BoltConnector defaultBoltConf = new BoltConnector("bolt");
            File          configFile      = ConfigFileBuilder.Builder(Folder.Root).withNameValue(defaultBoltConf.Enabled.name(), Settings.TRUE).build();

            // when
            Config testConf = Config.fromFile(configFile).withHome(Folder.Root).withConnectorsDisabled().build();

            // then
            assertNotNull(testConf);
            assertEquals(false, testConf.Get(defaultBoltConf.Enabled));
            assertEquals(false, testConf.Get((new BoltConnector()).enabled));
        }
Esempio n. 10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.neo4j.server.enterprise.OpenEnterpriseNeoServer startNeoServer(org.neo4j.kernel.impl.factory.GraphDatabaseFacade database) throws java.io.IOException
		 private OpenEnterpriseNeoServer StartNeoServer( GraphDatabaseFacade database )
		 {
			  if ( _neoServer == null )
			  {
					GuardingServerBuilder serverBuilder = new GuardingServerBuilder( this, database );
					BoltConnector boltConnector = new BoltConnector( BOLT_CONNECTOR_KEY );
					serverBuilder.WithProperty( boltConnector.Type.name(), "BOLT" ).withProperty(boltConnector.Enabled.name(), Settings.TRUE).withProperty(boltConnector.EncryptionLevel.name(), BoltConnector.EncryptionLevel.DISABLED.name()).withProperty(GraphDatabaseSettings.auth_enabled.name(), Settings.FALSE);
					serverBuilder.WithProperty( ( new HttpConnector( "http" ) ).listen_address.name(), "localhost:0" );
					_neoServer = serverBuilder.Build();
					CleanupRule.add( _neoServer );
					_neoServer.start();
			  }
			  return _neoServer;
		 }
Esempio n. 11
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldGrabPortFromRegisterIfSetTo0() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldGrabPortFromRegisterIfSetTo0()
        {
            // Given
            BoltConnector         bolt   = new BoltConnector("honestJakesBoltConnector");
            Config                config = Config.builder().withSetting(EnterpriseEditionSettings.mode, EnterpriseEditionSettings.Mode.CORE.name()).withSetting(bolt.Enabled, "true").withSetting(bolt.Type, BoltConnector.ConnectorType.BOLT.name()).withSetting(bolt.ListenAddress, ":0").build();
            ConnectorPortRegister ports  = new ConnectorPortRegister();

            ports.Register(bolt.Key(), new InetSocketAddress(1337));

            // When
            IDictionary <string, object> asd = ToMap(EnterpriseDiscoverableURIs.EnterpriseDiscoverableURIsConflict(config, ports));

            // Then
            assertThat(asd["bolt_routing"], equalTo("bolt+routing://localhost:1337"));
        }
Esempio n. 12
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void groupToScopeSetting()
        internal virtual void GroupToScopeSetting()
        {
            // given
            string hostname = "my_other_host";
            int    port     = 9999;
            string scoping  = "bla";
            IDictionary <string, string> config = stringMap(GraphDatabaseSettings.DefaultAdvertisedAddress.name(), hostname, (new BoltConnector(scoping)).advertised_address.name(), ":" + port);

            // when
            BoltConnector boltConnector = new BoltConnector(scoping);
            Setting <AdvertisedSocketAddress> advertisedAddress       = boltConnector.AdvertisedAddress;
            AdvertisedSocketAddress           advertisedSocketAddress = advertisedAddress.apply(config.get);

            // then
            assertEquals(hostname, advertisedSocketAddress.Hostname);
            assertEquals(port, advertisedSocketAddress.Port);
        }
Esempio n. 13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void start() throws Throwable
        public override void Start()
        {
            bool useEpoll = _useEpoll && Epoll.Available;
            ServerConfigurationProvider configurationProvider = useEpoll ? EpollConfigurationProvider.INSTANCE : NioConfigurationProvider.INSTANCE;

            _bossGroup = configurationProvider.CreateEventLoopGroup(1, _tf);

            // These threads handle live channels. Each thread has a set of channels it is responsible for, and it will
            // continuously run a #select() loop to react to new events on these channels.
            _selectorGroup = configurationProvider.CreateEventLoopGroup(_numSelectorThreads, _tf);

            // Bootstrap the various ports and protocols we want to handle

            foreach (KeyValuePair <BoltConnector, ProtocolInitializer> bootstrapEntry in _bootstrappersMap.SetOfKeyValuePairs())
            {
                try
                {
                    ProtocolInitializer protocolInitializer = bootstrapEntry.Value;
                    BoltConnector       boltConnector       = bootstrapEntry.Key;
                    ServerBootstrap     serverBootstrap     = CreateServerBootstrap(configurationProvider, protocolInitializer);
                    ChannelFuture       channelFuture       = serverBootstrap.bind(protocolInitializer.Address().socketAddress()).sync();
                    InetSocketAddress   localAddress        = ( InetSocketAddress )channelFuture.channel().localAddress();
                    _connectionRegister.register(boltConnector.Key(), localAddress);
                    string host = protocolInitializer.Address().Hostname;
                    int    port = localAddress.Port;
                    if (host.Contains(":"))
                    {
                        // IPv6
                        _log.info("Bolt enabled on [%s]:%s.", host, port);
                    }
                    else
                    {
                        // IPv4
                        _log.info("Bolt enabled on %s:%s.", host, port);
                    }
                }
                catch (Exception e)
                {
                    // We catch throwable here because netty uses clever tricks to have method signatures that look like they do not
                    // throw checked exceptions, but they actually do. The compiler won't let us catch them explicitly because in theory
                    // they shouldn't be possible, so we have to catch Throwable and do our own checks to grab them
                    throw new PortBindException(bootstrapEntry.Value.address(), e);
                }
            }
        }
Esempio n. 14
0
        private NettyServer.ProtocolInitializer CreateProtocolInitializer(BoltConnector connector, BoltProtocolFactory boltProtocolFactory, TransportThrottleGroup throttleGroup, Log log)
        {
            SslContext sslCtx;
            bool       requireEncryption;

            BoltConnector.EncryptionLevel encryptionLevel = _config.get(connector.EncryptionLevel);
            SslPolicyLoader sslPolicyLoader = _dependencyResolver.resolveDependency(typeof(SslPolicyLoader));

            switch (encryptionLevel)
            {
            case BoltConnector.EncryptionLevel.REQUIRED:
                // Encrypted connections are mandatory, a self-signed certificate may be generated.
                requireEncryption = true;
                sslCtx            = CreateSslContext(sslPolicyLoader, _config);
                break;

            case BoltConnector.EncryptionLevel.OPTIONAL:
                // Encrypted connections are optional, a self-signed certificate may be generated.
                requireEncryption = false;
                sslCtx            = CreateSslContext(sslPolicyLoader, _config);
                break;

            case BoltConnector.EncryptionLevel.DISABLED:
                // Encryption is turned off, no self-signed certificate will be generated.
                requireEncryption = false;
                sslCtx            = null;
                break;

            default:
                // In the unlikely event that we happen to fall through to the default option here,
                // there is a mismatch between the BoltConnector.EncryptionLevel enum and the options
                // handled in this switch statement. In this case, we'll log a warning and default to
                // disabling encryption, since this mirrors the functionality introduced in 3.0.
                log.Warn("Unhandled encryption level %s - assuming DISABLED.", encryptionLevel.name());
                requireEncryption = false;
                sslCtx            = null;
                break;
            }

            ListenSocketAddress listenAddress = _config.get(connector.ListenAddress);

            return(new SocketTransport(connector.Key(), listenAddress, sslCtx, requireEncryption, _logService.InternalLogProvider, throttleGroup, boltProtocolFactory, _connectionTracker));
        }
Esempio n. 15
0
        private void Init(File workingDir)
        {
            Directory = workingDir;
            withConfig(auth_enabled, "false");
            withConfig(pagecache_memory, "8m");

            BoltConnector bolt0 = new BoltConnector("bolt");
            HttpConnector http1 = new HttpConnector("http", HttpConnector.Encryption.NONE);
            HttpConnector http2 = new HttpConnector("https", HttpConnector.Encryption.TLS);

            WithConfig(http1.Type, "HTTP");
            withConfig(http1.Encryption, HttpConnector.Encryption.NONE.name());
            WithConfig(http1.Enabled, "true");
            WithConfig(http1.Address, "localhost:0");

            WithConfig(http2.Type, "HTTP");
            withConfig(http2.Encryption, HttpConnector.Encryption.TLS.name());
            WithConfig(http2.Enabled, "false");
            WithConfig(http2.Address, "localhost:0");

            WithConfig(bolt0.Type, "BOLT");
            WithConfig(bolt0.Enabled, "true");
            WithConfig(bolt0.Address, "localhost:0");
        }