Tests that use h2 in-mem db fail on Heroku

There are several tests in my Spring boot application that port perfectly on my local machine, but crash on Heroku:

org.h2.jdbc.JdbcSQLException: Exception opening port "8082" (port may be in use), cause: "java.net.BindException: Address already in use (Bind failed)" [90061-196]

Profile data source configuration test:

@Configuration
public class TestDataSourceConfiguration {
    @Bean
    @ConfigurationProperties(prefix = "spring.datasource")
    @Profile("test")
    public DataSource testDataSource() throws URISyntaxException {
        return DataSourceBuilder.create().build();
    }
}

application-test.properties: spring.datasource.url = JDBC: h2: MEM: tesdb; DB_CLOSE_DELAY = -1; DB_CLOSE_ON_EXIT = FALSE, spring.datasource.driverClassName = org.h2.Driver spring.datasource.username = ca spring.datasource.password =

spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

I know Heroku does not support h2, but it should not be here, as the application itself raises db, right?

, , - , Heroku h2, , 8082 ( , )

+4
3

- , Heroku. Eclipse , , . Heroku . h2 :

@AfterClass
public static void tearDown() throws SQLException {
    webServer.stop();
}
+3

Heroku , PORT.

, application-test.properties:

server.port=${PORT:8082}

application-test.yml:

server:
     port: ${PORT:8082}

, PORT ( ), 8082.

java.net.BindException.

+2

db will not be generated automatically unless you add this property to your properties file

spring.jpa.hibernate.ddl-auto = update
+1
source

Source: https://habr.com/ru/post/1689848/


All Articles