Skip to content
Browse files

Test to prove that one feed failing to load doesn't stop the others f…

…rom been processed.
  • Loading branch information...
1 parent 0eb7c07 commit 441106aec3da2cc7acca2386986535aee9bedcda @tonytw1 committed
View
5 src/main/java/nz/gen/wellington/rsstotwitter/feeds/FeedDAO.java
@@ -23,12 +23,13 @@
@SuppressWarnings("unchecked")
public List<FeedItem> loadFeedItems(Feed feed) {
+ List<FeedItem> feedItems = new ArrayList<FeedItem>();
SyndFeed syndfeed = loadSyndFeedWithFeedFetcher(feed.getUrl());
if (syndfeed == null) {
- log.warn("Could not load syndfeed from url: " + feed.getUrl());
+ log.warn("Could not load syndfeed from url: " + feed.getUrl() + ". Returning empty list of items");
+ return null;
}
- List<FeedItem> feedItems = new ArrayList<FeedItem>();
Iterator<SyndEntry> feedItemsIterator = syndfeed.getEntries().iterator();
while (feedItemsIterator.hasNext()) {
SyndEntry feedItem = (SyndEntry) feedItemsIterator.next();
View
1 src/main/java/nz/gen/wellington/rsstotwitter/twitter/TwitterUpdater.java
@@ -34,6 +34,7 @@ public TwitterUpdater(TwitterHistoryDAO twitterHistoryDAO, TwitterService twitte
}
public void updateFeed(List<FeedItem> feedItems, TwitterAccount account, String tag) {
+ log.info("Calling update feed for account '" + account.getUsername() + "' with " + feedItems.size() + " feed items");
Feed feed = feedItems.get(0).getFeed(); // TODO Meh - drops out when we move to account rate limiting.
int tweetsSent = twitterHistoryDAO.getNumberOfTwitsInLastTwentyFourHours(feed); // TODO rate limit should really be about the twitter account, not the feed.
if (hasExceededFeedRateLimit(tweetsSent)) {
View
21 src/test/java/nz/gen/wellington/rsstotwitter/timers/UpdateServiceTest.java
@@ -24,6 +24,7 @@
private static final String TWITTER_USERNAME = "testuser";
private static final String FEED_URL = "http://localhost/rss";
+ private static final String SECOND_FEED_URL = "http://localhost/2/rss";
@Mock FeedToTwitterJobDAO tweetFeedJobDAO;
@Mock FeedDAO feedDAO;
@@ -34,8 +35,11 @@
private List<FeedToTwitterJob> feedToTwitterJobs;
Feed feed;
- @Mock List<FeedItem> feedItems;
+ Feed secondFeed;
TwitterAccount account;
+ TwitterAccount secondAccount;
+ @Mock List<FeedItem> feedItems;
+ @Mock private List<FeedItem> secondFeedItems;
private String tag;
@Before
@@ -46,7 +50,11 @@ public void setUp() throws Exception {
feed = new Feed(FEED_URL);
account = new TwitterAccount(1, TWITTER_USERNAME);
+ secondFeed = new Feed(SECOND_FEED_URL);
+ secondAccount = new TwitterAccount(2, TWITTER_USERNAME);
feedToTwitterJobs.add(new FeedToTwitterJob(feed, account, tag));
+ feedToTwitterJobs.add(new FeedToTwitterJob(secondFeed, secondAccount, tag));
+
when(tweetFeedJobDAO.getAllTweetFeedJobs()).thenReturn(feedToTwitterJobs);
}
@@ -65,8 +73,17 @@ public void shouldGracefullyDoNothingIfFeedFailsToLoad() throws Exception {
service.run();
- verify(feedDAO).loadFeedItems(feed);
verifyNoMoreInteractions(twitterUpdater);
}
+
+ @Test
+ public void shouldContinueProcessingRemainingFeedsIfOneFailsToLoad() throws Exception {
+ when(feedDAO.loadFeedItems(feed)).thenReturn(null);
+ when(feedDAO.loadFeedItems(secondFeed)).thenReturn(secondFeedItems);
+
+ service.run();
+
+ verify(twitterUpdater).updateFeed(secondFeedItems, secondAccount, tag);
+ }
}

0 comments on commit 441106a

Please sign in to comment.
Something went wrong with that request. Please try again.