Skip to content

Commit

Permalink
Merge commit 'c97b744a2445281b6919628858ac3c33fde4f2a3' into version-…
Browse files Browse the repository at this point in the history
…3-1-snapshot

* commit 'c97b744a2445281b6919628858ac3c33fde4f2a3':
  Fixes Tests in context of updated hibernate version.
  Fix concurrent error in MailReceiver

# Conflicts:
#	de.micromata.mgc.jpa.spring/src/test/java/de/micromata/mgc/jpa/spring/test/SpringJpaCombinedTest.java
@ignore (Junit4) -> Disabled (JUnit 5).
  • Loading branch information
kreinhard committed Jul 18, 2019
2 parents b5355eb + c97b744 commit 27f9427
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,14 @@ public synchronized List<ReceivedMail> getNewMessages(SearchTerm searchTerm, boo
return mails;
}
// TODO RK check valid
List<ReceivedMail> allMails = new ArrayList<>();
try (MailAccount mailAccount = new MailAccount(cfg)) {
// If mark messages as seen is set then open mbox read-write.
boolean connected = mailAccount.connect("INBOX", markRecentMailsAsSeen);
mails = mailAccount.getMails(searchTerm);

for (ReceivedMail mail : mails) {
// allMails.add(mail);
ReceivedMail entry = new ReceivedMail();
entry.setDate(mail.getDate());
String content = mail.getContent();
Expand Down Expand Up @@ -141,7 +144,7 @@ public synchronized List<ReceivedMail> getNewMessages(SearchTerm searchTerm, boo
} catch (IOException ex) {
log.fatal("Exception encountered " + ex, ex);
}
mails.add(entry);
allMails.add(entry);
if (markRecentMailsAsSeen == true) {
try {
mail.getMessage().setFlag(Flags.Flag.SEEN, true);
Expand All @@ -153,7 +156,7 @@ public synchronized List<ReceivedMail> getNewMessages(SearchTerm searchTerm, boo
// log.info(mail);
}

return mails;
return allMails;
}
}

Expand Down
6 changes: 6 additions & 0 deletions de.micromata.mgc.jpa.spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@
<version>${hsqldb.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1211.jre7</version>
<scope>test</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import de.micromata.mgc.jpa.spring.test.entities.MyUserDO;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -114,6 +113,10 @@ public void testNestedEx()
}

@Disabled
/**
* see comments below in the code. THIS will not working, because spring tx and jpa client tx (which will be used in
* runInTrans()) are not the same.
*/
public void testNestedEx2()
{
MyUserDO user = new MyUserDO();
Expand All @@ -123,6 +126,12 @@ public void testNestedEx2()
Holder<Long> insertedSkillPk = new Holder<>();

long newUserPk = testSpringService.doWithNewUser("testNestedEx2", (myUser) -> {
// this not work, because transaction doWithNewUser is not committed yet.
// with postresql you get:
// Caused by: org.postgresql.util.PSQLException: FEHLER: Einfügen oder Aktualisieren in Tabelle »myskilldo« verletzt Fremdschlüssel-Constraint »fk8afdmj4cc7497pin1ph713qau«
// Detail: Schlüssel (user_pk)=(12) ist nicht in Tabelle »myuserdo« vorhanden.
// at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2458)\
// with derby simply hang on a lock
SpringJpaEmgrFactory.get().runInTrans((emgr) -> {
MySkillDO mskill = new MySkillDO();
mskill.setName("Coden");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@

package de.micromata.mgc.jpa.spring.test;

import javax.persistence.PersistenceContext;
import javax.transaction.Transactional;
import javax.transaction.Transactional.TxType;

import org.hibernate.Session;
import org.springframework.beans.factory.annotation.Autowired;

import de.micromata.mgc.jpa.spring.test.entities.MySkillDO;
import de.micromata.mgc.jpa.spring.test.entities.MyUserDO;

public class TestSpringService
{
@Autowired
@PersistenceContext
Session hibernateSession;

@Transactional(value = TxType.REQUIRES_NEW)
Expand All @@ -49,7 +49,7 @@ public MyUserDO loadUser(Long pk)
{
return hibernateSession.load(MyUserDO.class, pk);
}

@Transactional()
public Long storeSkill(MySkillDO skill)
{
hibernateSession.persist(skill);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.2.xsd">

<context:annotation-config />
<tx:annotation-driven />

<bean id="sessionFactory" class="de.micromata.mgc.jpa.spring.test.TestJpaToSessionFactorySpringBeanFactory"/>

<bean id="emfBean" class="de.micromata.mgc.jpa.spring.test.SpringJpaEmgrFactory" factory-method="getMyEntityManagerFactory"/>
<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emfBean">

</property>
</bean>

<bean id="testSpringService" class="de.micromata.mgc.jpa.spring.test.TestSpringService"/>
<bean id="hibernateSession" class="de.micromata.mgc.jpa.spring.factories.JpaToSessionSpringBeanFactory"/>

<context:annotation-config />
<tx:annotation-driven />


<bean id="emfBean"
class="de.micromata.mgc.jpa.spring.test.SpringJpaEmgrFactory"
factory-method="getMyEntityManagerFactory" />
<bean id="transactionManager"
class="org.springframework.orm.jpa.JpaTransactionManager">
<property name="entityManagerFactory" ref="emfBean">

</property>
</bean>

<bean id="testSpringService"
class="de.micromata.mgc.jpa.spring.test.TestSpringService" />
<bean id="hibernateSession"
class="de.micromata.mgc.jpa.spring.factories.JpaToSessionSpringBeanFactory" />
</beans>

0 comments on commit 27f9427

Please sign in to comment.