Skip to content

Commit

Permalink
Refine contribution #595
Browse files Browse the repository at this point in the history
- Update versions of jdbc driver and docker image
- Update Javadocs
- Remove JOB_CONFIGURATION_LOCATION from DDL schema
- Remove unused resources
  • Loading branch information
fmbenhassine committed Mar 18, 2022
1 parent 9388abb commit 968a5b5
Show file tree
Hide file tree
Showing 15 changed files with 134 additions and 164 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
<h2.version>2.1.210</h2.version>
<sqlite.version>3.36.0.3</sqlite.version>
<derby.version>10.14.2.0</derby.version>
<hana.version>2.9.12</hana.version>
<hana.version>2.11.17</hana.version>
<artemis.version>2.20.0</artemis.version>
<jaxb-core.version>3.0.2</jaxb-core.version>
<log4j.version>2.17.2</log4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ CREATE TABLE BATCH_JOB_EXECUTION (
EXIT_CODE VARCHAR(2500) ,
EXIT_MESSAGE VARCHAR(2500) ,
LAST_UPDATED TIMESTAMP,
JOB_CONFIGURATION_LOCATION VARCHAR(2500) ,
constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID)
references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
) ;
Expand Down
14 changes: 0 additions & 14 deletions spring-batch-core/src/main/sql/hana.properties

This file was deleted.

3 changes: 0 additions & 3 deletions spring-batch-core/src/main/sql/hana.vpp

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2020-2021 the original author or authors.
* 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.
Expand All @@ -15,11 +15,21 @@
*/
package org.springframework.batch.core.test.repository;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import javax.sql.DataSource;

import com.github.dockerjava.api.model.Ulimit;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.batch.core.ExitStatus;
Expand All @@ -38,19 +48,30 @@
import org.springframework.core.io.ClassPathResource;
import org.springframework.jdbc.datasource.init.ResourceDatabasePopulator;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit.jupiter.EnabledIf;
import org.springframework.test.context.junit4.SpringRunner;

import org.testcontainers.containers.JdbcDatabaseContainer;
import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy;
import org.testcontainers.utility.DockerImageName;

import com.sap.db.jdbcext.HanaDataSource;
import org.testcontainers.utility.LicenseAcceptance;

/**
* The official Docker image for SAP HANA is not publicly available. SAP HANA support is tested manually.
* See https://hub.docker.com/_/sap-hana-express-edition/plans/f2dc436a-d851-4c22-a2ba-9de07db7a9ac
* FTR, from the previous link: "This installation does not support Docker for Windows or Docker for Mac."
*
* @author Jonathan Bregler
* @author Mahmoud Ben Hassine
*/
@RunWith(SpringRunner.class)
@ContextConfiguration
@Ignore("Official Docker image for SAP HANA not publicly available and works only on Linux")
public class HANAJobRepositoryIntegrationTests {

private static final DockerImageName HANA_IMAGE = DockerImageName.parse( "store/saplabs/hanaexpress:2.00.054.00.20210603.1" );
private static final DockerImageName HANA_IMAGE = DockerImageName.parse( "store/saplabs/hanaexpress:2.00.057.00.20211207.1" );

@ClassRule
public static HANAContainer<?> hana = new HANAContainer<>( HANA_IMAGE ).acceptLicense();
Expand Down Expand Up @@ -103,4 +124,103 @@ public Job job(JobBuilderFactory jobs, StepBuilderFactory steps) {
}

}

