List of usage examples for java.util.concurrent.atomic AtomicInteger intValue
public int intValue()
From source file:Main.java
public static void main(String[] argv) throws Exception { AtomicInteger atomicInteger = new AtomicInteger(); System.out.println(atomicInteger.intValue()); }
From source file:org.jtheque.undo.UndoServiceTest.java
@Test @DirtiesContext/*ww w. j a va2 s . c o m*/ public void addError() { final AtomicInteger undo = new AtomicInteger(0); final AtomicInteger redo = new AtomicInteger(0); UndoableEdit edit = new TestEdit(undo, redo); undoService.addEdit(edit); assertEquals(0, undo.intValue()); assertEquals(0, redo.intValue()); undoService.undo(); assertEquals(1, undo.intValue()); assertEquals(0, redo.intValue()); undoService.redo(); assertEquals(1, undo.intValue()); assertEquals(1, redo.intValue()); }
From source file:com.zimbra.cs.servlet.ContextPathBasedThreadPoolBalancerFilter.java
/** Determine whether to suspend request based on state of current thread pool */ protected boolean shouldSuspend(ServletRequest request) { // Disable this servlet filter if the current thread pool is not known (we're probably not running in Jetty) if (queuedThreadPool == null) { return false; }//from w w w . ja va2 s . c o m // Determine whether request is for one of the context paths this filter is managing QoS for String contextPath = getContextPath(request); // Enforce maximums Rules rules = rulesByContextPath.get(contextPath); if (rules != null) { // Determine the state of the thread pool int threads = queuedThreadPool.getThreads(); int idleThreads = queuedThreadPool.getIdleThreads(); int busyThreads = threads - idleThreads; int roomInPoolForNewThreads = queuedThreadPool.getMaxThreads() - busyThreads; AtomicInteger count = activeRequestsByContextPath.get(contextPath); int activeRequestsCount = count == null ? 0 : count.intValue(); ZimbraLog.misc.debug( "Servlet (contextPath=%s active=%d), Jetty pool (threads=%d, idle=%d, busy=%d, room=%d)", getLoggableContextPath(contextPath), activeRequestsCount, threads, idleThreads, busyThreads, roomInPoolForNewThreads); // Enforce max count if (rules.max != null) { if (activeRequestsCount > rules.max) { ZimbraLog.misc.info( "Suspending for %dms because context path %s is at %d configured max threads", suspendMs, getLoggableContextPath(contextPath), activeRequestsCount); return true; } } // Enforce max % if (rules.maxPercent != null) { if (100 * activeRequestsCount / queuedThreadPool.getMaxThreads() > rules.maxPercent) { ZimbraLog.misc.info( "Suspending for %dms because context path %s is at %d threads (%d configured max percentage of thread pool size)", suspendMs, getLoggableContextPath(contextPath), activeRequestsCount, rules.maxPercent); return true; } } } return false; }
From source file:org.jtheque.core.LifeCycleTest.java
@Test @DirtiesContext/*from w w w . ja v a 2s . c o m*/ public void titleListener() { final AtomicInteger titleCounter = new AtomicInteger(0); lifeCycle.addTitleListener(new TitleListener() { @Override public void titleUpdated(String title) { titleCounter.incrementAndGet(); } }); lifeCycle.refreshTitle(); assertEquals(1, titleCounter.intValue()); }
From source file:org.jtheque.core.LifeCycleTest.java
@Test @DirtiesContext/*w w w. ja v a 2 s. c o m*/ public void functionListener() { final AtomicInteger functionCounter = new AtomicInteger(0); lifeCycle.addFunctionListener(new FunctionListener() { @Override public void functionUpdated(String function) { functionCounter.incrementAndGet(); } }); lifeCycle.setCurrentFunction("new function"); assertEquals(1, functionCounter.intValue()); }
From source file:org.jtheque.errors.ErrorServiceTest.java
@Test @DirtiesContext/* w ww .j a va 2s.c o m*/ public void listenerCalled() { final Error error = Errors.newError("Test"); final AtomicInteger integer = new AtomicInteger(0); errorService.addErrorListener(new ErrorListener() { @Override public void errorOccurred(Error occuredError) { integer.incrementAndGet(); assertEquals(error, occuredError); } }); errorService.addError(error); assertEquals(1, integer.intValue()); }
From source file:org.jtheque.undo.UndoServiceTest.java
@Test @DirtiesContext//from ww w.ja v a 2 s. com public void listenerCalled() { final AtomicInteger counter = new AtomicInteger(0); undoService.addStateListener(new StateListener() { @Override public void stateChanged(String undoName, boolean canUndo, String redoName, boolean canRedo) { counter.incrementAndGet(); } }); undoService.addEdit(new TestEdit(new AtomicInteger(0), new AtomicInteger(0))); assertEquals(1, counter.intValue()); undoService.addEdit(new TestEdit(new AtomicInteger(0), new AtomicInteger(0))); assertEquals(2, counter.intValue()); undoService.undo(); assertEquals(3, counter.intValue()); undoService.redo(); assertEquals(4, counter.intValue()); }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testImportNullWord() { WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount"); ReflectionUtils.makeAccessible(rowCountField); AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl);/* w w w .jav a 2 s . c o m*/ assertEquals(0, rowCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); wordListImporterImpl.setWordDao(wordDaoMock); wordListImporterImpl.setPersistenceBatchSize(3); List<Word> wordBatch = new ArrayList<Word>(); wordListImporterImpl.importWord(null, wordBatch); rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(0, rowCountFromObject.intValue()); verifyZeroInteractions(wordDaoMock); assertTrue(wordBatch.isEmpty()); }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testImportWord() { WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount"); ReflectionUtils.makeAccessible(rowCountField); AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl);/* w w w .j av a 2 s . c o m*/ assertEquals(0, rowCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); wordListImporterImpl.setWordDao(wordDaoMock); wordListImporterImpl.setPersistenceBatchSize(3); List<Word> wordBatch = new ArrayList<Word>(); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word1, wordBatch); verify(wordDaoMock, never()).insertBatch(anyListOf(Word.class)); assertEquals(1, wordBatch.size()); Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word2, wordBatch); verify(wordDaoMock, never()).insertBatch(anyListOf(Word.class)); assertEquals(2, wordBatch.size()); Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word3, wordBatch); rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(3, rowCountFromObject.intValue()); verify(wordDaoMock, times(1)).insertBatch(same(wordBatch)); assertTrue(wordBatch.isEmpty()); }
From source file:com.ciphertool.sentencebuilder.etl.importers.WordListImporterImplTest.java
@Test public void testImportWord_BatchSizeNotReached() { WordListImporterImpl wordListImporterImpl = new WordListImporterImpl(); Field rowCountField = ReflectionUtils.findField(WordListImporterImpl.class, "rowCount"); ReflectionUtils.makeAccessible(rowCountField); AtomicInteger rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl);/*from ww w .ja v a2 s.co m*/ assertEquals(0, rowCountFromObject.intValue()); WordDao wordDaoMock = mock(WordDao.class); when(wordDaoMock.insertBatch(anyListOf(Word.class))).thenReturn(true); wordListImporterImpl.setWordDao(wordDaoMock); wordListImporterImpl.setPersistenceBatchSize(4); List<Word> wordBatch = new ArrayList<Word>(); Word word1 = new Word(new WordId("george", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word1, wordBatch); verify(wordDaoMock, never()).insertBatch(anyListOf(Word.class)); assertEquals(1, wordBatch.size()); Word word2 = new Word(new WordId("elmer", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word2, wordBatch); verify(wordDaoMock, never()).insertBatch(anyListOf(Word.class)); assertEquals(2, wordBatch.size()); Word word3 = new Word(new WordId("belden", PartOfSpeechType.NOUN)); wordListImporterImpl.importWord(word3, wordBatch); rowCountFromObject = (AtomicInteger) ReflectionUtils.getField(rowCountField, wordListImporterImpl); assertEquals(0, rowCountFromObject.intValue()); verify(wordDaoMock, never()).insertBatch(anyListOf(Word.class)); assertEquals(3, wordBatch.size()); assertSame(word1, wordBatch.get(0)); assertSame(word2, wordBatch.get(1)); assertSame(word3, wordBatch.get(2)); }