Skip to content
This repository was archived by the owner on May 14, 2025. It is now read-only.

Commit cb56513

Browse files
dturanskitzolov
andauthored
Add dataflowTaskLauncherSink IT test (#4652)
* Add dataflowTaskLauncherSink IT test * Adjustments - Add explicit --spring.cloud.dataflow.client.serverUri=http://dataflow-server:9393 to the definition. - Add RuntimeApplicationHelper#httpPost with http headers support. - Add CT: application/json to the test's http post. Co-authored-by: Christian Tzolov <[email protected]>
1 parent 1c7b193 commit cb56513

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/integration/test/DataFlowIT.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.Optional;
3131
import java.util.Random;
3232
import java.util.UUID;
33+
import java.util.concurrent.atomic.AtomicLong;
3334
import java.util.function.Consumer;
3435
import java.util.function.Predicate;
3536
import java.util.function.Supplier;
@@ -83,7 +84,9 @@
8384
import org.springframework.context.annotation.Import;
8485
import org.springframework.core.io.DefaultResourceLoader;
8586
import org.springframework.hateoas.PagedModel;
87+
import org.springframework.http.HttpHeaders;
8688
import org.springframework.http.HttpMethod;
89+
import org.springframework.http.MediaType;
8790
import org.springframework.test.context.junit.jupiter.SpringExtension;
8891
import org.springframework.util.StreamUtils;
8992
import org.springframework.web.util.UriComponentsBuilder;
@@ -753,6 +756,50 @@ public void namedChannelDirectedGraph() {
753756
}
754757
}
755758

759+
@Test
760+
public void dataflowTaskLauncherSink() {
761+
logger.info("dataflow-tasklauncher-sink-test");
762+
String uri = String.format("docker:springcloud/spring-cloud-dataflow-tasklauncher-sink-kafka:%s",
763+
testProperties.getDatabase().getDataflowVersion());
764+
dataFlowOperations.appRegistryOperations()
765+
.register("dataflowTaskLauncher", ApplicationType.sink, uri, null, true);
766+
767+
768+
String taskName = randomTaskName();
769+
try (Task task = Task.builder(dataFlowOperations)
770+
.name(taskName)
771+
.definition("timestamp")
772+
.description("Test timestamp task")
773+
.build()) {
774+
try (Stream stream = Stream.builder(dataFlowOperations).name("tasklauncher-test")
775+
.definition("http | dataflowTaskLauncher --trigger.initialDelay=100 --trigger.maxPeriod=1000 " +
776+
"--spring.cloud.dataflow.client.serverUri=http://dataflow-server:9393")
777+
.create()
778+
.deploy(testDeploymentProperties())) {
779+
780+
Awaitility.await().until(() -> stream.getStatus().equals(DEPLOYED));
781+
782+
HttpHeaders headers = new HttpHeaders();
783+
headers.setContentType(MediaType.APPLICATION_JSON);
784+
headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON));
785+
786+
runtimeApps.httpPost(stream.getName(), "http", "{\"name\" : \"" + taskName + "\"}", headers);
787+
788+
AtomicLong launchId = new AtomicLong();
789+
Awaitility.await().until(() -> task.executions().stream().filter(t ->
790+
t.getTaskName().equals(taskName) && t.getTaskExecutionStatus() == TaskExecutionStatus.COMPLETE)
791+
.findFirst()
792+
.map(t -> launchId.getAndSet(t.getExecutionId())).isPresent()
793+
);
794+
long id = launchId.get();
795+
assertThat(task.executions().size()).isEqualTo(1);
796+
assertThat(task.execution(id).isPresent()).isTrue();
797+
assertThat(task.execution(id).get().getExitCode()).isEqualTo(EXIT_CODE_SUCCESS);
798+
}
799+
}
800+
}
801+
802+
756803
// -----------------------------------------------------------------------
757804
// STREAM METRICS TESTS
758805
// -----------------------------------------------------------------------

spring-cloud-dataflow-server/src/test/java/org/springframework/cloud/dataflow/integration/test/util/RuntimeApplicationHelper.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
import org.springframework.cloud.dataflow.rest.resource.AppStatusResource;
3333
import org.springframework.cloud.dataflow.rest.resource.DetailedAppRegistrationResource;
3434
import org.springframework.cloud.skipper.domain.Deployer;
35+
import org.springframework.http.HttpEntity;
36+
import org.springframework.http.HttpHeaders;
3537
import org.springframework.http.HttpMethod;
3638
import org.springframework.util.Assert;
3739
import org.springframework.util.CollectionUtils;
@@ -259,6 +261,12 @@ public void httpPost(String url, String message) {
259261
dataFlowTemplate.getRestTemplate().postForObject(url, message, String.class);
260262
}
261263

264+
public void httpPost(String streamName, String appName, String message, HttpHeaders headers) {
265+
String url = this.getApplicationInstanceUrl(streamName, appName);
266+
HttpEntity<String> entity = new HttpEntity<>(message, headers);
267+
dataFlowTemplate.getRestTemplate().postForEntity(url, entity, String.class);
268+
}
269+
262270
public String httpGet(String url) {
263271
return dataFlowTemplate.getRestTemplate().getForObject(url, String.class);
264272
}

0 commit comments

Comments
 (0)