/** * http://code.google.com/p/jodd/issues/detail?id=4 */ @Test void testPutGetAndPrune() throws InterruptedException { LFUCache<String, String> lfuCache = new LFUCache<>(2, 0); lfuCache.put("1", "value"); assertFalse(lfuCache.isFull()); lfuCache.put("2", "value"); assertTrue(lfuCache.isFull()); lfuCache.get("2"); lfuCache.get("2"); assertEquals(2, lfuCache.size()); Semaphore semaphore = new Semaphore(2); Thread1 t1 = new Thread1(semaphore, lfuCache); Thread2 t2 = new Thread2(semaphore, lfuCache); t1.start(); t2.start(); semaphore.acquire(); if (t1.exception != null) { t1.exception.printStackTrace(); } assertNull(t1.exception); if (t2.exception != null) { t2.exception.printStackTrace(); } assertNull(t2.exception); }
public void traceErrors() { try { for (ErrorRecord er : errors) { System.out.println("Error: " + er); } } catch (ConcurrentModificationException e) { e.printStackTrace(); } }
/** * If no objects are monitored, this just delegates to * {@code System.gc()} and returns {@link #UNKNOWN_COUNT} as a * non-erroneous default value. If objects are monitored, * it emulates a synchronous gc-run in the sense that it waits * until all collected monitored objects were finalized. * * @return Number of collected monitored cyclic trash-objects * or {@link #UNKNOWN_COUNT} if nothing is monitored or -1 * if an error occurred and collection did not complete. * @see #UNKNOWN_COUNT * @see #collect(int) */ public static int collect() { try { return collect_intern(); } catch (java.util.ConcurrentModificationException cme) { cme.printStackTrace(); } catch (NullPointerException npe) { npe.printStackTrace(); } return -1; }
@Override public void run() { while(runThread) { try { UserGroupInformation.getCurrentUser().getCredentials(); } catch (ConcurrentModificationException cme) { this.cme = cme; cme.printStackTrace(); runThread = false; } catch (IOException ex) { ex.printStackTrace(); } } } }
@Override public void run() { while(runThread) { try { UserGroupInformation.getCurrentUser().getCredentials(); } catch (ConcurrentModificationException cme) { this.cme = cme; cme.printStackTrace(); runThread = false; } catch (IOException ex) { ex.printStackTrace(); } } } }
t.printStackTrace(); } catch (InterruptedException e) { t.printStackTrace(); } catch (InterruptedException e) {
} catch (ConcurrentModificationException t) { hasError.set(true); t.printStackTrace(); } catch (InterruptedException e) { t.printStackTrace(); } catch (InterruptedException e) {
ex.printStackTrace(System.err);
@Override public Void run() throws Exception { // make sure it is not the same as the login user because we use the // same UGI object for every instantiation of the login user and you // won't run into the race condition otherwise assertNotEquals(UserGroupInformation.getLoginUser(), UserGroupInformation.getCurrentUser()); GetTokenThread thread = new GetTokenThread(); try { thread.start(); for (int i = 0; i < 100; i++) { @SuppressWarnings("unchecked") Token<? extends TokenIdentifier> t = mock(Token.class); when(t.getService()).thenReturn(new Text("t" + i)); UserGroupInformation.getCurrentUser().addToken(t); assertNull("ConcurrentModificationException encountered", thread.cme); } } catch (ConcurrentModificationException cme) { cme.printStackTrace(); fail("ConcurrentModificationException encountered"); } finally { thread.runThread = false; thread.join(5 * 1000); } return null; }}); }
@Override public Void run() throws Exception { // make sure it is not the same as the login user because we use the // same UGI object for every instantiation of the login user and you // won't run into the race condition otherwise assertNotEquals(UserGroupInformation.getLoginUser(), UserGroupInformation.getCurrentUser()); GetTokenThread thread = new GetTokenThread(); try { thread.start(); for (int i = 0; i < 100; i++) { @SuppressWarnings("unchecked") Token<? extends TokenIdentifier> t = mock(Token.class); when(t.getService()).thenReturn(new Text("t" + i)); UserGroupInformation.getCurrentUser().addToken(t); assertNull("ConcurrentModificationException encountered", thread.cme); } } catch (ConcurrentModificationException cme) { cme.printStackTrace(); fail("ConcurrentModificationException encountered"); } finally { thread.runThread = false; thread.join(5 * 1000); } return null; }}); }