/** * Returns the current size of the executor pool for this computer. * This number may temporarily differ from {@link #getNumExecutors()} if there * are busy tasks when the configured size is decreased. OneOffExecutors are * not included in this count. */ public final int countExecutors() { return executors.size(); }
/** * Returns the number of tests that failed during the run */ public int getFailureCount() { return failures.size(); }
/** * Gets the read-only snapshot view of all {@link Executor} instances including {@linkplain OneOffExecutor}s. * * @return the read-only snapshot view of all {@link Executor} instances including {@linkplain OneOffExecutor}s. * @since 2.55 */ public List<Executor> getAllExecutors() { List<Executor> result = new ArrayList<>(executors.size() + oneOffExecutors.size()); result.addAll(executors); result.addAll(oneOffExecutors); return result; }
private Object[] copyMappedFiles(final int reservedMappedFiles) { Object[] mfs; if (this.mappedFiles.size() <= reservedMappedFiles) { return null; } mfs = this.mappedFiles.toArray(); return mfs; }
public void removeListener(Listener listener) { if (null == listener) { throw new IllegalArgumentException("listener is null"); } ManagerListenerWrap wrap = new ManagerListenerWrap(listener); if (listeners.remove(wrap)) { log.info(name, "[remove-listener] ok, dataId={}, group={}, cnt={}", dataId, group, listeners.size()); } }
public boolean isEmpty() { synchronized (hydrantLock) { return hydrants.size() == 1 && currHydrant.getIndex().isEmpty(); } }
private void addNewExecutorIfNecessary() { if (Jenkins.getInstanceOrNull() == null) { return; } Set<Integer> availableNumbers = new HashSet<Integer>(); for (int i = 0; i < numExecutors; i++) availableNumbers.add(i); for (Executor executor : executors) availableNumbers.remove(executor.getNumber()); for (Integer number : availableNumbers) { /* There may be busy executors with higher index, so only fill up until numExecutors is reached. Extra executors will call removeExecutor(...) and that will create any necessary executors from #0 again. */ if (executors.size() < numExecutors) { Executor e = new Executor(this, number); executors.add(e); } } }
private File createNewPartitionFolder() throws IOException { File partitionFolder = indexStorage.getPartitionFolder( partitions.size() + 1 ); indexStorage.prepareFolder( partitionFolder ); return partitionFolder; }
public MappedFile getLastMappedFile() { MappedFile mappedFileLast = null; while (!this.mappedFiles.isEmpty()) { try { mappedFileLast = this.mappedFiles.get(this.mappedFiles.size() - 1); break; } catch (IndexOutOfBoundsException e) { //continue; } catch (Exception e) { log.error("getLastMappedFile has exception.", e); break; } } return mappedFileLast; }
@Test public void singleSmartLifecycleWithoutAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(false); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertFalse(bean.isRunning()); assertEquals(0, startedBeans.size()); context.start(); assertTrue(bean.isRunning()); assertEquals(1, startedBeans.size()); context.stop(); }
@Test public void singleSmartLifecycleShutdown() throws Exception { Assume.group(TestGroup.PERFORMANCE); CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forShutdownTests(99, 300, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
@Test public void singleSmartLifecycleAutoStartup() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(true); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); assertFalse(bean.isRunning()); context.refresh(); assertTrue(bean.isRunning()); context.stop(); assertFalse(bean.isRunning()); assertEquals(1, startedBeans.size()); }
@Test public void singleLifecycleShutdown() throws Exception { CopyOnWriteArrayList<Lifecycle> stoppedBeans = new CopyOnWriteArrayList<>(); Lifecycle bean = new TestLifecycleBean(null, stoppedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.refresh(); assertFalse(bean.isRunning()); bean.start(); assertTrue(bean.isRunning()); context.stop(); assertEquals(1, stoppedBeans.size()); assertFalse(bean.isRunning()); assertEquals(bean, stoppedBeans.get(0)); }
@Test public void dependencyStartedFirstButNotSmartLifecycle() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans); TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forStartupTests(7, startedBeans); TestLifecycleBean simpleBean = TestLifecycleBean.forStartupTests(startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanMin", beanMin); context.getBeanFactory().registerSingleton("bean7", bean7); context.getBeanFactory().registerSingleton("simpleBean", simpleBean); context.getBeanFactory().registerDependentBean("simpleBean", "beanMin"); context.refresh(); assertTrue(beanMin.isRunning()); assertTrue(bean7.isRunning()); assertTrue(simpleBean.isRunning()); assertEquals(3, startedBeans.size()); assertEquals(0, getPhase(startedBeans.get(0))); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(1))); assertEquals(7, getPhase(startedBeans.get(2))); context.stop(); }
@Test public void singleSmartLifecycleAutoStartupWithNonAutoStartupDependency() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean bean = TestSmartLifecycleBean.forStartupTests(1, startedBeans); bean.setAutoStartup(true); TestSmartLifecycleBean dependency = TestSmartLifecycleBean.forStartupTests(1, startedBeans); dependency.setAutoStartup(false); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("bean", bean); context.getBeanFactory().registerSingleton("dependency", dependency); context.getBeanFactory().registerDependentBean("dependency", "bean"); assertFalse(bean.isRunning()); assertFalse(dependency.isRunning()); context.refresh(); assertTrue(bean.isRunning()); assertFalse(dependency.isRunning()); context.stop(); assertFalse(bean.isRunning()); assertFalse(dependency.isRunning()); assertEquals(1, startedBeans.size()); }
@Test public void dependencyStartedFirstAndIsSmartLifecycle() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanNegative = TestSmartLifecycleBean.forStartupTests(-99, startedBeans); TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forStartupTests(99, startedBeans); TestSmartLifecycleBean bean7 = TestSmartLifecycleBean.forStartupTests(7, startedBeans); TestLifecycleBean simpleBean = TestLifecycleBean.forStartupTests(startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanNegative", beanNegative); context.getBeanFactory().registerSingleton("bean7", bean7); context.getBeanFactory().registerSingleton("bean99", bean99); context.getBeanFactory().registerSingleton("simpleBean", simpleBean); context.getBeanFactory().registerDependentBean("bean7", "simpleBean"); context.refresh(); context.stop(); startedBeans.clear(); // clean start so that simpleBean is included context.start(); assertTrue(beanNegative.isRunning()); assertTrue(bean99.isRunning()); assertTrue(bean7.isRunning()); assertTrue(simpleBean.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(-99, getPhase(startedBeans.get(0))); assertEquals(7, getPhase(startedBeans.get(1))); assertEquals(0, getPhase(startedBeans.get(2))); assertEquals(99, getPhase(startedBeans.get(3))); context.stop(); }
@Test public void dependencyStartedFirstEvenIfItsPhaseIsHigher() throws Exception { CopyOnWriteArrayList<Lifecycle> startedBeans = new CopyOnWriteArrayList<>(); TestSmartLifecycleBean beanMin = TestSmartLifecycleBean.forStartupTests(Integer.MIN_VALUE, startedBeans); TestSmartLifecycleBean bean2 = TestSmartLifecycleBean.forStartupTests(2, startedBeans); TestSmartLifecycleBean bean99 = TestSmartLifecycleBean.forStartupTests(99, startedBeans); TestSmartLifecycleBean beanMax = TestSmartLifecycleBean.forStartupTests(Integer.MAX_VALUE, startedBeans); StaticApplicationContext context = new StaticApplicationContext(); context.getBeanFactory().registerSingleton("beanMin", beanMin); context.getBeanFactory().registerSingleton("bean2", bean2); context.getBeanFactory().registerSingleton("bean99", bean99); context.getBeanFactory().registerSingleton("beanMax", beanMax); context.getBeanFactory().registerDependentBean("bean99", "bean2"); context.refresh(); assertTrue(beanMin.isRunning()); assertTrue(bean2.isRunning()); assertTrue(bean99.isRunning()); assertTrue(beanMax.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(0))); assertEquals(99, getPhase(startedBeans.get(1))); assertEquals(bean99, startedBeans.get(1)); assertEquals(2, getPhase(startedBeans.get(2))); assertEquals(bean2, startedBeans.get(2)); assertEquals(Integer.MAX_VALUE, getPhase(startedBeans.get(3))); context.stop(); }
assertFalse(simpleBean1.isRunning()); assertFalse(simpleBean2.isRunning()); assertEquals(2, startedBeans.size()); assertEquals(-3, getPhase(startedBeans.get(0))); assertEquals(5, getPhase(startedBeans.get(1))); assertTrue(simpleBean1.isRunning()); assertTrue(simpleBean2.isRunning()); assertEquals(4, startedBeans.size()); assertEquals(0, getPhase(startedBeans.get(2))); assertEquals(0, getPhase(startedBeans.get(3)));
assertTrue(beanMax.isRunning()); context.stop(); assertEquals(5, startedBeans.size()); assertEquals(Integer.MIN_VALUE, getPhase(startedBeans.get(0))); assertEquals(1, getPhase(startedBeans.get(1)));
assertFalse(bean7.isRunning()); assertFalse(simpleBean.isRunning()); assertEquals(5, stoppedBeans.size()); assertEquals(7, getPhase(stoppedBeans.get(0))); assertEquals(0, getPhase(stoppedBeans.get(1)));