2014-03-24 1 views
1

최대 절전 모드를 통해 MySQL 데이터베이스에 연결된 Java 응용 프로그램이 있습니다.최대 절전 모드 테스트가 완료되지 않았습니다.

데이터베이스 연결 테스트를위한 테스트를 작성했지만 끝내지는 않습니다. 두 개의 스레드가 실행 중이지만 테스트에서 작성한 모든 코드가 실행됩니다. 두 스레드는 다음과 같습니다

Thread [pool-1-thread-1] (Running) 
Thread [DestroyJavaVM] (Running)  

는 IS 다음 내 testfile 위 :

Vote v1 = new Vote(0, "abc"); 
Vote v2 = new Vote(1, "def"); 
Candidate c1 = new Candidate(0, "First Candidate"); 
Timestamp t = new Timestamp(0, 123456l); 

EntityManager entMgr = EntityManagerUtil.getEntityManagerFactory().createEntityManager(); 
EntityTransaction transaction = entMgr.getTransaction(); 
transaction.begin(); 

VoteRepository vr = new VoteRepository(entMgr); 
entMgr.persist(v1); 
entMgr.persist(v2); 

CandidateRepository cr = new CandidateRepository(entMgr); 
entMgr.persist(c1); 

TimestampRepository tr = new TimestampRepository(entMgr); 
entMgr.persist(t); 

transaction.commit(); 
entMgr.close(); 

내의 persistence.xml은 다음과 같습니다

<provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> 
    <!-- This is where we tell JPA/Hibernate about our @Entity objects --> 
    <class>org.evoting.database.entities.Candidate</class> 
    <class>org.evoting.database.entities.Timestamp</class> 
    <class>org.evoting.database.entities.Vote</class> 

<properties> 
    <property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" /> 
    <property name="javax.persistence.jdbc.url" value="jdbc:mysql://url" /> 
    <property name="javax.persistence.jdbc.user" value="***" /> 
    <property name="javax.persistence.jdbc.password" value="***" /> 
    <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" /> 

    <!-- Update the database schema on startup: "update"; "validate" to only check --> 
    <property name="hibernate.hbm2ddl.auto" value="update" /> 

    <!-- Echo all executed SQL to stdout --> 
    <property name="hibernate.show_sql" value="true" /> 

    <!-- Disable the second-level cache --> 
    <property name="hibernate.cache.provider_class" value="org.hibernate.cache.NoCacheProvicer" /> 

    <property name="hibernate.format_sql" value="true" /> 
    <property name="hibernate.transaction.flush_before_completion" value="true" /> 
    <property name="hibernate.connection.autocommit" value="false" /> 
    <property name="hibernate.connection.release_mode" value="after_transaction" /> 
</properties> 

어떤 테스트가 완료 결코 될 수 있습니다?

+0

게시물입니다. 테스트를 롤백으로 트랜잭션으로 선언하고 있습니까? http://stackoverflow.com/questions/4166983/how-to-rollback-a-database-transaction-when-testing-services-with-spring-in-juni – emeraldjava

+0

전체 코드를 참조하십시오. 그것은 단지 평범한 구식 방법입니다. – Prechtig

+0

일부 System.out.println ("test")을 추가해보십시오. 귀하의 방법을 통해 어떤 라인 실행이 멈추고 있는지 정확히 알 수 있습니다. – dave823

답변

0

테스트를 완료하기 위해 EntityManagerFactory를 닫아야한다는 것을 알았습니다. 그래서 그 대신

entMgr.close(); 

의 나는이 새로운 라인으로

entMgr.getEntityManagerFactory.close(); 

에게 테스트 완료를 작성해야하고 모든 사람이 시험 방법 및 클래스의 전체 코드 행복 :