// fill DB with one default tag
tagSearchTester.getSearch().bulkUpdate(Arrays.asList(new JTag("java")), tagSearchTester.getSearch().getIndexName(), true);
ElasticUserSearch userSearch = userSearchTester.getSearch();
ElasticTweetSearch tweetSearch = tweetSearchTester.getSearch();
// already existing tweets must not harm
tweetSearch.store(new JTweet(3L, "duplication tweet", new JUser("tmp")), true);
TwitterSearch tws = new TwitterSearch() {
@Override
public boolean isInitialized() {
return true;
}
@Override
public long search(String q, Collection<JTweet> result, int tweets, long lastMillis) {
JUser u = new JUser("timetabling");
JTweet tw1 = new JTweet(1L, "test", u);
result.add(tw1);
tw1 = new JTweet(2L, "java test", u);
result.add(tw1);
// this tweet will be ignored and so it won't be indexed!
tw1 = new JTweet(3L, "duplicate tweet", new JUser("anotheruser"));
result.add(tw1);
tw1 = new JTweet(4L, "reference a user: @timetabling", new JUser("user3"));
result.add(tw1);
assertEquals(4, result.size());
return lastMillis;
}
@Override
public List<JTweet> getTweets(JUser user, Collection<JUser> users, int twPerPage) {
return Collections.EMPTY_LIST;
}
};
TweetConsumer tweetConsumer = getInstance(TweetConsumer.class);
tweetConsumer.setUncaughtExceptionHandler(excHandler);
tweetConsumer.start();
TweetProducer tweetProducer = getInstance(TweetProducer.class);
tweetProducer.setTwitterSearch(tws);
tweetProducer.setUserSearch(userSearch);
tweetProducer.setTagSearch(tagSearchTester.getSearch());
tweetProducer.setQueue(tweetConsumer.register("tweet-producer", Integer.MAX_VALUE, 100));
Thread tweetProducerThread = new Thread(tweetProducer);
tweetProducerThread.setUncaughtExceptionHandler(excHandler);
tweetProducerThread.start();
Thread.sleep(500);
tweetConsumer.interrupt();
checkExceptions(exceptionMap);
tweetSearch.forceEmptyQueueAndRefresh();
Set<JUser> users = new LinkedHashSet<JUser>();
tweetSearch.query(users, new TweetQuery().addFilterQuery(ElasticTweetSearch.USER, "timetabling"));
assertEquals(2, users.iterator().next().getOwnTweets().size());
List<JUser> res = new ArrayList<JUser>();
tweetSearch.query(res, new TweetQuery("java"));
assertEquals(1, res.size());
Collection<JTweet> coll = tweetSearch.searchTweets(new TweetQuery("duplicate"));
assertEquals(1, coll.size());
assertEquals("duplication tweet", coll.iterator().next().getText());
coll = tweetSearch.searchTweets(new TweetQuery("duplication"));
assertEquals(1, coll.size());
assertEquals("duplication tweet", coll.iterator().next().getText());
}