Skip to content

Commit d911710

Browse files
committed
Test and Doc test cleanup
* Updated TaskExecutionService tests to replaced deprecated code. * Updated TaskLogsDocumentation to use Awaitility instead of a thread.sleep. * Updated StreamDeploymentDocumentation to remove unnecessary prints that cluttered the log. * Updated StreamDeploymentDocumentation to remove unnecessary thread.sleeps. Updated DefaultTaskExecutionServiceTests to JUnit5 Removed unusedimport from StreamDeploymentDocumentation
1 parent f8ca29c commit d911710

File tree

4 files changed

+188
-246
lines changed

4 files changed

+188
-246
lines changed

spring-cloud-dataflow-classic-docs/pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,12 @@
8888
<artifactId>junit</artifactId>
8989
<scope>test</scope>
9090
</dependency>
91-
</dependencies>
91+
<dependency>
92+
<groupId>org.awaitility</groupId>
93+
<artifactId>awaitility</artifactId>
94+
<scope>test</scope>
95+
</dependency>
96+
</dependencies>
9297
<build>
9398
<plugins>
9499
<plugin>

spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/StreamDeploymentsDocumentation.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2018 the original author or authors.
2+
* Copyright 2017-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -42,7 +42,6 @@
4242
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
4343
import static org.springframework.restdocs.request.RequestDocumentation.pathParameters;
4444
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
45-
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
4645
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
4746

4847
/**
@@ -93,7 +92,6 @@ public void scale() throws Exception {
9392
post("/streams/deployments/scale/{streamName}/{appName}/instances/{count}", "timelog", "log", 1)
9493
.contentType(MediaType.APPLICATION_JSON)
9594
.content(json))
96-
.andDo(print())
9795
.andExpect(status().isCreated())
9896
.andDo(this.documentationHandler.document(pathParameters(
9997
parameterWithName("streamName")
@@ -148,7 +146,6 @@ public void deploy() throws Exception {
148146
post("/streams/deployments/{timelog}", "timelog")
149147
.contentType(MediaType.APPLICATION_JSON)
150148
.content(json))
151-
.andDo(print())
152149
.andExpect(status().isCreated())
153150
.andDo(this.documentationHandler.document(
154151
pathParameters(parameterWithName("timelog")
@@ -163,13 +160,11 @@ public void streamUpdate() throws Exception {
163160
post("/streams/deployments/{timelog1}", "timelog1")
164161
.contentType(MediaType.APPLICATION_JSON)
165162
.content(json))
166-
.andDo(print())
167163
.andExpect(status().isCreated())
168164
.andDo(this.documentationHandler.document(
169165
pathParameters(parameterWithName("timelog1")
170166
.description("The name of an existing stream definition (required)"))
171167
));
172-
Thread.sleep(30000);
173168
UpdateStreamRequest updateStreamRequest = new UpdateStreamRequest();
174169
updateStreamRequest.setReleaseName("timelog1");
175170
Map<String, String> updateProperties = new HashMap<>();
@@ -186,13 +181,11 @@ public void streamUpdate() throws Exception {
186181
post("/streams/deployments/update/{timelog1}", "timelog1")
187182
.contentType(MediaType.APPLICATION_JSON)
188183
.content(convertObjectToJson(updateStreamRequest)))
189-
.andDo(print())
190184
.andExpect(status().isCreated())
191185
.andDo(this.documentationHandler.document(
192186
pathParameters(parameterWithName("timelog1")
193187
.description("The name of an existing stream definition (required)"))
194188
));
195-
Thread.sleep(30000);
196189
}
197190

198191
@Test
@@ -202,13 +195,11 @@ public void rollback() throws Exception {
202195
this.mockMvc.perform(
203196
post("/streams/deployments/rollback/{name}/{version}", "timelog1", 1)
204197
.contentType(MediaType.APPLICATION_JSON))
205-
.andDo(print())
206198
.andExpect(status().isCreated())
207199
.andDo(this.documentationHandler.document(
208200
pathParameters(parameterWithName("name")
209201
.description("The name of an existing stream definition (required)"),
210202
parameterWithName("version").description("The version to rollback to"))));
211-
Thread.sleep(30000);
212203
}
213204

214205
@Test
@@ -219,7 +210,6 @@ public void history() throws Exception {
219210
this.mockMvc.perform(
220211
get("/streams/deployments/history/{name}", "timelog1")
221212
.contentType(MediaType.APPLICATION_JSON))
222-
.andDo(print())
223213
.andExpect(status().isOk())
224214
.andDo(this.documentationHandler.document(
225215
pathParameters(parameterWithName("name")
@@ -231,7 +221,6 @@ public void manifest() throws Exception {
231221
this.mockMvc.perform(
232222
get("/streams/deployments/manifest/{name}/{version}", "timelog1", 1)
233223
.contentType(MediaType.APPLICATION_JSON))
234-
.andDo(print())
235224
.andExpect(status().isOk())
236225
.andDo(this.documentationHandler.document(
237226
pathParameters(parameterWithName("name")
@@ -244,7 +233,6 @@ public void platformList() throws Exception {
244233
this.mockMvc.perform(
245234
get("/streams/deployments/platform/list")
246235
.contentType(MediaType.APPLICATION_JSON))
247-
.andDo(print())
248236
.andExpect(status().isOk());
249237
}
250238

spring-cloud-dataflow-classic-docs/src/test/java/org/springframework/cloud/dataflow/server/rest/documentation/TaskLogsDocumentation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2019 the original author or authors.
2+
* Copyright 2019-2023 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,12 +16,16 @@
1616

1717
package org.springframework.cloud.dataflow.server.rest.documentation;
1818

19+
import org.awaitility.Awaitility;
1920
import org.junit.FixMethodOrder;
2021
import org.junit.Test;
2122
import org.junit.runners.MethodSorters;
2223

2324
import org.springframework.cloud.dataflow.core.ApplicationType;
2425
import org.springframework.cloud.dataflow.server.repository.TaskDeploymentRepository;
26+
import org.springframework.cloud.dataflow.server.service.TaskExecutionService;
27+
28+
import java.time.Duration;
2529

2630
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.get;
2731
import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.post;
@@ -34,6 +38,7 @@
3438
* Documentation for the {@code /tasks/logs} endpoint.
3539
*
3640
* @author Ilayaperumal Gopinathan
41+
* @author Glenn Renfro
3742
*/
3843
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
3944
public class TaskLogsDocumentation extends BaseDocumentation {
@@ -53,7 +58,9 @@ public void getLogsByTaskId() throws Exception {
5358
.andExpect(status().isCreated());
5459
TaskDeploymentRepository taskDeploymentRepository =
5560
springDataflowServer.getWebApplicationContext().getBean(TaskDeploymentRepository.class);
56-
Thread.sleep(30000);
61+
TaskExecutionService service = this.springDataflowServer.getWebApplicationContext().getBean(TaskExecutionService.class);
62+
Awaitility.await().atMost(Duration.ofMillis(30000)).until(() -> service.getLog("default",
63+
taskDeploymentRepository.findTopByTaskDefinitionNameOrderByCreatedOnAsc(taskName).getTaskDeploymentId()).length() > 0);
5764
this.mockMvc.perform(
5865
get("/tasks/logs/"+taskDeploymentRepository.findTopByTaskDefinitionNameOrderByCreatedOnAsc(taskName)
5966
.getTaskDeploymentId()).param("platformName", "default"))

0 commit comments

Comments
 (0)