1 27 package de.nava.informa.utils; 28 29 import java.io.File ; 30 31 import de.nava.informa.core.ChannelIF; 32 import de.nava.informa.core.FeedIF; 33 import de.nava.informa.impl.basic.ChannelBuilder; 34 import de.nava.informa.parsers.FeedParser; 35 import de.nava.informa.impl.basic.Feed; 36 37 40 public class TestCacheSettingsFM extends InformaTestCase { 41 42 public TestCacheSettingsFM(String name) { 43 super("TestCacheSettingsFM", name); 44 } 45 46 public void testRSS091SettingsDefault() { 47 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 48 CacheSettings cs = new CacheSettings(); 49 cs.setDefaultTtl(2000); 50 51 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 52 try { 53 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 54 55 assertEquals(2000, cs.getTtl(channel, -1L)); 57 58 String url = new Feed(channel).getLocation().toString(); 59 FM.addFeed(url); 60 61 assertEquals(2000, cs.getTtl(FM.getFeed(url).getChannel(), -1L)); 63 } catch (Exception e) { 64 System.err.println("testRSS091SettingsDefault error " + e); 65 e.printStackTrace(); 66 } 67 } 68 69 public void testRSS091Settings() { 70 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 71 CacheSettings cs = new CacheSettings(); 72 cs.setDefaultTtl(2000); 73 74 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 75 try { 76 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 77 78 assertEquals(2000L, cs.getTtl(channel, 10000L)); assertEquals(360000L, cs.getTtl(channel, 360000L)); 82 String url = new Feed(channel).getLocation().toString(); 83 FM.addFeed(url); 84 85 assertEquals(2000L, cs.getTtl(FM.getFeed(url).getChannel(), 10000L)); 87 assertEquals(360000L, cs.getTtl(FM.getFeed(url).getChannel(), 360000L)); } catch (Exception e) { 89 System.err.println("testRSS091Settings error " + e); 90 } 91 } 92 93 public void testRSS100SettingsNoUpdatePeriodInFeed() { 94 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 95 CacheSettings cs = new CacheSettings(); 96 cs.setDefaultTtl(2000); 97 98 File inpFile = new File (getDataDir(), "bloggy.rdf"); 99 try { 100 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 101 102 assertEquals(2000, cs.getTtl(channel, -1L)); 104 assertEquals(2000L, cs.getTtl(channel, 10000L)); assertEquals(360000L, cs.getTtl(channel, 360000L)); 107 String url = new Feed(channel).getLocation().toString(); 108 FM.addFeed(url); 109 110 assertEquals(2000, cs.getTtl(FM.getFeed(url).getChannel(), -1L)); 112 assertEquals(2000L, cs.getTtl(FM.getFeed(url).getChannel(), 10000L)); 113 assertEquals(360000L, cs.getTtl(FM.getFeed(url).getChannel(), 360000L)); } catch (Exception e) { 115 System.err.println("testRSS100SettingsNoUpdatePeriodInFeed error " + e); 116 e.printStackTrace(); 117 } 118 } 119 120 public void testRSS100SettingsUpdatePeriodInFeed() { 121 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 122 CacheSettings cs = new CacheSettings(); 123 cs.setDefaultTtl(2000); 124 125 File inpFile = new File (getDataDir(), "slashdot-010604.rdf"); 126 try { 127 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 128 129 assertEquals(3600000, cs.getTtl(channel, -1L)); 131 assertEquals(3600000, cs.getTtl(channel, 10000L)); 132 assertEquals(3600005, cs.getTtl(channel, 3600005)); String url = new Feed(channel).getLocation().toString(); 135 FM.addFeed(url); 136 assertEquals(3600000, cs.getTtl(FM.getFeed(url).getChannel(), -1L)); 137 assertEquals(3600000, cs.getTtl(FM.getFeed(url).getChannel(), 10000L)); 138 } catch (Exception e) { 139 System.err.println("testRSS100SettingsUpdatePeriodInFeed error " + e); 140 } 141 } 142 143 public void testRSS200SettingsUpdatePeriodInFeed() { 144 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 145 CacheSettings cs = new CacheSettings(); 146 cs.setDefaultTtl(2000); 147 148 File inpFile = new File (getDataDir(), "mobitopia.xml"); 149 try { 150 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 151 152 assertEquals((60*60*1000), cs.getTtl(channel, -1L)); 154 assertEquals((60*60*1000), cs.getTtl(channel, 10000L)); 155 assertEquals((60*60*1000), cs.getTtl(channel, (30*60*1000))); assertEquals((120*60*1000), cs.getTtl(channel, (120*60*1000))); 160 String url = new Feed(channel).getLocation().toString(); 161 FM.addFeed(url); 162 163 assertEquals( (60*60*1000), cs.getTtl(FM.getFeed(url).getChannel(), -1L)); 164 assertEquals( (60*60*1000), cs.getTtl(FM.getFeed(url).getChannel(), 10000L)); 165 } catch (Exception e) { 166 System.err.println("testRSS200SettingsUpdatePeriodInFeed error " + e); 167 } 168 } 169 170 public void testFMCache091() { 171 long t1, t2; 172 173 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 174 CacheSettings cs = new CacheSettings(); 175 cs.setDefaultTtl(3000); 176 177 File inpFile = new File (getDataDir(), "xmlhack-0.91.xml"); 178 try { 179 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 180 181 assertEquals(3000, cs.getTtl(channel, -1L)); 184 185 String url = new Feed(channel).getLocation().toString(); 186 FM.removeFeed(url); 187 FM.addFeed(url); 188 assertTrue("feed not in cache !!", FM.hasFeed(url)); 189 FeedIF feedRef1 = FM.getFeed(url); 190 191 assertNotNull("feed read null", feedRef1); 192 193 t1 = feedRef1.getLastUpdated().getTime(); 194 t2 = FM.getFeed(url).getLastUpdated().getTime(); 195 assertTrue("same date for feeds read in cache " + t1, t1 == t2); 196 197 try { 198 Thread.sleep(4000); 199 } catch (Exception e) { 200 System.err.println("Error in Wait..." + e); 201 } 202 t2 = FM.getFeed(url).getLastUpdated().getTime(); 204 205 System.err.println("LAST uptd " + t1 + "," + t2); 206 System.err.println("LAST uptd test (false?)" + (t1 == t2)); 207 208 assertTrue("lastUpdated must differ for RSS091 test feed", t1 != t2); 209 210 FM.removeFeed(url); 211 assertFalse("feed should be removed", FM.hasFeed(url)); 212 213 System.err.println("ori:" 215 + FM.addFeed(url, 100).getLastUpdated().getTime()); 216 217 t1 = FM.getFeed(url).getLastUpdated().getTime(); 218 try { 219 Thread.sleep(4000); 220 } catch (Exception e) { 221 System.err.println("Error in Wait..." + e); 222 } 223 224 t2 = FM.getFeed(url).getLastUpdated().getTime(); 225 assertTrue("lastUpdated must be the same for a 100 mins ttl" + url, 227 t1 == t2); 228 229 } catch (Exception e) { 230 System.err.println("testFMCache091 error " + e); 231 e.printStackTrace(); 232 } 233 } 234 235 public void testCondGet() { 236 long t1, t2; 237 238 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 239 CacheSettings cs = new CacheSettings(); 240 cs.setDefaultTtl(3000); 241 242 try { 243 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), "http://www.intertwingly.net/blog/index.rss"); 245 String url = new Feed(channel).getLocation().toString(); 246 FM.removeFeed(url); 247 FM.addFeed(url); 248 FeedIF feedRef1 = FM.getFeed(url); 249 250 t1 = feedRef1.getLastUpdated().getTime(); 251 t2 = FM.getFeed(url).getLastUpdated().getTime(); 252 assertTrue("same date for feeds read in cache " + t1, t1 == t2); 253 254 try { 255 Thread.sleep(4000); 256 } catch (Exception e) { 257 System.err.println("Error in Wait..." + e); 258 } 259 260 System.err.println("Look at the stderr for trace about cond.get"); 261 262 t2 = FM.getFeed(url).getLastUpdated().getTime(); 264 265 266 assertTrue("lastUpdated must be different", t1 != t2); 267 268 } catch (Exception e) { 269 System.err.println("testCondGet error " + e); 270 e.printStackTrace(); 271 } 272 } 273 274 public void testFMCacheRSS100WithUpdatePeriod() { 275 long t1, t2; 276 277 FeedManager FM = new FeedManager(ChannelIF.UPDATE_HOURLY, 2); 278 CacheSettings cs = new CacheSettings(); 279 cs.setDefaultTtl(3000); 280 281 282 File inpFile = new File (getDataDir(), "slashdot-010604.rdf"); 283 try { 284 ChannelIF channel = FeedParser.parse(new ChannelBuilder(), inpFile); 285 286 assertEquals(60 * 60 * 1000, cs.getTtl(channel, -1L)); 289 290 String url = new Feed(channel).getLocation().toString(); 291 FM.removeFeed(url); 292 293 channel = FeedParser.parse(new ChannelBuilder(), inpFile); 294 url = new Feed(channel).getLocation().toString(); 296 FeedIF feedRef1 = FM.addFeed(url); 297 t1 = feedRef1.getLastUpdated().getTime(); 298 try { 299 Thread.sleep(4000); 300 } catch (Exception e) { 301 System.err.println("Error in Wait..." + e); 302 } 303 t2 = FM.getFeed(url).getLastUpdated().getTime(); 304 assertTrue("lastUpdated must be the same for this RSS1.00 test feed", 305 (t1 == t2)); 306 307 } catch (Exception e) { 308 System.err.println("testFMCacheRSS100WithUpdatePeriod error " + e); 309 e.printStackTrace(); 310 } 311 } 312 } 313 314 | Popular Tags |