/**
* @author Jonathan Bregler
*/
public static class HANAContainer<SELF extends HANAContainer<SELF>> extends JdbcDatabaseContainer<SELF> {

private static final Integer PORT = 39041;

private static final String SYSTEM_USER = "SYSTEM";
private static final String SYSTEM_USER_PASSWORD = "HXEHana1";

public HANAContainer(DockerImageName image) {

super( image );

addExposedPorts( 39013, 39017, 39041, 39042, 39043, 39044, 39045, 1128, 1129, 59013, 59014 );

// create ulimits
Ulimit[] ulimits = new Ulimit[]{ new Ulimit( "nofile", 1048576L, 1048576L ) };

// create sysctls Map.
Map<String, String> sysctls = new HashMap<String, String>();

sysctls.put( "kernel.shmmax", "1073741824" );
sysctls.put( "net.ipv4.ip_local_port_range", "40000 60999" );

// Apply mounts, ulimits and sysctls.
this.withCreateContainerCmdModifier( it -> it.getHostConfig().withUlimits( ulimits ).withSysctls( sysctls ) );

// Arguments for Image.
this.withCommand( "--master-password " + SYSTEM_USER_PASSWORD + " --agree-to-sap-license" );

// Determine if container is ready.
this.waitStrategy = new LogMessageWaitStrategy().withRegEx( ".*Startup finished!*\\s" ).withTimes( 1 )
.withStartupTimeout( Duration.of( 600, ChronoUnit.SECONDS ) );
}

@Override
protected void configure() {
/*
* Enforce that the license is accepted - do not remove. License available at:
* https://www.sap.com/docs/download/cmp/2016/06/sap-hana-express-dev-agmt-and-exhibit.pdf
*/

// If license was not accepted programmatically, check if it was accepted via
// resource file
if ( !getEnvMap().containsKey( "AGREE_TO_SAP_LICENSE" ) ) {
LicenseAcceptance.assertLicenseAccepted( this.getDockerImageName() );
acceptLicense();
}
}

/**
* Accepts the license for the SAP HANA Express container by setting the AGREE_TO_SAP_LICENSE=Y Calling this method
* will automatically accept the license at:
* https://www.sap.com/docs/download/cmp/2016/06/sap-hana-express-dev-agmt-and-exhibit.pdf
*
* @return The container itself with an environment variable accepting the SAP HANA Express license
*/
public SELF acceptLicense() {
addEnv( "AGREE_TO_SAP_LICENSE", "Y" );
return self();
}

@Override
public Set<Integer> getLivenessCheckPortNumbers() {
return new HashSet<>( Arrays.asList( new Integer[]{ getMappedPort( PORT ) } ) );
}

@Override
protected void waitUntilContainerStarted() {
getWaitStrategy().waitUntilReady( this );
}

@Override
public String getDriverClassName() {
return "com.sap.db.jdbc.Driver";
}

@Override
public String getUsername() {
return SYSTEM_USER;
}

@Override
public String getPassword() {
return SYSTEM_USER_PASSWORD;
}

@Override
public String getTestQueryString() {
return "SELECT 1 FROM SYS.DUMMY";
}

@Override
public String getJdbcUrl() {
return "jdbc:sap://" + getContainerIpAddress() + ":" + getMappedPort( PORT ) + "/";
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2017-2020 the original author or authors.
* Copyright 2017-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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* 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.
Expand All @@ -23,7 +23,7 @@
* SAP HANA implementation of a {@link PagingQueryProvider} using database specific features.
*
* @author Jonathan Bregler
* @since 4.0
* @since 5.0
*/
public class HanaPagingQueryProvider extends AbstractSqlPagingQueryProvider {

Expand All @@ -35,7 +35,7 @@ public String generateFirstPageQuery(int pageSize) {
@Override
public String generateRemainingPagesQuery(int pageSize) {
if(StringUtils.hasText(getGroupClause())) {
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, true, buildLimitClause(pageSize));
return SqlPagingQueryUtils.generateLimitGroupedSqlQuery(this, buildLimitClause(pageSize));
}
else {
return SqlPagingQueryUtils.generateLimitSqlQuery(this, true, buildLimitClause(pageSize));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 the original author or authors.
* Copyright 2006-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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2021 the original author or authors.
* Copyright 2006-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.
Expand Down

0 comments on commit 968a5b5

Please sign in to comment.