Skip to content

Adjust h2 schema to work with v2.0.x #4043

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
<commons-dbcp2.version>2.9.0</commons-dbcp2.version>
<slf4j.version>1.7.32</slf4j.version>
<hsqldb.version>2.6.1</hsqldb.version>
<h2.version>1.4.200</h2.version>
<h2.version>2.0.206</h2.version>
<sqlite.version>3.36.0.3</sqlite.version>
<derby.version>10.14.2.0</derby.version>
<artemis.version>2.19.0</artemis.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-- Autogenerated: do not edit this file

CREATE TABLE BATCH_JOB_INSTANCE (
JOB_INSTANCE_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
JOB_INSTANCE_ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,
VERSION BIGINT ,
JOB_NAME VARCHAR(100) NOT NULL,
JOB_KEY VARCHAR(32) NOT NULL,
constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
) ;

CREATE TABLE BATCH_JOB_EXECUTION (
JOB_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
JOB_EXECUTION_ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,
VERSION BIGINT ,
JOB_INSTANCE_ID BIGINT NOT NULL,
CREATE_TIME TIMESTAMP NOT NULL,
Expand Down Expand Up @@ -37,7 +37,7 @@ CREATE TABLE BATCH_JOB_EXECUTION_PARAMS (
) ;

CREATE TABLE BATCH_STEP_EXECUTION (
STEP_EXECUTION_ID BIGINT IDENTITY NOT NULL PRIMARY KEY ,
STEP_EXECUTION_ID BIGINT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY ,
VERSION BIGINT NOT NULL,
STEP_NAME VARCHAR(100) NOT NULL,
JOB_EXECUTION_ID BIGINT NOT NULL,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
/*
* Copyright 2022 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
*
* https://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.batch.core.test.repository;

import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import javax.sql.DataSource;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;

import org.springframework.batch.core.ExitStatus;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
import org.springframework.batch.core.configuration.annotation.JobBuilderFactory;
import org.springframework.batch.core.configuration.annotation.StepBuilderFactory;
import org.springframework.batch.core.launch.JobLauncher;
import org.springframework.batch.repeat.RepeatStatus;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.DefaultResourceLoader;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.datasource.SimpleDriverDataSource;
import org.springframework.jdbc.datasource.init.DatabasePopulatorUtils;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;

/**
* @author Henning Pöttker
*/
@RunWith(Parameterized.class)
public class H2CompatibilityModeJobRepositoryIntegrationTests {

private final String compatibilityMode;

public H2CompatibilityModeJobRepositoryIntegrationTests(String compatibilityMode) {
this.compatibilityMode = compatibilityMode;
}

@Test
public void testJobExecution() throws Exception {
var context = new AnnotationConfigApplicationContext();
context.register(TestConfiguration.class);
context.registerBean(DataSource.class, this::buildDataSource);
context.refresh();
var jobLauncher = context.getBean(JobLauncher.class);
var job = context.getBean(Job.class);

var jobExecution = jobLauncher.run(job, new JobParameters());

Assert.assertNotNull(jobExecution);
Assert.assertEquals(ExitStatus.COMPLETED, jobExecution.getExitStatus());

var jdbcTemplate = new JdbcTemplate(context.getBean(DataSource.class));
jdbcTemplate.execute("SHUTDOWN");
}

private DataSource buildDataSource() {
var connectionUrl = String.format(
"jdbc:h2:mem:%s;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false;MODE=%s",
UUID.randomUUID(),
this.compatibilityMode
);
var dataSource = new SimpleDriverDataSource(new org.h2.Driver(), connectionUrl, "sa", "");
var populator = new ResourceDatabasePopulator();
var resource = new DefaultResourceLoader()
.getResource("/org/springframework/batch/core/schema-h2.sql");
populator.addScript(resource);
DatabasePopulatorUtils.execute(populator, dataSource);
return dataSource;
}

@Configuration
@EnableBatchProcessing
static class TestConfiguration {
@Bean
Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
return jobs.get("job")
.start(steps.get("step")
.tasklet((contribution, chunkContext) -> RepeatStatus.FINISHED)
.build())
.build();
}
}

@Parameters
public static List<Object[]> data() throws Exception {
return Arrays.stream(org.h2.engine.Mode.ModeEnum.values())
.map(mode -> new Object[]{mode.toString()})
.toList();
}
}