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

Commit fddafed

Browse files
authored
stream update should not require --properties (#5785)
Currently a user can not set --propertiesFile option on a stream update command This fix allows users to use --properties or --properties file with a stream update command. Added tests to verify
1 parent 13486fc commit fddafed

File tree

4 files changed

+67
-12
lines changed

4 files changed

+67
-12
lines changed

spring-cloud-dataflow-shell-core/src/main/java/org/springframework/cloud/dataflow/shell/command/StreamCommands.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2018-2022 the original author or authors.
2+
* Copyright 2018-2024 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.
@@ -203,7 +203,7 @@ public Table listPlatforms() {
203203
@ShellMethodAvailability("availableWithModifyRole")
204204
public String updateStream(
205205
@ShellOption(value = { "", "--name" }, help = "the name of the stream", valueProvider = StreamNameValueProvider.class) String name,
206-
@ShellOption(help = "Flattened YAML style properties to update the stream") String properties,
206+
@ShellOption(value = "--properties", help = "Flattened YAML style properties to update the stream", defaultValue = ShellOption.NULL) String properties,
207207
@ShellOption(value = "--propertiesFile", help = "the properties for the stream update (as a File)", defaultValue = ShellOption.NULL) File propertiesFile,
208208
@ShellOption(value = "--packageVersion", help = "the package version of the package to update when using Skipper", defaultValue = ShellOption.NULL) String packageVersion,
209209
@ShellOption(value = "--repoName", help = "the name of the local repository to upload the package when using Skipper", defaultValue = ShellOption.NULL) String repoName,

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/StreamCommandTemplate.java

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2022 the original author or authors.
2+
* Copyright 2002-2024 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.
@@ -112,6 +112,30 @@ private void doCreate(String streamname, String streamdefinition, boolean deploy
112112
verifyExists(streamname, actualDefinition, deploy);
113113
}
114114

115+
/**
116+
* Update the given stream
117+
*
118+
* @param streamname name of the stream
119+
* @param propertyValue the value to update stream
120+
*
121+
*/
122+
public void update(String streamname, String propertyValue, String expectedResult) {
123+
Object result = commandRunner.executeCommand("stream update --name " + streamname + " --properties " + propertyValue);
124+
assertThat((String)result).contains(expectedResult);
125+
}
126+
127+
/**
128+
* Update the given stream
129+
*
130+
* @param streamname name of the stream
131+
* @param propertyFile the file that contains the properties
132+
*
133+
*/
134+
public void updateFile(String streamname, String propertyFile, String expectedResult) {
135+
Object result = commandRunner.executeCommand("stream update --name " + streamname + " --propertiesFile " + propertyFile);
136+
assertThat((String)result).contains(expectedResult);
137+
}
138+
115139
/**
116140
* Deploy the given stream
117141
*

spring-cloud-dataflow-shell-core/src/test/java/org/springframework/cloud/dataflow/shell/command/StreamCommandTests.java

+39-9
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2015-2022 the original author or authors.
2+
* Copyright 2015-2024 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,6 +16,7 @@
1616

1717
package org.springframework.cloud.dataflow.shell.command;
1818

19+
import java.io.File;
1920
import java.util.Arrays;
2021

2122
import org.junit.jupiter.api.AfterEach;
@@ -38,6 +39,7 @@
3839
import org.springframework.shell.table.Table;
3940

4041
import static org.assertj.core.api.Assertions.assertThat;
42+
import static org.assertj.core.api.Assertions.in;
4143
import static org.junit.Assert.assertEquals;
4244
import static org.mockito.Mockito.mock;
4345
import static org.mockito.Mockito.when;
@@ -67,20 +69,48 @@ public void destroyStreams() {
6769

6870
@Test
6971
public void testStreamLifecycleForTickTock() throws InterruptedException {
70-
logger.info("Starting Stream Test for TickTock");
71-
Thread.sleep(2000);
7272
String streamName = generateUniqueStreamOrTaskName();
73-
Info info = new Info();
74-
Status status = new Status();
75-
status.setStatusCode(StatusCode.UNKNOWN);
76-
status.setPlatformStatus(null);
77-
info.setStatus(status);
73+
when(skipperClient.status(ArgumentMatchers.anyString())).thenReturn(setupBaseTest());
74+
AppDeployer appDeployer = applicationContext.getBean(AppDeployer.class);
75+
Deployer deployer = new Deployer("testDeployer", "testType", appDeployer, mock(ActuatorOperations.class));
76+
when(skipperClient.listDeployers()).thenReturn(Arrays.asList(deployer));
77+
stream().create(streamName, "time | log");
78+
}
7879

79-
when(skipperClient.status(ArgumentMatchers.anyString())).thenReturn(info);
80+
@Test
81+
public void testStreamUpdateForTickTock() throws InterruptedException {
82+
String streamName = generateUniqueStreamOrTaskName();
83+
84+
when(skipperClient.status(ArgumentMatchers.anyString())).thenReturn(setupBaseTest());
85+
AppDeployer appDeployer = applicationContext.getBean(AppDeployer.class);
86+
Deployer deployer = new Deployer("testDeployer", "testType", appDeployer, mock(ActuatorOperations.class));
87+
when(skipperClient.listDeployers()).thenReturn(Arrays.asList(deployer));
88+
stream().create(streamName, "time | log");
89+
stream().update(streamName, "version.log=3.2.1","Update request has been sent for the stream");
90+
}
91+
92+
@Test
93+
public void testStreamUpdatePropFileForTickTock() throws InterruptedException {
94+
String streamName = generateUniqueStreamOrTaskName();
95+
96+
when(skipperClient.status(ArgumentMatchers.anyString())).thenReturn(setupBaseTest());
8097
AppDeployer appDeployer = applicationContext.getBean(AppDeployer.class);
8198
Deployer deployer = new Deployer("testDeployer", "testType", appDeployer, mock(ActuatorOperations.class));
8299
when(skipperClient.listDeployers()).thenReturn(Arrays.asList(deployer));
83100
stream().create(streamName, "time | log");
101+
File resourcesDirectory = new File("src/test/resources");
102+
stream().updateFile(streamName, resourcesDirectory.getAbsolutePath() + "/myproperties.properties","Update request has been sent for the stream");
103+
}
104+
105+
private Info setupBaseTest() throws InterruptedException {
106+
logger.info("Starting Stream Test for TickTock Update");
107+
Thread.sleep(2000);
108+
Info info = new Info();
109+
Status status = new Status();
110+
status.setStatusCode(StatusCode.UNKNOWN);
111+
status.setPlatformStatus(null);
112+
info.setStatus(status);
113+
return info;
84114
}
85115

86116
@Test
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
version.log=3.2.1

0 commit comments

Comments
 (0)