|
| 1 | +/* |
| 2 | + * Copyright 2026 Conductor Authors. |
| 3 | + * <p> |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with |
| 5 | + * the License. You may obtain a copy of the License at |
| 6 | + * <p> |
| 7 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | + * <p> |
| 9 | + * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on |
| 10 | + * an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the |
| 11 | + * specific language governing permissions and limitations under the License. |
| 12 | + */ |
| 13 | +package org.conductoross.conductor.scheduler.sqlite.service; |
| 14 | + |
| 15 | +import javax.sql.DataSource; |
| 16 | + |
| 17 | +import org.conductoross.conductor.scheduler.dao.SchedulerDAO; |
| 18 | +import org.conductoross.conductor.scheduler.service.AbstractSchedulerServiceIntegrationTest; |
| 19 | +import org.conductoross.conductor.scheduler.sqlite.dao.SqliteSchedulerDAO; |
| 20 | +import org.flywaydb.core.Flyway; |
| 21 | +import org.junit.runner.RunWith; |
| 22 | +import org.springframework.beans.factory.annotation.Autowired; |
| 23 | +import org.springframework.boot.autoconfigure.flyway.FlywayAutoConfiguration; |
| 24 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 25 | +import org.springframework.boot.test.context.SpringBootTest; |
| 26 | +import org.springframework.boot.test.context.TestConfiguration; |
| 27 | +import org.springframework.context.annotation.Bean; |
| 28 | +import org.springframework.context.annotation.DependsOn; |
| 29 | +import org.springframework.test.context.ContextConfiguration; |
| 30 | +import org.springframework.test.context.TestPropertySource; |
| 31 | +import org.springframework.test.context.junit4.SpringRunner; |
| 32 | + |
| 33 | +import com.netflix.conductor.common.config.ObjectMapperProvider; |
| 34 | + |
| 35 | +import com.fasterxml.jackson.databind.ObjectMapper; |
| 36 | + |
| 37 | +/** |
| 38 | + * Runs the full {@link AbstractSchedulerServiceIntegrationTest} suite against an in-memory SQLite |
| 39 | + * database — no Docker required. |
| 40 | + * |
| 41 | + * <p>SQLite uses a connection pool of 1 because in-memory databases are connection-scoped. The |
| 42 | + * concurrency test in the abstract class still passes: concurrent service calls serialize through |
| 43 | + * HikariCP, verifying correctness (not parallelism). |
| 44 | + * |
| 45 | + * <p>No test logic lives here — all tests are inherited from the abstract class. |
| 46 | + */ |
| 47 | +@ContextConfiguration( |
| 48 | + classes = { |
| 49 | + DataSourceAutoConfiguration.class, |
| 50 | + FlywayAutoConfiguration.class, |
| 51 | + SqliteSchedulerServiceIntegrationTest.SqliteTestConfiguration.class |
| 52 | + }) |
| 53 | +@RunWith(SpringRunner.class) |
| 54 | +@SpringBootTest |
| 55 | +@TestPropertySource( |
| 56 | + properties = { |
| 57 | + "spring.datasource.url=jdbc:sqlite::memory:", |
| 58 | + "spring.datasource.driver-class-name=org.sqlite.JDBC", |
| 59 | + "spring.datasource.hikari.maximum-pool-size=1", |
| 60 | + "spring.datasource.hikari.minimum-idle=1", |
| 61 | + "spring.flyway.enabled=false" |
| 62 | + }) |
| 63 | +public class SqliteSchedulerServiceIntegrationTest |
| 64 | + extends AbstractSchedulerServiceIntegrationTest { |
| 65 | + |
| 66 | + @TestConfiguration |
| 67 | + static class SqliteTestConfiguration { |
| 68 | + |
| 69 | + @Bean |
| 70 | + public ObjectMapper objectMapper() { |
| 71 | + return new ObjectMapperProvider().getObjectMapper(); |
| 72 | + } |
| 73 | + |
| 74 | + @Bean(initMethod = "migrate") |
| 75 | + public Flyway flywayForScheduler(DataSource dataSource) { |
| 76 | + return Flyway.configure() |
| 77 | + .locations("classpath:db/migration_scheduler_sqlite") |
| 78 | + .dataSource(dataSource) |
| 79 | + .table("flyway_schema_history_scheduler") |
| 80 | + .outOfOrder(true) |
| 81 | + .baselineOnMigrate(true) |
| 82 | + .baselineVersion("0") |
| 83 | + .mixed(true) |
| 84 | + .load(); |
| 85 | + } |
| 86 | + |
| 87 | + @Bean |
| 88 | + @DependsOn("flywayForScheduler") |
| 89 | + public SchedulerDAO schedulerDAO(DataSource dataSource, ObjectMapper objectMapper) { |
| 90 | + return new SqliteSchedulerDAO(dataSource, objectMapper); |
| 91 | + } |
| 92 | + } |
| 93 | + |
| 94 | + @Autowired private SchedulerDAO schedulerDAO; |
| 95 | + @Autowired private DataSource dataSource; |
| 96 | + |
| 97 | + @Override |
| 98 | + protected SchedulerDAO dao() { |
| 99 | + return schedulerDAO; |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + protected DataSource dataSource() { |
| 104 | + return dataSource; |
| 105 | + } |
| 106 | +} |
0 commit comments