|
16 | 16 |
|
17 | 17 | package org.springframework.cloud.dataflow.server.repository; |
18 | 18 |
|
| 19 | +import java.net.URI; |
19 | 20 | import java.util.Date; |
20 | 21 | import java.util.HashMap; |
21 | 22 | import java.util.HashSet; |
22 | 23 | import java.util.List; |
23 | 24 | import java.util.Map; |
24 | 25 | import java.util.Set; |
| 26 | +import java.util.stream.Collectors; |
25 | 27 |
|
26 | 28 | import javax.sql.DataSource; |
27 | 29 |
|
|
33 | 35 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; |
34 | 36 | import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; |
35 | 37 | import org.springframework.boot.test.context.SpringBootTest; |
36 | | -import org.springframework.cloud.dataflow.aggregate.task.TaskDefinitionReader; |
37 | | -import org.springframework.cloud.dataflow.schema.AggregateTaskExecution; |
38 | 38 | import org.springframework.cloud.dataflow.aggregate.task.AggregateExecutionSupport; |
39 | 39 | import org.springframework.cloud.dataflow.aggregate.task.AggregateTaskExplorer; |
| 40 | +import org.springframework.cloud.dataflow.aggregate.task.TaskDefinitionReader; |
| 41 | +import org.springframework.cloud.dataflow.core.AppRegistration; |
| 42 | +import org.springframework.cloud.dataflow.core.ApplicationType; |
| 43 | +import org.springframework.cloud.dataflow.core.TaskDefinition; |
| 44 | +import org.springframework.cloud.dataflow.registry.service.AppRegistryService; |
| 45 | +import org.springframework.cloud.dataflow.schema.AggregateTaskExecution; |
| 46 | +import org.springframework.cloud.dataflow.schema.AppBootSchemaVersion; |
40 | 47 | import org.springframework.cloud.dataflow.schema.SchemaVersionTarget; |
41 | 48 | import org.springframework.cloud.dataflow.schema.service.SchemaService; |
42 | 49 | import org.springframework.cloud.dataflow.server.configuration.TaskServiceDependencies; |
43 | 50 | import org.springframework.cloud.dataflow.server.repository.support.SchemaUtilities; |
44 | 51 | import org.springframework.data.domain.PageRequest; |
| 52 | +import org.springframework.data.domain.Sort; |
45 | 53 | import org.springframework.jdbc.core.JdbcTemplate; |
46 | 54 | import org.springframework.test.annotation.DirtiesContext; |
47 | 55 | import org.springframework.test.annotation.DirtiesContext.ClassMode; |
48 | 56 | import org.springframework.test.context.junit.jupiter.SpringExtension; |
49 | 57 |
|
50 | 58 | import static org.assertj.core.api.Assertions.assertThat; |
| 59 | +import static org.mockito.ArgumentMatchers.any; |
| 60 | +import static org.mockito.ArgumentMatchers.eq; |
| 61 | +import static org.mockito.Mockito.when; |
51 | 62 |
|
52 | 63 | /** |
53 | 64 | * @author Glenn Renfro |
@@ -77,28 +88,38 @@ public class TaskExecutionExplorerTests { |
77 | 88 | @Autowired |
78 | 89 | private TaskDefinitionReader taskDefinitionReader; |
79 | 90 |
|
| 91 | + @Autowired |
| 92 | + private AppRegistryService appRegistryService; |
| 93 | + |
| 94 | + @Autowired |
| 95 | + private TaskDefinitionRepository definitionRepository; |
| 96 | + |
80 | 97 | @BeforeEach |
81 | 98 | public void setup() throws Exception { |
82 | 99 | template = new JdbcTemplate(dataSource); |
83 | 100 | for (SchemaVersionTarget target : schemaService.getTargets().getSchemas()) { |
84 | 101 | String prefix = target.getTaskPrefix(); |
85 | 102 | template.execute(SchemaUtilities.getQuery("DELETE FROM %PREFIX%EXECUTION", prefix)); |
86 | 103 | } |
| 104 | + TaskDefinition taskDefinition = new TaskDefinition("baz", "baz"); |
| 105 | + definitionRepository.save(taskDefinition); |
87 | 106 | } |
88 | 107 |
|
89 | 108 | @Test |
90 | 109 | public void testInitializer() { |
91 | 110 | for (SchemaVersionTarget target : schemaService.getTargets().getSchemas()) { |
92 | 111 | String prefix = target.getTaskPrefix(); |
93 | | - int actual = template.queryForObject(SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION", prefix), Integer.class); |
| 112 | + int actual = template.queryForObject( |
| 113 | + SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION", prefix), Integer.class); |
94 | 114 | assertThat(actual).isEqualTo(0); |
95 | | - actual = template.queryForObject(SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION_PARAMS", prefix), Integer.class); |
| 115 | + actual = template.queryForObject( |
| 116 | + SchemaUtilities.getQuery("SELECT COUNT(*) from %PREFIX%EXECUTION_PARAMS", prefix), Integer.class); |
96 | 117 | assertThat(actual).isEqualTo(0); |
97 | 118 | } |
98 | 119 | } |
99 | 120 |
|
100 | 121 | @Test |
101 | | - public void testExplorerFindAll(){ |
| 122 | + public void testExplorerFindAll() { |
102 | 123 | final int ENTRY_COUNT = 4; |
103 | 124 | insertTestExecutionDataIntoRepo(template, 3L, "foo"); |
104 | 125 | insertTestExecutionDataIntoRepo(template, 2L, "foo"); |
@@ -135,6 +156,20 @@ public void testExplorerFindByName() throws Exception { |
135 | 156 | assertThat(taskExecution.getTaskName()).isEqualTo("fee"); |
136 | 157 | } |
137 | 158 |
|
| 159 | + @Test |
| 160 | + public void testExplorerSort() throws Exception { |
| 161 | + when(appRegistryService.find(eq("baz"), any(ApplicationType.class))).thenReturn(new AppRegistration("baz", ApplicationType.task, "1.0.0", new URI("file://src/test/resources/register-all.txt"),null, AppBootSchemaVersion.BOOT3)); |
| 162 | + insertTestExecutionDataIntoRepo(template, 3L, "foo"); |
| 163 | + insertTestExecutionDataIntoRepo(template, 2L, "bar"); |
| 164 | + insertTestExecutionDataIntoRepo(template, 1L, "baz"); |
| 165 | + insertTestExecutionDataIntoRepo(template, 0L, "fee"); |
| 166 | + |
| 167 | + List<AggregateTaskExecution> resultList = explorer.findAll(PageRequest.of(0, 10, Sort.by("SCHEMA_TARGET"))).getContent(); |
| 168 | + assertThat(resultList.size()).isEqualTo(4); |
| 169 | + List<Long> ids = resultList.stream().map(AggregateTaskExecution::getExecutionId).collect(Collectors.toList()); |
| 170 | + assertThat(ids).containsExactly(0L, 2L, 3L, 1L); |
| 171 | + } |
| 172 | + |
138 | 173 | private void insertTestExecutionDataIntoRepo(JdbcTemplate template, long id, String taskName) { |
139 | 174 | SchemaVersionTarget schemaVersionTarget = aggregateExecutionSupport.findSchemaVersionTarget(taskName, taskDefinitionReader); |
140 | 175 | final String INSERT_STATEMENT = SchemaUtilities.getQuery("INSERT INTO %PREFIX%EXECUTION (task_execution_id, " |
|
0 commit comments