Skip to content

Adding system statistics #640

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
public class InternalSummaryCounters implements SummaryCounters
{
public static final InternalSummaryCounters EMPTY_STATS =
new InternalSummaryCounters( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
new InternalSummaryCounters( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
private final int nodesCreated;
private final int nodesDeleted;
private final int relationshipsCreated;
Expand All @@ -35,14 +35,15 @@ public class InternalSummaryCounters implements SummaryCounters
private final int indexesRemoved;
private final int constraintsAdded;
private final int constraintsRemoved;
private final int systemUpdates;

public InternalSummaryCounters(
int nodesCreated, int nodesDeleted,
int relationshipsCreated, int relationshipsDeleted,
int propertiesSet,
int labelsAdded, int labelsRemoved,
int indexesAdded, int indexesRemoved,
int constraintsAdded, int constraintsRemoved )
int constraintsAdded, int constraintsRemoved, int systemUpdates )
{
this.nodesCreated = nodesCreated;
this.nodesDeleted = nodesDeleted;
Expand All @@ -55,6 +56,7 @@ public InternalSummaryCounters(
this.indexesRemoved = indexesRemoved;
this.constraintsAdded = constraintsAdded;
this.constraintsRemoved = constraintsRemoved;
this.systemUpdates = systemUpdates;
}

@Override
Expand Down Expand Up @@ -140,6 +142,18 @@ public int constraintsRemoved()
return constraintsRemoved;
}

@Override
public boolean containsSystemUpdates()
{
return isPositive( systemUpdates );
}

@Override
public int systemUpdates()
{
return systemUpdates;
}

@Override
public boolean equals( Object o )
{
Expand All @@ -164,7 +178,8 @@ public boolean equals( Object o )
&& indexesAdded == that.indexesAdded
&& indexesRemoved == that.indexesRemoved
&& constraintsAdded == that.constraintsAdded
&& constraintsRemoved == that.constraintsRemoved;
&& constraintsRemoved == that.constraintsRemoved
&& systemUpdates == that.systemUpdates;
}

@Override
Expand All @@ -181,6 +196,7 @@ public int hashCode()
result = 31 * result + indexesRemoved;
result = 31 * result + constraintsAdded;
result = 31 * result + constraintsRemoved;
result = 31 * result + systemUpdates;
return result;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,8 @@ private static InternalSummaryCounters extractCounters( Map<String,Value> metada
counterValue( countersValue, "indexes-added" ),
counterValue( countersValue, "indexes-removed" ),
counterValue( countersValue, "constraints-added" ),
counterValue( countersValue, "constraints-removed" )
counterValue( countersValue, "constraints-removed" ),
counterValue( countersValue, "system-updates" )
);
}
return null;
Expand Down
11 changes: 11 additions & 0 deletions driver/src/main/java/org/neo4j/driver/summary/SummaryCounters.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ public interface SummaryCounters
* @return number of constraints removed from the schema.
*/
int constraintsRemoved();

/**
* If the query updated the system graph in any way, this method will return true,
* @return true if the system graph has been updated.
*/
boolean containsSystemUpdates();

/**
* @return the number of system updates performed by this query.
*/
int systemUpdates();
}
39 changes: 37 additions & 2 deletions driver/src/test/java/org/neo4j/driver/integration/SummaryIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@
*/
package org.neo4j.driver.integration;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import java.util.List;
import java.util.concurrent.TimeUnit;

import org.neo4j.driver.Session;
import org.neo4j.driver.StatementResult;
import org.neo4j.driver.Value;
import org.neo4j.driver.Values;
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
import org.neo4j.driver.internal.util.Neo4jFeature;
import org.neo4j.driver.summary.Notification;
import org.neo4j.driver.summary.Plan;
import org.neo4j.driver.summary.ProfiledPlan;
import org.neo4j.driver.summary.ResultSummary;
import org.neo4j.driver.summary.StatementType;
import org.neo4j.driver.util.DatabaseExtension;
import org.neo4j.driver.util.ParallelizableIT;
import org.neo4j.driver.util.SessionExtension;

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
Expand All @@ -44,12 +49,30 @@
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.neo4j.driver.SessionConfig.forDatabase;

@ParallelizableIT
class SummaryIT
{
@RegisterExtension
static final SessionExtension session = new SessionExtension();
static final DatabaseExtension neo4j = new DatabaseExtension();
private Session session;

@BeforeEach
void setup()
{
session = neo4j.driver().session();
}

@AfterEach
void tearDown()
{
if ( session != null && session.isOpen() )
{
session.close();
}
session = null;
}

@Test
void shouldContainBasicMetadata()
Expand Down Expand Up @@ -112,6 +135,18 @@ void shouldContainCorrectStatistics()
.summary().counters().constraintsRemoved(), equalTo( 1 ) );
}

@Test
@EnabledOnNeo4jWith( Neo4jFeature.BOLT_V4 )
void shouldGetSystemUpdates() throws Throwable
{
try ( Session session = neo4j.driver().session( forDatabase( "system" ) ) )
{
StatementResult result = session.run( "CREATE USER foo SET PASSWORD 'bar'" );
assertThat( result.summary().counters().containsUpdates(), equalTo( false ) );
assertThat( result.summary().counters().containsSystemUpdates(), equalTo( true ) );
}
}

@Test
void shouldContainCorrectStatementType()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ void shouldReturnSummary()

ResultSummary summary = new InternalResultSummary( new Statement( "RETURN 42" ),
new InternalServerInfo( BoltServerAddress.LOCAL_DEFAULT, anyServerVersion() ), DEFAULT_DATABASE_INFO, StatementType.SCHEMA_WRITE,
new InternalSummaryCounters( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 ), null, null, emptyList(), 42, 42 );
new InternalSummaryCounters( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0 ),
null, null, emptyList(), 42, 42 );
when( pullAllHandler.summaryAsync() ).thenReturn( completedFuture( summary ) );

AsyncStatementResultCursorImpl cursor = newCursor( pullAllHandler );
Expand Down