diff --git a/adapters/jdbc/src/test/java/org/atomhopper/jdbc/query/SqlBuilderTest.java b/adapters/jdbc/src/test/java/org/atomhopper/jdbc/query/SqlBuilderTest.java index 7ea2ef3f3..16e66b6e9 100644 --- a/adapters/jdbc/src/test/java/org/atomhopper/jdbc/query/SqlBuilderTest.java +++ b/adapters/jdbc/src/test/java/org/atomhopper/jdbc/query/SqlBuilderTest.java @@ -49,7 +49,11 @@ public static class WhenCallingSearchSql { private String result_next_with_cats_and_prefix = "(SELECT * FROM entries WHERE feed = ? AND datelastupdated = ? AND id < ? AND( categories @> ?::varchar[] AND tenantId = ? )) UNION ALL (SELECT * FROM entries WHERE feed = ? AND datelastupdated < ? AND( categories @> ?::varchar[] AND tenantId = ? )ORDER BY datelastupdated DESC, id DESC LIMIT 1) ORDER BY datelastupdated DESC, id DESC LIMIT 1"; private String result_next_with_cats_not_prefix = "(SELECT * FROM entries WHERE feed = ? AND datelastupdated = ? AND id < ? AND NOT ( categories @> ?::varchar[] AND tenantId = ? )) UNION ALL (SELECT * FROM entries WHERE feed = ? AND datelastupdated < ? AND NOT ( categories @> ?::varchar[] AND tenantId = ? )ORDER BY datelastupdated DESC, id DESC LIMIT 1) ORDER BY datelastupdated DESC, id DESC LIMIT 1"; private String result_next_with_cats_or_prefix = "(SELECT * FROM entries WHERE feed = ? AND datelastupdated = ? AND id < ? AND( categories @> ?::varchar[] OR tenantId = ? )) UNION ALL (SELECT * FROM entries WHERE feed = ? AND datelastupdated < ? AND( categories @> ?::varchar[] OR tenantId = ? )ORDER BY datelastupdated DESC, id DESC LIMIT 1) ORDER BY datelastupdated DESC, id DESC LIMIT 1"; - + private String result_forward_feed_delay = "(SELECT * FROM entries WHERE feed = ? AND datelastupdated = ? AND id > ? AND datelastupdated < now() - interval '1 seconds' ) UNION ALL (SELECT * FROM entries WHERE feed = ? AND datelastupdated > ? AND datelastupdated < now() - interval '1 seconds' ORDER BY datelastupdated ASC, id ASC LIMIT ?) ORDER BY datelastupdated ASC, id ASC LIMIT ?"; + private String result_head_feed_delay = "SELECT * FROM entries WHERE feed = ? AND datelastupdated < now() - interval '1 seconds' ORDER BY datelastupdated DESC, id DESC LIMIT ?"; + private String result_last_feed_delay = "SELECT * FROM entries WHERE feed = ? AND datelastupdated < now() - interval '1 seconds' ORDER BY datelastupdated ASC, id ASC LIMIT ?"; + + private DateTimeFormatter isoDTF = ISODateTimeFormat.dateTime(); private Map map; @@ -74,6 +78,17 @@ public void ShouldGetSqlForForward() throws Exception { Assert.assertEquals(result_forward, result); } + + @Test + public void ShouldGetSqlForForwardwithFeedDelay() throws Exception { + + SearchToSqlConverter searchToSqlConverter = new SearchToSqlConverter( map, PREFIX_SPLIT ); + String result = new SqlBuilder( searchToSqlConverter ) + .searchType(SearchType.FEED_FORWARD).feedHeadDelayInSeconds(1) + .toString(); + + Assert.assertEquals(result_forward_feed_delay, result); + } @Test public void ShouldGetSqlForBackward() throws Exception { @@ -96,6 +111,17 @@ public void ShouldGetSqlForHead() throws Exception { Assert.assertEquals(result_head, result); } + + @Test + public void ShouldGetSqlForHeadwithFeedDelay() throws Exception { + SearchToSqlConverter searchToSqlConverter = new SearchToSqlConverter( map, PREFIX_SPLIT ); + + String result = new SqlBuilder( searchToSqlConverter ) + .searchType( SearchType.FEED_HEAD ).feedHeadDelayInSeconds(1) + .toString(); + + Assert.assertEquals(result_head_feed_delay, result); + } @Test public void ShouldGetSqlForLast() throws Exception { @@ -107,6 +133,17 @@ public void ShouldGetSqlForLast() throws Exception { Assert.assertEquals(result_last, result); } + + @Test + public void ShouldGetSqlForLastWithFeedDelay() throws Exception { + SearchToSqlConverter searchToSqlConverter = new SearchToSqlConverter( map, PREFIX_SPLIT ); + + String result = new SqlBuilder( searchToSqlConverter ) + .searchType( SearchType.LAST_PAGE ).feedHeadDelayInSeconds(1) + .toString(); + + Assert.assertEquals(result_last_feed_delay, result); + } @Test public void ShouldGetSqlForNext() throws Exception { @@ -396,5 +433,22 @@ public void shouldGetSelectWithTimestamp() throws Exception { Assert.assertTrue("result string has timezone", result.contains("current_setting('TIMEZONE')")); Assert.assertTrue("result string has correct time", result.contains(timestamp)); } + + @Test + public void shouldGetSelectWithTimestampWithFeedDelay() throws Exception { + String startingTimestamp = "2014-03-03T08:51:32.000Z"; + DateTime startAt = isoDTF.parseDateTime(startingTimestamp); + SearchToSqlConverter searchToSqlConverter = new SearchToSqlConverter( map, PREFIX_SPLIT ); + + String result = new SqlBuilder( searchToSqlConverter ) + .searchType( SearchType.BY_TIMESTAMP_BACKWARD ) + .startingTimestamp(startAt).feedHeadDelayInSeconds(1) + .toString(); + + String timestamp = startAt.getHourOfDay() + ":" + startAt.getMinuteOfHour() + ":" + startAt.getSecondOfMinute(); + Assert.assertTrue("result string has timezone", result.contains("current_setting('TIMEZONE')")); + Assert.assertTrue("result string has correct time", result.contains(timestamp)); + } + } }