-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: make elastic tests independent of the time
Some of the tests of the elastic repository depend on the time when they are executed. This commit introduces a TimeProvider class that is used to provide the same date for both the data put in ES and the tests themselves. (cherry picked from commit 94b9e2a)
- Loading branch information
Showing
9 changed files
with
138 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
...sitory-elasticsearch/src/test/java/io/gravitee/repository/elasticsearch/TimeProvider.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Copyright © 2015 The Gravitee team (http://gravitee.io) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.gravitee.repository.elasticsearch; | ||
|
||
import java.time.Instant; | ||
import java.time.ZoneId; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.temporal.ChronoUnit; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class TimeProvider { | ||
|
||
private static final DateTimeFormatter DATE_TIME_FORMATTER_WITH_DASH = DateTimeFormatter | ||
.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSxxx") | ||
.withZone(ZoneId.systemDefault()); | ||
private static final DateTimeFormatter DATE_FORMATTER_WITH_DASH = DateTimeFormatter | ||
.ofPattern("yyyy-MM-dd") | ||
.withZone(ZoneId.systemDefault()); | ||
private static final DateTimeFormatter DATE_FORMATTER_WITH_DOT = DateTimeFormatter | ||
.ofPattern("yyyy.MM.dd") | ||
.withZone(ZoneId.systemDefault()); | ||
|
||
private final String dateToday; | ||
private final String dateYesterday; | ||
private final String dateTimeToday; | ||
private final String dateTimeYesterday; | ||
private final String todayWithDot; | ||
private final String yesterdayWithDot; | ||
|
||
public TimeProvider() { | ||
final Instant now = Instant.now().minus(30, ChronoUnit.MINUTES); | ||
final Instant yesterday = now.minus(1, ChronoUnit.DAYS); | ||
|
||
dateToday = DATE_FORMATTER_WITH_DASH.format(now); | ||
dateYesterday = DATE_FORMATTER_WITH_DASH.format(yesterday); | ||
|
||
dateTimeToday = DATE_TIME_FORMATTER_WITH_DASH.format(now); | ||
dateTimeYesterday = DATE_TIME_FORMATTER_WITH_DASH.format(yesterday); | ||
|
||
todayWithDot = DATE_FORMATTER_WITH_DOT.format(now); | ||
yesterdayWithDot = DATE_FORMATTER_WITH_DOT.format(yesterday); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 11 additions & 11 deletions
22
...epository/gravitee-apim-repository-elasticsearch/src/test/resources/freemarker/health.ftl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGcnBPkSadZDBaTBag"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": false,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T18:33:11.079+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": false,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGcnBPkSadZDBaTBao"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T18:10:11.079+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGgzxGooztmMPf1gOs"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T18:28:30.718+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGgiqaTGG_RLWNOXe7"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T17:27:20.714+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGgxUsooztmMPf1gOp"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T16:28:20.717+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameToday}, "_id": "AVsGg7GYooztmMPf1gO1"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateToday}T18:29:00.719+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeToday}"} | ||
{ "index" :{ ${indexNameYesterday}, "_id": "AVsGg__MooztmMPf1gO7"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateYesterday}T18:29:20.720+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeYesterday}"} | ||
{ "index" :{ ${indexNameYesterday}, "_id": "AVsGhl3aooztmMPf1gPs"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateYesterday}T18:32:00.052+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeYesterday}"} | ||
{ "index" :{ ${indexNameYesterday}, "_id": "AVsGhoTzooztmMPf1gPv"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateYesterday}T18:32:10.052+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeYesterday}"} | ||
{ "index" :{ ${indexNameYesterday}, "_id": "AVsGhoTzooztmuPf1gPv"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateYesterday}T18:32:10.052+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeYesterday}"} | ||
{ "index" :{ ${indexNameYesterday}, "_id": "AVsGhaTzooztmuPf1gPv"} } | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateYesterday}T18:32:20.052+01:00"} | ||
{"api": "bf19088c-f2c7-4fec-9908-8cf2c75fece4","status": 200,"url": "https://api.gravitee.io/echo/","method": 3,"success": true,"state": 0,"message": null,"hostname": "debian","@timestamp": "${dateTimeYesterday}"} |
Oops, something went wrong.