示例#1
0
        /// <summary>
        /// This test makes sure that the database is able to start after having been stopped during initialization.
        ///
        /// In order to make sure that the server is stopped during startup we create a separate thread that calls stop.
        /// In order to make sure that this thread does not call stop before the startup procedure has started we use a
        /// custom implementation of a PageSwapperFactory, which communicates with the thread that calls stop. We do this
        /// via a static semaphore. </summary>
        /// <exception cref="IOException"> </exception>
        /// <exception cref="InterruptedException"> </exception>

//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToRestartWhenStoppedDuringStartup() throws java.io.IOException, InterruptedException
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToRestartWhenStoppedDuringStartup()
        {
            // Make sure that the semaphore is in a clean state.
            _semaphore.drainPermits();
            // Get a server that uses our custom swapper.
            NeoServer server = GetNeoServer(CUSTOM_SWAPPER);

            try
            {
                AtomicBoolean failure = new AtomicBoolean();
                Thread        serverStoppingThread = ThreadTestUtils.fork(StopServerAfterStartingHasStarted(server, failure));
                server.Start();
                // Wait for the server to stop.
                serverStoppingThread.Join();
                // Check if the server stopped successfully.
                if (failure.get())
                {
                    fail("Server failed to stop.");
                }
                // Verify that we can start the server again.
                server = GetNeoServer(CUSTOM_SWAPPER);
                server.Start();
            }
            finally
            {
                server.Stop();
            }
        }
示例#2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldBeAbleToStartInHAMode() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldBeAbleToStartInHAMode()
        {
            // Given
            int       clusterPort = PortAuthority.allocatePort();
            NeoServer server      = EnterpriseServerBuilder.serverOnRandomPorts().usingDataDir(Folder.Root.AbsolutePath).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(cluster_server.name(), ":" + clusterPort).withProperty(initial_hosts.name(), ":" + clusterPort).persistent().build();

            try
            {
                server.Start();
                server.Database;

                assertThat(server.Database.Graph, @is(instanceOf(typeof(HighlyAvailableGraphDatabase))));

                HTTP.Response haEndpoint = HTTP.GET(GetHaEndpoint(server));
                assertEquals(200, haEndpoint.Status());
                assertThat(haEndpoint.RawContent(), containsString("master"));

                HTTP.Response discovery = HTTP.GET(server.BaseUri().toASCIIString());
                assertEquals(200, discovery.Status());
            }
            finally
            {
                server.Stop();
            }
        }
示例#3
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldShowServerMetrics() throws Throwable
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldShowServerMetrics()
        {
            // Given
            File      metrics = Folder.file("metrics");
            NeoServer server  = EnterpriseServerBuilder.serverOnRandomPorts().usingDataDir(Folder.databaseDir().AbsolutePath).withProperty(MetricsSettings.metricsEnabled.name(), "true").withProperty(MetricsSettings.csvEnabled.name(), "true").withProperty(MetricsSettings.csvPath.name(), metrics.Path).withProperty(MetricsSettings.csvInterval.name(), "100ms").persistent().build();

            try
            {
                // when
                server.Start();

                string host = "http://localhost:" + server.BaseUri().Port + ServerSettings.rest_api_path.DefaultValue + "/transaction/commit";

                for (int i = 0; i < 5; i++)
                {
                    ClientResponse r = Client.create().resource(host).accept(APPLICATION_JSON).type(APPLICATION_JSON).post(typeof(ClientResponse), "{ 'statements': [ { 'statement': 'CREATE ()' } ] }");
                    assertEquals(200, r.Status);
                }

                // then
                AssertMetricsExists(metrics, ServerMetrics.THREAD_JETTY_ALL);
                AssertMetricsExists(metrics, ServerMetrics.THREAD_JETTY_IDLE);
            }
            finally
            {
                server.Stop();
            }
        }
