Skip to content

Commit

Permalink
Metrics files eventual assertions in ServerMetricsIT
Browse files Browse the repository at this point in the history
  • Loading branch information
MishaDemianenko committed Jul 4, 2018
1 parent 16536b4 commit 26695b5
Showing 1 changed file with 11 additions and 11 deletions.
Expand Up @@ -26,43 +26,43 @@
import com.sun.jersey.api.client.ClientResponse; import com.sun.jersey.api.client.ClientResponse;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TemporaryFolder;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.TimeUnit;


import org.neo4j.metrics.MetricsSettings; import org.neo4j.metrics.MetricsSettings;
import org.neo4j.metrics.source.server.ServerMetrics; import org.neo4j.metrics.source.server.ServerMetrics;
import org.neo4j.server.NeoServer; import org.neo4j.server.NeoServer;
import org.neo4j.server.configuration.ServerSettings; import org.neo4j.server.configuration.ServerSettings;
import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder; import org.neo4j.server.enterprise.helpers.EnterpriseServerBuilder;
import org.neo4j.test.rule.SuppressOutput; import org.neo4j.test.rule.SuppressOutput;
import org.neo4j.test.rule.TestDirectory;


import static javax.ws.rs.core.MediaType.APPLICATION_JSON; import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import static org.neo4j.metrics.MetricsTestHelper.metricsCsv; import static org.neo4j.metrics.MetricsTestHelper.metricsCsv;
import static org.neo4j.metrics.MetricsTestHelper.readLongValue; import static org.neo4j.metrics.MetricsTestHelper.readLongValue;
import static org.neo4j.test.assertion.Assert.assertEventually;


public class ServerMetricsIT public class ServerMetricsIT
{ {
@Rule @Rule
public final TemporaryFolder folder = new TemporaryFolder(); public final TestDirectory folder = TestDirectory.testDirectory();
@Rule @Rule
public final SuppressOutput suppressOutput = SuppressOutput.suppressAll(); public final SuppressOutput suppressOutput = SuppressOutput.suppressAll();


@Test @Test
public void shouldShowServerMetrics() throws Throwable public void shouldShowServerMetrics() throws Throwable
{ {
// Given // Given
String path = folder.getRoot().getAbsolutePath(); File metrics = folder.file( "metrics" );
File metricsPath = new File( path + "/metrics" );
NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts() NeoServer server = EnterpriseServerBuilder.serverOnRandomPorts()
.usingDataDir( path ) .usingDataDir( folder.graphDbDir().getAbsolutePath() )
.withProperty( MetricsSettings.metricsEnabled.name(), "true" ) .withProperty( MetricsSettings.metricsEnabled.name(), "true" )
.withProperty( MetricsSettings.csvEnabled.name(), "true" ) .withProperty( MetricsSettings.csvEnabled.name(), "true" )
.withProperty( MetricsSettings.csvPath.name(), metricsPath.getPath() ) .withProperty( MetricsSettings.csvPath.name(), metrics.getPath() )
.withProperty( MetricsSettings.csvInterval.name(), "100ms" ) .withProperty( MetricsSettings.csvInterval.name(), "100ms" )
.persistent() .persistent()
.build(); .build();
Expand All @@ -82,19 +82,19 @@ public void shouldShowServerMetrics() throws Throwable
} }


// then // then
assertMetricsExists( metricsPath, ServerMetrics.THREAD_JETTY_ALL ); assertMetricsExists( metrics, ServerMetrics.THREAD_JETTY_ALL );
assertMetricsExists( metricsPath, ServerMetrics.THREAD_JETTY_IDLE ); assertMetricsExists( metrics, ServerMetrics.THREAD_JETTY_IDLE );
} }
finally finally
{ {
server.stop(); server.stop();
} }
} }


private void assertMetricsExists( File metricsPath, String meticsName ) throws IOException, InterruptedException private static void assertMetricsExists( File metricsPath, String meticsName ) throws IOException, InterruptedException
{ {
File file = metricsCsv( metricsPath, meticsName ); File file = metricsCsv( metricsPath, meticsName );
long threadCount = readLongValue( file ); long threadCount = readLongValue( file );
assertThat( threadCount, greaterThan( 0L ) ); assertEventually( () -> threadCount, greaterThan( 0L ), 1, TimeUnit.MINUTES );
} }
} }

0 comments on commit 26695b5

Please sign in to comment.