Skip to content

Commit 89e693e

Browse files
committed
QueryEntity updates
1 parent 1e59b96 commit 89e693e

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
@@ -1063,8 +1063,17 @@ void getCurrentlyRunningQueries(ArangoDatabase db) throws InterruptedException {
10631063
final Collection<QueryEntity> currentlyRunningQueries = db.getCurrentlyRunningQueries();
10641064
assertThat(currentlyRunningQueries).hasSize(1);
10651065
final QueryEntity queryEntity = currentlyRunningQueries.iterator().next();
1066+
assertThat(queryEntity.getId()).isNotNull();
1067+
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
1068+
assertThat(queryEntity.getUser()).isEqualTo("root");
10661069
assertThat(queryEntity.getQuery()).isEqualTo(query);
1070+
assertThat(queryEntity.getBindVars()).isEmpty();
1071+
assertThat(queryEntity.getRunTime()).isPositive();
1072+
if(isAtLeastVersion(3,11)){
1073+
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
1074+
}
10671075
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.EXECUTING);
1076+
assertThat(queryEntity.getStream()).isFalse();
10681077
t.join();
10691078
}
10701079

@@ -1108,11 +1117,22 @@ void getAndClearSlowQueries(ArangoDatabase db) {
11081117
properties.setSlowQueryThreshold(1L);
11091118
db.setQueryTrackingProperties(properties);
11101119

1111-
db.query("return sleep(1.1)", null, null, Void.class);
1120+
String query = "return sleep(1.1)";
1121+
db.query(query, Void.class);
11121122
final Collection<QueryEntity> slowQueries = db.getSlowQueries();
11131123
assertThat(slowQueries).hasSize(1);
11141124
final QueryEntity queryEntity = slowQueries.iterator().next();
1115-
assertThat(queryEntity.getQuery()).isEqualTo("return sleep(1.1)");
1125+
assertThat(queryEntity.getId()).isNotNull();
1126+
assertThat(queryEntity.getDatabase()).isEqualTo(db.name());
1127+
assertThat(queryEntity.getUser()).isEqualTo("root");
1128+
assertThat(queryEntity.getQuery()).isEqualTo(query);
1129+
assertThat(queryEntity.getBindVars()).isEmpty();
1130+
assertThat(queryEntity.getRunTime()).isPositive();
1131+
if(isAtLeastVersion(3,11)){
1132+
assertThat(queryEntity.getPeakMemoryUsage()).isNotNull();
1133+
}
1134+
assertThat(queryEntity.getState()).isEqualTo(QueryExecutionState.FINISHED);
1135+
assertThat(queryEntity.getStream()).isFalse();
11161136

11171137
db.clearSlowQueries();
11181138
assertThat(db.getSlowQueries()).isEmpty();

0 commit comments

Comments
 (0)