Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random failure in WordContributionEventDaoTest #1646

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions src/test/java/ai/elimu/dao/WordContributionEventDaoTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class WordContributionEventDaoTest {

@Test
public void testReadMostRecent() {
logger.info("testReadMostRecent");
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecent(10);
int numberOfWordContributionEventsBefore = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore);

Contributor contributor = new Contributor();
contributorDao.create(contributor);
Expand All @@ -56,13 +58,16 @@ public void testReadMostRecent() {

wordContributionEvents = wordContributionEventDao.readMostRecent(10);
int numberOfWordContributionEventsAfter = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter);
assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 1));
}

@Test
public void testReadMostRecentPerWord() {
logger.info("testReadMostRecentPerWord");
List<WordContributionEvent> wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
int numberOfWordContributionEventsBefore = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsBefore: " + numberOfWordContributionEventsBefore);

Contributor contributor = new Contributor();
contributorDao.create(contributor);
Expand All @@ -80,7 +85,9 @@ public void testReadMostRecentPerWord() {
wordContributionEventDao.create(wordContributionEvent2);

wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 1));
int numberOfWordContributionEventsAfter = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter);
assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 1));

Word word3 = new Word();
word3.setText("word3");
Expand All @@ -95,7 +102,9 @@ public void testReadMostRecentPerWord() {
wordContributionEventDao.create(wordContributionEvent3);

wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 2));
numberOfWordContributionEventsAfter = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter);
assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 2));

// Re-use a word (word3) that was used in a previous contribution event
WordContributionEvent wordContributionEvent4 = new WordContributionEvent();
Expand All @@ -106,8 +115,10 @@ public void testReadMostRecentPerWord() {
wordContributionEvent4.setTimeSpentMs(10_000L);
wordContributionEventDao.create(wordContributionEvent4);

// The number of contribution events returned should not increase
// The number of contribution events returned should remain the same (since word3 was used twice)
wordContributionEvents = wordContributionEventDao.readMostRecentPerWord();
assertThat(wordContributionEvents.size(), is(numberOfWordContributionEventsBefore + 2));
numberOfWordContributionEventsAfter = wordContributionEvents.size();
logger.info("numberOfWordContributionEventsAfter: " + numberOfWordContributionEventsAfter);
assertThat(numberOfWordContributionEventsAfter, is(numberOfWordContributionEventsBefore + 2));
}
}
2 changes: 1 addition & 1 deletion src/test/resources/jdbc.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
jpa.database=HSQL
jpa.databasePlatform=org.hibernate.dialect.HSQLDialect
jpa.generateDdl=true
jpa.showSql=true
jpa.showSql=false

# JDBC Settings
jdbc.driverClassName=org.hsqldb.jdbcDriver
Expand Down
Loading