Skip to content

Commit 4fc4615

Browse files
committed
fix: correct event search query by using API ID to fetch latest event
(cherry picked from commit f6d484d)
1 parent 6039587 commit 4fc4615

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/main/java/io/gravitee/rest/api/service/v4/impl/ApiStateServiceImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ private void addDeploymentLabelToProperties(
248248
.build();
249249

250250
String lastDeployNumber = eventLatestRepository
251-
.search(criteria, Event.EventProperties.DEPLOYMENT_NUMBER, 0L, 1L)
251+
.search(criteria, Event.EventProperties.API_ID, 0L, 1L)
252252
.stream()
253253
.findFirst()
254254
.map(eventEntity -> eventEntity.getProperties().getOrDefault(Event.EventProperties.DEPLOYMENT_NUMBER.getValue(), "0"))

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/test/java/io/gravitee/rest/api/service/v4/impl/ApiServiceImplTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,9 @@ public void shouldDeployApi() throws TechnicalException {
11651165
when(apiValidationService.canDeploy(any(), any())).thenReturn(true);
11661166
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
11671167
when(apiRepository.update(api)).thenReturn(api);
1168-
when(
1169-
eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.DEPLOYMENT_NUMBER), eq(0L), eq(1L))
1170-
).thenReturn(List.of(previousPublishedEvent));
1168+
when(eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.API_ID), eq(0L), eq(1L))).thenReturn(
1169+
List.of(previousPublishedEvent)
1170+
);
11711171

11721172
final ApiDeploymentEntity apiDeploymentEntity = new ApiDeploymentEntity();
11731173
apiDeploymentEntity.setDeploymentLabel("deploy-label");

gravitee-apim-rest-api/gravitee-apim-rest-api-service/src/test/java/io/gravitee/rest/api/service/v4/impl/ApiStateServiceImpl_DeployTest.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,9 @@ public void should_deploy_api_if_managed_by_kubernetes() throws TechnicalExcepti
223223
when(apiValidationService.canDeploy(GraviteeContext.getExecutionContext(), API_ID)).thenReturn(true);
224224
when(apiSearchService.findRepositoryApiById(any(), eq(API_ID))).thenReturn(api);
225225
when(apiRepository.update(api)).thenReturn(api);
226-
when(
227-
eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.DEPLOYMENT_NUMBER), eq(0L), eq(1L))
228-
).thenReturn(List.of(previousPublishedEvent));
226+
when(eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.API_ID), eq(0L), eq(1L))).thenReturn(
227+
List.of(previousPublishedEvent)
228+
);
229229

230230
final ApiDeploymentEntity apiDeploymentEntity = new ApiDeploymentEntity();
231231
apiDeploymentEntity.setDeploymentLabel("deploy-label");
@@ -267,9 +267,9 @@ public void should_deploy_api() throws TechnicalException {
267267
when(apiValidationService.canDeploy(GraviteeContext.getExecutionContext(), API_ID)).thenReturn(true);
268268
when(apiSearchService.findRepositoryApiById(GraviteeContext.getExecutionContext(), API_ID)).thenReturn(api);
269269
when(apiRepository.update(api)).thenReturn(api);
270-
when(
271-
eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.DEPLOYMENT_NUMBER), eq(0L), eq(1L))
272-
).thenReturn(List.of(previousPublishedEvent));
270+
when(eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.API_ID), eq(0L), eq(1L))).thenReturn(
271+
List.of(previousPublishedEvent)
272+
);
273273

274274
final ApiDeploymentEntity apiDeploymentEntity = new ApiDeploymentEntity();
275275
apiDeploymentEntity.setDeploymentLabel("deploy-label");
@@ -320,9 +320,9 @@ public void shouldAddDeploymentLabelAndIncrementDeploymentNumber() throws Except
320320
deploymentEntity.setDeploymentLabel("Release v1.0");
321321
Event mockEvent = new Event();
322322
mockEvent.setProperties(Map.of(Event.EventProperties.DEPLOYMENT_NUMBER.getValue(), "5"));
323-
when(
324-
eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.DEPLOYMENT_NUMBER), eq(0L), eq(1L))
325-
).thenReturn(List.of(mockEvent));
323+
when(eventLatestRepository.search(any(EventCriteria.class), eq(Event.EventProperties.API_ID), eq(0L), eq(1L))).thenReturn(
324+
List.of(mockEvent)
325+
);
326326
Map<String, String> props = new HashMap<>();
327327

328328
ApiStateServiceImpl impl = new ApiStateServiceImpl(

0 commit comments

Comments
 (0)