2017-12-01 15 views
3

테스트 목적으로 만 h2 메모리 내 데이터베이스를 사용합니다. 기본 포트가 8082 인 것 같습니다. 이로 인해 내 테스트가 영웅에게 실패합니다.임베디드 h2 데이터베이스의 포트 번호 설정

이 포트 번호를 변경하고 싶습니다. 어떻게해야합니까? 내가 지금까지했던 어떤

는 :

  1. 이 포트를 지정하는 내 로컬 컴퓨터 ($USER_HOME/.h2.server.properties)에서 파일을 것으로 보인다. 그 파일을 응용 프로그램 작업 영역 밖에 두는 것은 매우 이상한 일이지만, 나는 heroku에서 검사 할 수 없습니다. ,

  2. 나는 application-test.properties에서 port (그것이 프로퍼티 내 테스트를 위해 사용하는 파일), webPort을 설정하려고하지만 내가 다른 조합 server.port,`spring.data.source.h2.webPort 시도 (작동하지 않았다 등)

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=sa 
spring.datasource.password= 
spring.datasource.testWhileIdle = true 
spring.datasource.validationQuery = SELECT 1 

build.gradle을 application-test.properties

buildscript { 
    repositories { 
     mavenCentral() 
    } 
    dependencies { 
     classpath("org.springframework.boot:spring-boot-gradle-plugin:1.5.8.RELEASE") 
    } 
} 

apply plugin: 'java' 

sourceCompatibility = 1.8 
targetCompatibility = 1.8 
tasks.withType(JavaCompile) { 
    options.encoding = 'UTF-8' 
} 

test{ 

    forkEvery = 1 
    testLogging { 
     showStandardStreams = true 
    } 
} 

repositories { 
    maven { url "http://repo.maven.apache.org/maven2" } 
} 

dependencies { 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version:'1.5.8.RELEASE' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version:'1.5.8.RELEASE' 
    compile group: 'mysql', name: 'mysql-connector-java', version:'5.1.44' 
    compile group: 'org.javassist', name: 'javassist', version:'3.18.0-GA' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-security', version:'1.5.8.RELEASE' 
    compile group: 'org.springframework.security.oauth', name: 'spring-security-oauth2', version:'2.0.14.RELEASE' 
    compile group: 'org.springframework.boot', name: 'spring-boot-configuration-processor', version:'1.5.8.RELEASE' 
    compile group: 'io.jsonwebtoken', name: 'jjwt', version:'0.7.0' 
    compile group: 'org.springframework.security', name: 'spring-security-cas', version:'4.2.3.RELEASE' 
    compile group: 'org.springframework.security', name: 'spring-security-acl', version:'4.2.3.RELEASE' 
    compile group: 'bsf', name: 'bsf', version:'2.4.0' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-batch', version:'1.5.8.RELEASE' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-actuator', version:'1.5.8.RELEASE' 
    compile group: 'org.springframework.security', name: 'spring-security-ldap', version:'4.2.3.RELEASE' 
    compile group: 'javax.jdo', name: 'jdo-api', version:'3.0.1' 
    compile group: 'com.querydsl', name: 'querydsl-core', version:'4.1.4' 
    compile group: 'org.springframework', name: 'springloaded', version:'1.2.8.RELEASE' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-rest', version:'1.5.8.RELEASE' 
    compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib', version:'1.0.6' 
    compile group: 'org.scala-lang', name: 'scala-library', version:'2.11.0' 
    compile group: 'commons-validator', name: 'commons-validator', version:'1.6' 
    compile group: 'commons-io', name: 'commons-io', version:'2.5' 
    compile group: 'org.springframework.boot', name: 'spring-boot-starter-jersey', version:'1.5.8.RELEASE' 
    compile group: 'org.modelmapper', name: 'modelmapper', version:'0.7.5' 
    compile(group: 'org.apache.httpcomponents', name: 'httpclient', version:'4.5.3') { 
exclude(module: 'commons-logging') 
    } 
    compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.4' 
    compile(group: 'org.springframework.boot', name: 'spring-boot-starter-test', version:'1.5.8.RELEASE') { 
exclude(module: 'commons-logging') 
    } 
    compile group: 'org.eclipse.jetty.aggregate', name: 'jetty-all', version:'9.2.13.v20150730' 
    compile group: 'com.h2database', name: 'h2', version:'1.4.196' 
    compile group: 'org.springframework.integration', name: 'spring-integration-test', version:'4.3.12.RELEASE' 
    compile group: 'org.springframework.security', name: 'spring-security-test', version:'4.2.3.RELEASE' 
    compile group: 'org.apache.hadoop', name: 'hadoop-core', version:'1.0.0' 
    compile group: 'com.sleepycat', name: 'je', version:'5.0.73' 
    compile group: 'commons-dbcp', name: 'commons-dbcp', version:'1.4' 
    compile group: 'org.springframework', name: 'spring-webmvc', version:'4.3.12.RELEASE' 
    compile group: 'org.springframework.data', name: 'spring-data-commons', version:'1.13.8.RELEASE' 
    compile group: 'org.springframework.hateoas', name: 'spring-hateoas', version:'0.23.0.RELEASE' 
    compile group: 'org.springframework.data', name: 'spring-data-rest-core', version:'2.6.8.RELEASE' 
    compile group: 'org.springframework.plugin', name: 'spring-plugin-core', version:'1.2.0.RELEASE' 
    compile group: 'org.springframework', name: 'spring-orm', version:'4.3.12.RELEASE' 
    testCompile group: 'junit', name: 'junit', version:'4.11' 
    testCompile group: 'org.springframework', name: 'spring-test', version:'4.3.12.RELEASE' 
} 
+0

JDBC-URL에는 소켓이나 포트가 필요없는 연결 문자열을 포함 할 수 있습니다. 따라서 테스트 목적으로 완벽합니다. jdbc-connection-url의 예를 들어주십시오. –

+0

어떻게 h2 서버를 시작 하시겠습니까? 다른 응용 프로그램에서 데이터베이스에 연결할 필요가 없다면 왜 tcp 서버를 시작해야합니까? 나머지 데이터베이스 관련 구성은 무엇입니까? – Oleg

+0

'8082'는 h2console webServer에서 사용하는 포트입니다. 스프링 부트는 그것을 사용하지 않습니다. 당신은 그것을 시작하거나 자신을 어디서든지'Server.createWebServer'로 시작하는 bean을 가지게됩니다. 포트를 변경해도 도움이되지 않으며, 오직 한 개의 포트 만 영웅에게 사용할 수 있습니다. – Oleg

답변

0

해결책을 찾았습니다. 이전에 테스트 용 기본 클래스를 만들었습니다. 여기에서 H2 서버를 만듭니다. 포트는 같은 클래스에 설정되었습니다.

@BeforeClass 
public static void init() throws SQLException { 
    webServer = Server.createWebServer("-web", "-webAllowOthers", "-webPort", "8082"); 
    webServer.start(); 
} 

그러나 포트를 변경해도 문제가 해결되지 않습니다. eclipse가 각 테스트를 개별적으로 실행하는 것과는 달리 heroku는 모든 테스트를 한 번 실행하므로 서버가 파괴되지 않고 두 번의 테스트 사이에 유지됩니다. 따라서 각 테스트 클래스가 끝나면 서버를 종료해야합니다.

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

왜 테스트를 위해 웹 서버가 필요합니까 ??? – Oleg

+0

엔드 - 투 - 엔드 테스트입니다. –