示例#4
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GivenExplicitlyDisabledServerLoggingConfigurationShouldNotLogAccesses()
        {
            // given
            string directoryPrefix = _testName.MethodName;
            File   logDirectory    = _testDirectory.directory(directoryPrefix + "-logdir");

            NeoServer server = serverOnRandomPorts().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), Settings.FALSE).withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.ToString()).withProperty((new BoltConnector("bolt")).listen_address.name(), ":0").usingDataDir(_testDirectory.directory(directoryPrefix + "-dbdir").AbsolutePath).build();

            try
            {
                server.Start();
                FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);

                // when
                string        query    = "?implicitlyDisabled" + RandomString();
                JaxRsResponse response = (new RestRequest()).get(functionalTestHelper.ManagementUri() + query);

                assertThat(response.Status, @is(HttpStatus.SC_OK));
                response.Close();

                // then
                File httpLog = new File(logDirectory, "http.log");
                assertThat(httpLog.exists(), @is(false));
            }
            finally
            {
                server.Stop();
            }
        }
示例#5
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void givenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void GivenExplicitlyEnabledServerLoggingConfigurationShouldLogAccess()
        {
            // given
            string directoryPrefix = _testName.MethodName;
            File   logDirectory    = _testDirectory.directory(directoryPrefix + "-logdir");
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final String query = "?explicitlyEnabled=" + randomString();
            string query = "?explicitlyEnabled=" + RandomString();

            NeoServer server = serverOnRandomPorts().withDefaultDatabaseTuning().persistent().withProperty(ServerSettings.http_logging_enabled.name(), Settings.TRUE).withProperty(GraphDatabaseSettings.logs_directory.name(), logDirectory.AbsolutePath).withProperty((new BoltConnector("bolt")).listen_address.name(), ":0").usingDataDir(_testDirectory.directory(directoryPrefix + "-dbdir").AbsolutePath).build();

            try
            {
                server.Start();

                FunctionalTestHelper functionalTestHelper = new FunctionalTestHelper(server);

                // when
                JaxRsResponse response = (new RestRequest()).get(functionalTestHelper.ManagementUri() + query);
                assertThat(response.Status, @is(HttpStatus.SC_OK));
                response.Close();

                // then
                File httpLog = new File(logDirectory, "http.log");
                assertEventually("request appears in log", FileContentSupplier(httpLog), containsString(query), 5, TimeUnit.SECONDS);
            }
            finally
            {
                server.Stop();
            }
        }
示例#6
0
 private ThreadStart StopServerAfterStartingHasStarted(NeoServer server, AtomicBoolean failure)
 {
     return(() =>
     {
         try
         {
             // Make sure that we have started the startup procedure before calling stop.
             _semaphore.acquire();
             server.Stop();
         }
         catch (Exception)
         {
             failure.set(true);
         }
     });
 }
示例#7
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test public void shouldRequireAuthorizationForHAStatusEndpoints() throws Exception
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
        public virtual void ShouldRequireAuthorizationForHAStatusEndpoints()
        {
            // Given
            int       clusterPort = PortAuthority.allocatePort();
            NeoServer server      = EnterpriseServerBuilder.serverOnRandomPorts().withProperty(GraphDatabaseSettings.auth_enabled.name(), "true").usingDataDir(Folder.Root.AbsolutePath).withProperty(mode.name(), "HA").withProperty(server_id.name(), "1").withProperty(cluster_server.name(), ":" + clusterPort).withProperty(initial_hosts.name(), ":" + clusterPort).persistent().build();

            try
            {
                server.Start();
                server.Database;

                assertThat(server.Database.Graph, @is(instanceOf(typeof(HighlyAvailableGraphDatabase))));

                Client         client = Client.create();
                ClientResponse r      = client.resource(GetHaEndpoint(server)).accept(APPLICATION_JSON).get(typeof(ClientResponse));
                assertEquals(401, r.Status);
            }
            finally
            {
                server.Stop();
            }
        }