SCT-12 Creates the SCSt sink that can launch tasks.
resolves spring-cloud/spring-cloud-task#12
This commit is contained in:
committed by
Michael Minella
parent
f35f8ef52d
commit
aad0a0b1ee
@@ -0,0 +1,83 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.task.launcher;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.cloud.deployer.spi.task.LaunchState;
|
||||
import org.springframework.cloud.stream.annotation.Bindings;
|
||||
import org.springframework.cloud.stream.messaging.Sink;
|
||||
import org.springframework.cloud.task.launcher.configuration.TaskConfiguration;
|
||||
import org.springframework.cloud.task.launcher.util.TaskLauncherSinkApplication;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.messaging.support.GenericMessage;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = {TaskLauncherSinkApplication.class, TaskConfiguration.class} )
|
||||
public class TaskLauncherSinkTests {
|
||||
|
||||
private final static String DEFAULT_STATUS = "test_status";
|
||||
|
||||
@Autowired
|
||||
private ApplicationContext context;
|
||||
|
||||
@Autowired
|
||||
@Bindings(TaskLauncherSink.class)
|
||||
private Sink sink;
|
||||
|
||||
|
||||
@Test
|
||||
public void testSuccess() {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("server.port", "0");
|
||||
TaskLaunchRequest request = new TaskLaunchRequest("timestamp-task",
|
||||
"org.springframework.cloud.task.module","1.0.0.BUILD-SNAPSHOT", "jar",
|
||||
"exec", properties);
|
||||
GenericMessage<TaskLaunchRequest> message = new GenericMessage<>(request);
|
||||
this.sink.input().send(message);
|
||||
assertEquals(LaunchState.complete, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoRun() {
|
||||
TaskConfiguration.TestTaskLauncher testTaskLauncher =
|
||||
context.getBean(TaskConfiguration.TestTaskLauncher.class);
|
||||
|
||||
assertEquals(LaunchState.unknown, testTaskLauncher.status(DEFAULT_STATUS).getState());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoTaskLauncher() {
|
||||
Map<String, String> properties = new HashMap<>();
|
||||
properties.put("server.port", "0");
|
||||
TaskLauncherSink sink = new TaskLauncherSink();
|
||||
sink.taskLauncherSink(new TaskLaunchRequest("timestamp-task",
|
||||
"org.springframework.cloud.task.module","1.0.0.BUILD-SNAPSHOT", "jar",
|
||||
"exec", properties));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.task.launcher.configuration;
|
||||
|
||||
import org.springframework.cloud.deployer.spi.core.AppDeploymentRequest;
|
||||
import org.springframework.cloud.deployer.spi.task.LaunchState;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskLauncher;
|
||||
import org.springframework.cloud.deployer.spi.task.TaskStatus;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
|
||||
@Configuration
|
||||
public class TaskConfiguration {
|
||||
|
||||
@Bean
|
||||
public TaskLauncher taskLauncher(){
|
||||
return new TestTaskLauncher();
|
||||
}
|
||||
|
||||
public static class TestTaskLauncher implements TaskLauncher{
|
||||
|
||||
public static final String LAUNCH_ID = "TEST_LAUNCH_ID";
|
||||
|
||||
private LaunchState state = LaunchState.unknown;
|
||||
|
||||
@Override
|
||||
public String launch(AppDeploymentRequest request) {
|
||||
state = LaunchState.complete;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel(String id) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public TaskStatus status(String id) {
|
||||
return new TaskStatus(LAUNCH_ID, state, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2016 the original author or authors.
|
||||
*
|
||||
* 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 org.springframework.cloud.task.launcher.util;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.task.launcher.annotation.EnableTaskLauncher;
|
||||
|
||||
/**
|
||||
* @author Glenn Renfro
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@EnableTaskLauncher
|
||||
public class TaskLauncherSinkApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(TaskLauncherSinkApplication.class, args);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user