Skip to content
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

Fix #9346 clear single metrics api #9569

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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 14 additions & 14 deletions src/main/java/edu/harvard/iq/dataverse/api/Admin.java
Original file line number Diff line number Diff line change
Expand Up @@ -2063,21 +2063,21 @@ public void run() {
}
}

@DELETE
@Path("/clearMetricsCache")
public Response clearMetricsCache() {
em.createNativeQuery("DELETE FROM metric").executeUpdate();
return ok("all metric caches cleared.");
}
@DELETE
@Path("/clearMetricsCache")
public Response clearMetricsCache() {
em.createNativeQuery("DELETE FROM metric").executeUpdate();
return ok("all metric caches cleared.");
}

@DELETE
@Path("/clearMetricsCache/{name}")
public Response clearMetricsCacheByName(@PathParam("name") String name) {
Query deleteQuery = em.createNativeQuery("DELETE FROM metric where metricname = ?");
deleteQuery.setParameter(1, name);
deleteQuery.executeUpdate();
return ok("metric cache " + name + " cleared.");
}
@DELETE
@Path("/clearMetricsCache/{name}")
public Response clearMetricsCacheByName(@PathParam("name") String name) {
Query deleteQuery = em.createNativeQuery("DELETE FROM metric where name = ?");
deleteQuery.setParameter(1, name);
deleteQuery.executeUpdate();
return ok("metric cache " + name + " cleared.");
}

@GET
@AuthRequired
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/MetricsIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,12 @@ public void testGetDataverseBySubject() {
response = UtilIT.metricsDataversesBySubject("dataLocation=local");
response.then().assertThat()
.statusCode(BAD_REQUEST.getStatusCode());

// Test cache delete for single metric - just tests that the call succeeds since
// the client can't really tell whether it gets a new/cached value

response = UtilIT.clearMetricCache("dataversesBySubject");
response.then().assertThat().statusCode(OK.getStatusCode());
}

@Test
Expand Down
6 changes: 6 additions & 0 deletions src/test/java/edu/harvard/iq/dataverse/api/UtilIT.java
Original file line number Diff line number Diff line change
Expand Up @@ -2404,6 +2404,12 @@ static Response clearMetricCache() {
RequestSpecification requestSpecification = given();
return requestSpecification.delete("/api/admin/clearMetricsCache");
}

static Response clearMetricCache(String name) {
RequestSpecification requestSpecification = given();
return requestSpecification.delete("/api/admin/clearMetricsCache/" + name);
}


static Response sitemapUpdate() {
return given()
Expand Down