Fix ConcurrentModificationException in RSSCache. Add test.

This commit is contained in:
Christian P. MOMON 2014-05-14 00:08:45 +02:00
parent 2e85a0cee8
commit dcee88841e
2 changed files with 76 additions and 1 deletions

View file

@ -21,6 +21,8 @@ package fr.devinsy.util.rss;
import java.util.HashMap;
import java.util.Locale;
import fr.devinsy.util.StringList;
/**
*
* @author christian.momon@devinsy.fr
@ -167,7 +169,7 @@ public class RSSCache
*/
public void setOudated(final String name)
{
for (String subkey : this.cache.keySet())
for (String subkey : subkeys(name))
{
if (subkey.startsWith(name))
{
@ -176,6 +178,30 @@ public class RSSCache
}
}
/**
*
* @param key
*/
public StringList subkeys(final String name)
{
StringList result;
//
result = new StringList();
//
for (String key : this.cache.keySet())
{
if (key.startsWith(name))
{
result.add(key);
}
}
//
return result;
}
/**
*
* @return

View file

@ -0,0 +1,49 @@
package fr.devinsy.util.util.rss;
import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.junit.Before;
import org.junit.Test;
import fr.devinsy.util.rss.RSSCache;
/**
*
* @author Christian P. Momon
*/
public class RSSCacheTest
{
static protected org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(RSSCacheTest.class);
/**
*
*/
@Before
public void before()
{
BasicConfigurator.configure();
Logger.getRootLogger().setLevel(Level.ERROR);
}
/**
*
*/
@Test
public void test01()
{
//
logger.debug("===== test starting...");
RSSCache cache = RSSCache.instance();
cache.put("ALPHA", "Mignonne, allons voir si la rose");
cache.put("BRAVO", "Qui ce matin avoit desclose");
cache.put("CHARLIE", "Sa robe de pourpre au Soleil,");
cache.setOudated("CHARLIE");
//
logger.debug("===== test done.");
}
}