Skip to content

Commit 75064f5

Browse files
committed
QueryEntity updates
1 parent de0c195 commit 75064f5

File tree

2 files changed

+57
-6
lines changed

2 files changed

+57
-6
lines changed

src/main/java/com/arangodb/entity/QueryEntity.java

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ public class QueryEntity implements Entity {
3131
public static final String PROPERTY_STARTED = "started";
3232

3333
private String id;
34+
private String database;
35+
private String user;
3436
private String query;
37+
private Map<String, Object> bindVars;
3538
private Date started;
3639
private Double runTime;
37-
private Map<String, Object> bindVars;
40+
private Long peakMemoryUsage;
3841
private QueryExecutionState state;
42+
private Boolean stream;
3943

4044
public QueryEntity() {
4145
super();
@@ -48,13 +52,34 @@ public String getId() {
4852
return id;
4953
}
5054

55+
/**
56+
* @return the name of the database the query runs in
57+
*/
58+
public String getDatabase() {
59+
return database;
60+
}
61+
62+
/**
63+
* @return the name of the user that started the query
64+
*/
65+
public String getUser() {
66+
return user;
67+
}
68+
5169
/**
5270
* @return the query string (potentially truncated)
5371
*/
5472
public String getQuery() {
5573
return query;
5674
}
5775

76+
/**
77+
* @return the bind parameter values used by the query
78+
*/
79+
public Map<String, Object> getBindVars() {
80+
return bindVars;
81+
}
82+
5883
/**
5984
* @return the date and time when the query was started
6085
*/
@@ -70,10 +95,10 @@ public Double getRunTime() {
7095
}
7196

7297
/**
73-
* @return the bind parameter values used by the query
98+
* @return the query’s peak memory usage in bytes (in increments of 32KB)
7499
*/
75-
public Map<String, Object> getBindVars() {
76-
return bindVars;
100+
public Long getPeakMemoryUsage() {
101+
return peakMemoryUsage;
77102
}
78103

79104
/**
@@ -83,4 +108,10 @@ public QueryExecutionState getState() {
83108
return state;
84109
}
85110

111+
/**
112+
* @return whether or not the query uses a streaming cursor
113+
*/
114+
public Boolean getStream() {
115+
return stream;
116+
}
86117
}

src/test/java/com/arangodb/ArangoDatabaseTest.java

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,8 +1119,17 @@ void getCurrentlyRunningQueries(ArangoDatabase db) throws InterruptedException {
11191119
final Collection<QueryEntity> currentlyRunningQueries = db.getCurrentlyRunningQueries();
11201120
assertThat(currentlyRunningQueries).hasSize(1);
11211121
final QueryEntity queryEntity = currentlyRunningQueries.iterator().next();
1122+
assertThat(queryEntity.getId()).isNotNull();
1123+
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
1124+
assertThat(queryEntity.getUser()).isEqualTo("root");
11221125
assertThat(queryEntity.getQuery()).isEqualTo(query);
1126+
assertThat(queryEntity.getBindVars()).isEmpty();
1127+
assertThat(queryEntity.getRunTime()).isPositive();
1128+
if(isAtLeastVersion(3,11)){
1129+
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
1130+
}
11231131
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.EXECUTING);
1132+
assertThat(queryEntity.getStream()).isFalse();
11241133
t.join();
11251134
}
11261135

@@ -1164,11 +1173,22 @@ void getAndClearSlowQueries(ArangoDatabase db) {
11641173
properties.setSlowQueryThreshold(1L);
11651174
db.setQueryTrackingProperties(properties);
11661175

1167-
db.query("return sleep(1.1)", null, null, Void.class);
1176+
String query = "return sleep(1.1)";
1177+
db.query(query, Void.class);
11681178
final Collection<QueryEntity> slowQueries = db.getSlowQueries();
11691179
assertThat(slowQueries).hasSize(1);
11701180
final QueryEntity queryEntity = slowQueries.iterator().next();
1171-
assertThat(queryEntity.getQuery()).isEqualTo("return sleep(1.1)");
1181+
assertThat(queryEntity.getId()).isNotNull();
1182+
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
1183+
assertThat(queryEntity.getUser()).isEqualTo("root");
1184+
assertThat(queryEntity.getQuery()).isEqualTo(query);
1185+
assertThat(queryEntity.getBindVars()).isEmpty();
1186+
assertThat(queryEntity.getRunTime()).isPositive();
1187+
if(isAtLeastVersion(3,11)){
1188+
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
1189+
}
1190+
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.FINISHED);
1191+
assertThat(queryEntity.getStream()).isFalse();
11721192

11731193
db.clearSlowQueries();
11741194
assertThat(db.getSlowQueries()).isEmpty();

0 commit comments

Comments
 (0)