License { public static License findByValue(final String uri) { License found = License.lookupLicense.get(uri); if (found == null && uri.startsWith("http: final Iterator<String> it = License.lookupLicense.keySet().iterator(); while (it.hasNext() && found == null) { final String key = it.next(); try { if (key.startsWith(CC_START)) { final String licensePath = key.substring(CC_START.length(), key.length()); final StringTokenizer tok = new StringTokenizer(licensePath, "/"); final String license = tok.nextToken(); if (uri.toLowerCase().indexOf("creativecommons.org/licenses/" + license) != -1) { final License current = lookupLicense.get(key); found = new License(uri, current.getRequires(), current.getPermits()); } } } catch (final Exception e) { LOG.error("Error", e); } } } if (found == null) { found = new License(uri, null, null); } return found; } License(final String uri, final Behaviour[] requires, final Behaviour[] permits); static License findByValue(final String uri); Behaviour[] getPermits(); Behaviour[] getRequires(); @Override String toString(); String getValue(); @Override boolean equals(final Object obj); @Override int hashCode(); static final License NO_DERIVS; static final License NO_DERIVS_NONCOMMERCIAL; static final License NONCOMMERCIAL; static final License SHARE_ALIKE; static final License SHARE_ALIKE_NONCOMMERCIAL; static final License SHARE_ALIKE_ATTRIBUTION; static final License SHARE_ALIKE_NONCOMMERCIAL_ATTRIBUTION; static final License NONCOMMERCIAL_ATTRIBUTION; static final License NONCOMMERCIAL_ATTRIBUTION_NO_DERIVS; static final License ATTRIBUTION_NO_DERIVS; static final License ATTRIBUTION; }
@Test(timeout = 1000) public void testConcurrent() throws InterruptedException { final AtomicBoolean run = new AtomicBoolean(true); final AtomicLong type = new AtomicLong(0); final AtomicBoolean hadProblem = new AtomicBoolean(false); final AtomicBoolean hadException = new AtomicBoolean(false); final Thread addNew = new Thread() { @Override public void run() { try { while (run.get()) { final License license = License.findByValue("http: if (license == null) { hadProblem.set(true); } } } catch (final Exception e) { LOG.error("Exception in add-new thread", e); hadException.set(true); } } }; final Thread getExisting = new Thread() { @Override public void run() { final Random rnd = new Random(); try { while (run.get()) { if (type.intValue() == 0) { continue; } final License license = License.findByValue("http: if (license == null) { hadProblem.set(true); } } } catch (final Exception e) { LOG.error("Exception in get-existing thread", e); hadException.set(true); } } }; addNew.start(); getExisting.start(); Thread.sleep(400); run.set(false); addNew.join(50); getExisting.join(50); assertFalse(hadProblem.get()); assertFalse(hadException.get()); assertFalse(addNew.isAlive()); assertFalse(getExisting.isAlive()); }