Skip to content

Commit d4a0493

Browse files
author
Zhen Li
committed
Adding system statistics
1 parent cb994df commit d4a0493

File tree

5 files changed

+71
-7
lines changed

5 files changed

+71
-7
lines changed

driver/src/main/java/org/neo4j/driver/internal/summary/InternalSummaryCounters.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
public class InternalSummaryCounters implements SummaryCounters
2424
{
2525
public static final InternalSummaryCounters EMPTY_STATS =
26-
new InternalSummaryCounters( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
26+
new InternalSummaryCounters( 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 );
2727
private final int nodesCreated;
2828
private final int nodesDeleted;
2929
private final int relationshipsCreated;
@@ -35,14 +35,15 @@ public class InternalSummaryCounters implements SummaryCounters
3535
private final int indexesRemoved;
3636
private final int constraintsAdded;
3737
private final int constraintsRemoved;
38+
private final int systemUpdates;
3839

3940
public InternalSummaryCounters(
4041
int nodesCreated, int nodesDeleted,
4142
int relationshipsCreated, int relationshipsDeleted,
4243
int propertiesSet,
4344
int labelsAdded, int labelsRemoved,
4445
int indexesAdded, int indexesRemoved,
45-
int constraintsAdded, int constraintsRemoved )
46+
int constraintsAdded, int constraintsRemoved, int systemUpdates )
4647
{
4748
this.nodesCreated = nodesCreated;
4849
this.nodesDeleted = nodesDeleted;
@@ -55,6 +56,7 @@ public InternalSummaryCounters(
5556
this.indexesRemoved = indexesRemoved;
5657
this.constraintsAdded = constraintsAdded;
5758
this.constraintsRemoved = constraintsRemoved;
59+
this.systemUpdates = systemUpdates;
5860
}
5961

6062
@Override
@@ -140,6 +142,18 @@ public int constraintsRemoved()
140142
return constraintsRemoved;
141143
}
142144

145+
@Override
146+
public boolean containsSystemUpdates()
147+
{
148+
return isPositive( systemUpdates );
149+
}
150+
151+
@Override
152+
public int systemUpdates()
153+
{
154+
return systemUpdates;
155+
}
156+
143157
@Override
144158
public boolean equals( Object o )
145159
{
@@ -164,7 +178,8 @@ public boolean equals( Object o )
164178
&& indexesAdded == that.indexesAdded
165179
&& indexesRemoved == that.indexesRemoved
166180
&& constraintsAdded == that.constraintsAdded
167-
&& constraintsRemoved == that.constraintsRemoved;
181+
&& constraintsRemoved == that.constraintsRemoved
182+
&& systemUpdates == that.systemUpdates;
168183
}
169184

170185
@Override
@@ -181,6 +196,7 @@ public int hashCode()
181196
result = 31 * result + indexesRemoved;
182197
result = 31 * result + constraintsAdded;
183198
result = 31 * result + constraintsRemoved;
199+
result = 31 * result + systemUpdates;
184200
return result;
185201
}
186202

driver/src/main/java/org/neo4j/driver/internal/util/MetadataExtractor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ private static InternalSummaryCounters extractCounters( Map<String,Value> metada
178178
counterValue( countersValue, "indexes-added" ),
179179
counterValue( countersValue, "indexes-removed" ),
180180
counterValue( countersValue, "constraints-added" ),
181-
counterValue( countersValue, "constraints-removed" )
181+
counterValue( countersValue, "constraints-removed" ),
182+
counterValue( countersValue, "system-updates" )
182183
);
183184
}
184185
return null;

driver/src/main/java/org/neo4j/driver/summary/SummaryCounters.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,15 @@ public interface SummaryCounters
8787
* @return number of constraints removed from the schema.
8888
*/
8989
int constraintsRemoved();
90+
91+
/**
92+
* If the query updated the system graph in any way, this method will return true,
93+
* @return true if the system graph has been updated.
94+
*/
95+
boolean containsSystemUpdates();
96+
97+
/**
98+
* @return the number of system updates performed by this query.
99+
*/
100+
int systemUpdates();
90101
}

driver/src/test/java/org/neo4j/driver/integration/SummaryIT.java

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,27 @@
1818
*/
1919
package org.neo4j.driver.integration;
2020

21+
import org.junit.jupiter.api.AfterEach;
22+
import org.junit.jupiter.api.BeforeEach;
2123
import org.junit.jupiter.api.Test;
2224
import org.junit.jupiter.api.extension.RegisterExtension;
2325

2426
import java.util.List;
2527
import java.util.concurrent.TimeUnit;
2628

29+
import org.neo4j.driver.Session;
2730
import org.neo4j.driver.StatementResult;
2831
import org.neo4j.driver.Value;
2932
import org.neo4j.driver.Values;
33+
import org.neo4j.driver.internal.util.EnabledOnNeo4jWith;
34+
import org.neo4j.driver.internal.util.Neo4jFeature;
3035
import org.neo4j.driver.summary.Notification;
3136
import org.neo4j.driver.summary.Plan;
3237
import org.neo4j.driver.summary.ProfiledPlan;
3338
import org.neo4j.driver.summary.ResultSummary;
3439
import org.neo4j.driver.summary.StatementType;
40+
import org.neo4j.driver.util.DatabaseExtension;
3541
import org.neo4j.driver.util.ParallelizableIT;
36-
import org.neo4j.driver.util.SessionExtension;
3742

3843
import static org.hamcrest.Matchers.equalTo;
3944
import static org.hamcrest.Matchers.greaterThan;
@@ -44,12 +49,30 @@
4449
import static org.junit.jupiter.api.Assertions.assertFalse;
4550
import static org.junit.jupiter.api.Assertions.assertNotNull;
4651
import static org.junit.jupiter.api.Assertions.assertTrue;
52+
import static org.neo4j.driver.SessionConfig.forDatabase;
4753

4854
@ParallelizableIT
4955
class SummaryIT
5056
{
5157
@RegisterExtension
52-
static final SessionExtension session = new SessionExtension();
58+
static final DatabaseExtension neo4j = new DatabaseExtension();
59+
private Session session;
60+
61+
@BeforeEach
62+
void setup()
63+
{
64+
session = neo4j.driver().session();
65+
}
66+
67+
@AfterEach
68+
void tearDown()
69+
{
70+
if ( session != null && session.isOpen() )
71+
{
72+
session.close();
73+
}
74+
session = null;
75+
}
5376

5477
@Test
5578
void shouldContainBasicMetadata()
@@ -112,6 +135,18 @@ void shouldContainCorrectStatistics()
112135
.summary().counters().constraintsRemoved(), equalTo( 1 ) );
113136
}
114137

138+
@Test
139+
@EnabledOnNeo4jWith( Neo4jFeature.BOLT_V4 )
140+
void shouldGetSystemUpdates() throws Throwable
141+
{
142+
try ( Session session = neo4j.driver().session( forDatabase( "system" ) ) )
143+
{
144+
StatementResult result = session.run( "CREATE USER foo SET PASSWORD 'bar'" );
145+
assertThat( result.summary().counters().containsUpdates(), equalTo( false ) );
146+
assertThat( result.summary().counters().containsSystemUpdates(), equalTo( true ) );
147+
}
148+
}
149+
115150
@Test
116151
void shouldContainCorrectStatementType()
117152
{

driver/src/test/java/org/neo4j/driver/internal/async/AsyncStatementResultCursorImplTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ void shouldReturnSummary()
8888

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

9495
AsyncStatementResultCursorImpl cursor = newCursor( pullAllHandler );

0 commit comments

Comments
 (0)