Skip to content

Commit dc621be

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

File tree

5 files changed

+86
-6
lines changed

5 files changed

+86
-6
lines changed

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

Lines changed: 35 additions & 2 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,6 +35,7 @@ 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,
@@ -43,6 +44,23 @@ public InternalSummaryCounters(
4344
int labelsAdded, int labelsRemoved,
4445
int indexesAdded, int indexesRemoved,
4546
int constraintsAdded, int constraintsRemoved )
47+
{
48+
this( nodesCreated, nodesDeleted,
49+
relationshipsCreated, relationshipsDeleted,
50+
propertiesSet,
51+
labelsAdded, labelsRemoved,
52+
indexesAdded, indexesRemoved,
53+
constraintsAdded, constraintsRemoved,
54+
0 );
55+
}
56+
57+
public InternalSummaryCounters(
58+
int nodesCreated, int nodesDeleted,
59+
int relationshipsCreated, int relationshipsDeleted,
60+
int propertiesSet,
61+
int labelsAdded, int labelsRemoved,
62+
int indexesAdded, int indexesRemoved,
63+
int constraintsAdded, int constraintsRemoved, int systemUpdates )
4664
{
4765
this.nodesCreated = nodesCreated;
4866
this.nodesDeleted = nodesDeleted;
@@ -55,6 +73,7 @@ public InternalSummaryCounters(
5573
this.indexesRemoved = indexesRemoved;
5674
this.constraintsAdded = constraintsAdded;
5775
this.constraintsRemoved = constraintsRemoved;
76+
this.systemUpdates = systemUpdates;
5877
}
5978

6079
@Override
@@ -140,6 +159,18 @@ public int constraintsRemoved()
140159
return constraintsRemoved;
141160
}
142161

162+
@Override
163+
public boolean containsSystemUpdates()
164+
{
165+
return isPositive( systemUpdates );
166+
}
167+
168+
@Override
169+
public int systemUpdates()
170+
{
171+
return systemUpdates;
172+
}
173+
143174
@Override
144175
public boolean equals( Object o )
145176
{
@@ -164,7 +195,8 @@ public boolean equals( Object o )
164195
&& indexesAdded == that.indexesAdded
165196
&& indexesRemoved == that.indexesRemoved
166197
&& constraintsAdded == that.constraintsAdded
167-
&& constraintsRemoved == that.constraintsRemoved;
198+
&& constraintsRemoved == that.constraintsRemoved
199+
&& systemUpdates == that.systemUpdates;
168200
}
169201

170202
@Override
@@ -181,6 +213,7 @@ public int hashCode()
181213
result = 31 * result + indexesRemoved;
182214
result = 31 * result + constraintsAdded;
183215
result = 31 * result + constraintsRemoved;
216+
result = 31 * result + systemUpdates;
184217
return result;
185218
}
186219

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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ 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 ), null, null, emptyList(), 42, 42 );
9292
when( pullAllHandler.summaryAsync() ).thenReturn( completedFuture( summary ) );
9393

9494
AsyncStatementResultCursorImpl cursor = newCursor( pullAllHandler );

0 commit comments

Comments
 (0)