How to use setExecutorFactory method of org.testng.TestNG class

Best Testng code snippet using org.testng.TestNG.setExecutorFactory

Source:TestNG.java Github

copy

Full Screen

...678 */679 public void setVerbose(int verbose) {680 m_verbose = verbose;681 }682 public void setExecutorFactoryClass(String clazzName) {683 this.m_executorFactory = createExecutorFactoryInstanceUsing(clazzName);684 }685 private IExecutorFactory createExecutorFactoryInstanceUsing(String clazzName) {686 Class<?> cls = ClassHelper.forName(clazzName);687 Object instance = InstanceCreator.newInstance(cls);688 if (instance instanceof IExecutorFactory) {689 return (IExecutorFactory) instance;690 }691 throw new IllegalArgumentException(692 clazzName + " does not implement " + IExecutorFactory.class.getName());693 }694 public void setExecutorFactory(IExecutorFactory factory) {695 this.m_executorFactory = factory;696 }697 public IExecutorFactory getExecutorFactory() {698 if (this.m_executorFactory == null) {699 this.m_executorFactory = createExecutorFactoryInstanceUsing(DEFAULT_THREADPOOL_FACTORY);700 }701 return this.m_executorFactory;702 }703 private void initializeCommandLineSuites() {704 if (m_commandLineTestClasses != null || m_commandLineMethods != null) {705 if (null != m_commandLineMethods) {706 m_cmdlineSuites = createCommandLineSuitesForMethods(m_commandLineMethods);707 } else {708 m_cmdlineSuites = createCommandLineSuitesForClasses(m_commandLineTestClasses);709 }710 for (XmlSuite s : m_cmdlineSuites) {711 for (XmlTest t : s.getTests()) {712 t.setPreserveOrder(m_preserveOrder);713 }714 m_suites.add(s);715 if (m_groupByInstances != null) {716 s.setGroupByInstances(m_groupByInstances);717 }718 }719 }720 }721 private void initializeCommandLineSuitesParams() {722 if (null == m_cmdlineSuites) {723 return;724 }725 for (XmlSuite s : m_cmdlineSuites) {726 if (m_threadCount != -1) {727 s.setThreadCount(m_threadCount);728 }729 if (m_parallelMode != null) {730 s.setParallel(m_parallelMode);731 }732 if (m_configFailurePolicy != null) {733 s.setConfigFailurePolicy(m_configFailurePolicy);734 }735 }736 }737 private void initializeCommandLineSuitesGroups() {738 // If groups were specified on the command line, they should override groups739 // specified in the XML file740 boolean hasIncludedGroups = null != m_includedGroups && m_includedGroups.length > 0;741 boolean hasExcludedGroups = null != m_excludedGroups && m_excludedGroups.length > 0;742 List<XmlSuite> suites = m_cmdlineSuites != null ? m_cmdlineSuites : m_suites;743 if (hasIncludedGroups || hasExcludedGroups) {744 for (XmlSuite s : suites) {745 initializeCommandLineSuitesGroups(746 s, hasIncludedGroups, m_includedGroups, hasExcludedGroups, m_excludedGroups);747 }748 }749 }750 private static void initializeCommandLineSuitesGroups(751 XmlSuite s,752 boolean hasIncludedGroups,753 String[] m_includedGroups,754 boolean hasExcludedGroups,755 String[] m_excludedGroups) {756 if (hasIncludedGroups) {757 s.setIncludedGroups(Arrays.asList(m_includedGroups));758 }759 if (hasExcludedGroups) {760 s.setExcludedGroups(Arrays.asList(m_excludedGroups));761 }762 for (XmlSuite child : s.getChildSuites()) {763 initializeCommandLineSuitesGroups(764 child, hasIncludedGroups, m_includedGroups, hasExcludedGroups, m_excludedGroups);765 }766 }767 private void addReporter(Class<? extends IReporter> r) {768 if (!m_reporters.containsKey(r)) {769 m_reporters.put(r, InstanceCreator.newInstance(r));770 }771 }772 private void initializeDefaultListeners() {773 if (m_failIfAllTestsSkipped) {774 this.exitCodeListener.failIfAllTestsSkipped();775 }776 addListener(this.exitCodeListener);777 if (m_useDefaultListeners) {778 addReporter(SuiteHTMLReporter.class);779 addReporter(Main.class);780 addReporter(FailedReporter.class);781 addReporter(XMLReporter.class);782 if (RuntimeBehavior.useOldTestNGEmailableReporter()) {783 addReporter(EmailableReporter.class);784 } else if (RuntimeBehavior.useEmailableReporter()) {785 addReporter(EmailableReporter2.class);786 }787 addReporter(JUnitReportReporter.class);788 if (m_verbose != null && m_verbose > 4) {789 addListener(new VerboseReporter("[TestNG] "));790 }791 }792 }793 private void initializeConfiguration() {794 ITestObjectFactory factory = m_objectFactory;795 //796 // Install the listeners found in ServiceLoader (or use the class797 // loader for tests, if specified).798 //799 addServiceLoaderListeners();800 //801 // Install the listeners found in the suites802 //803 for (XmlSuite s : m_suites) {804 addListeners(s);805 //806 // Install the method selectors807 //808 for (XmlMethodSelector methodSelector : s.getMethodSelectors()) {809 addMethodSelector(methodSelector.getClassName(), methodSelector.getPriority());810 addMethodSelector(methodSelector);811 }812 //813 // Find if we have an object factory814 //815 if (s.getObjectFactory() != null) {816 if (factory == null) {817 factory = s.getObjectFactory();818 } else {819 throw new TestNGException("Found more than one object-factory tag in your suites");820 }821 }822 }823 m_configuration.setAnnotationFinder(new JDK15AnnotationFinder(getAnnotationTransformer()));824 m_configuration.setHookable(m_hookable);825 m_configuration.setConfigurable(m_configurable);826 m_configuration.setObjectFactory(factory);827 m_configuration.setAlwaysRunListeners(this.m_alwaysRun);828 m_configuration.setExecutorFactory(getExecutorFactory());829 }830 private void addListeners(XmlSuite s) {831 for (String listenerName : s.getListeners()) {832 Class<?> listenerClass = ClassHelper.forName(listenerName);833 // If specified listener does not exist, a TestNGException will be thrown834 if (listenerClass == null) {835 throw new TestNGException(836 "Listener " + listenerName + " was not found in project's classpath");837 }838 ITestNGListener listener = (ITestNGListener) InstanceCreator.newInstance(listenerClass);839 addListener(listener);840 }841 // Add the child suite listeners842 List<XmlSuite> childSuites = s.getChildSuites();843 for (XmlSuite c : childSuites) {844 addListeners(c);845 }846 }847 /** Using reflection to remain Java 5 compliant. */848 private void addServiceLoaderListeners() {849 Iterable<ITestNGListener> loader =850 m_serviceLoaderClassLoader != null851 ? ServiceLoader.load(ITestNGListener.class, m_serviceLoaderClassLoader)852 : ServiceLoader.load(ITestNGListener.class);853 for (ITestNGListener l : loader) {854 Utils.log("[TestNG]", 2, "Adding ServiceLoader listener:" + l);855 if (m_listenersToSkipFromBeingWiredIn.contains(l.getClass().getName())) {856 Utils.log("[TestNG]", 2, "Skipping adding the listener :" + l);857 continue;858 }859 addListener(l);860 addServiceLoaderListener(l);861 }862 }863 /**864 * Before suites are executed, do a sanity check to ensure all required conditions are met. If865 * not, throw an exception to stop test execution866 *867 * @throws TestNGException if the sanity check fails868 */869 private void sanityCheck() {870 XmlSuiteUtils.validateIfSuitesContainDuplicateTests(m_suites);871 XmlSuiteUtils.adjustSuiteNamesToEnsureUniqueness(m_suites);872 }873 /** Invoked by the remote runner. */874 public void initializeEverything() {875 // The Eclipse plug-in (RemoteTestNG) might have invoked this method already876 // so don't initialize suites twice.877 if (m_isInitialized) {878 return;879 }880 initializeSuitesAndJarFile();881 initializeConfiguration();882 initializeDefaultListeners();883 initializeCommandLineSuites();884 initializeCommandLineSuitesParams();885 initializeCommandLineSuitesGroups();886 m_isInitialized = true;887 }888 /** Run TestNG. */889 public void run() {890 initializeEverything();891 sanityCheck();892 runExecutionListeners(true /* start */);893 runSuiteAlterationListeners();894 m_start = System.currentTimeMillis();895 List<ISuite> suiteRunners = runSuites();896 m_end = System.currentTimeMillis();897 if (null != suiteRunners) {898 generateReports(suiteRunners);899 }900 runExecutionListeners(false /* finish */);901 exitCode = this.exitCodeListener.getStatus();902 if (exitCodeListener.noTestsFound()) {903 if (TestRunner.getVerbose() > 1) {904 System.err.println("[TestNG] No tests found. Nothing was run");905 usage();906 }907 }908 m_instance = null;909 m_jCommander = null;910 }911 /**912 * Run the test suites.913 *914 * <p>This method can be overridden by subclass. <br>915 * For example, DistributedTestNG to run in master/slave mode according to commandline args.916 *917 * @return - List of suites that were run as {@link ISuite} objects.918 * @since 6.9.11 when moving distributed/remote classes out into separate project919 */920 protected List<ISuite> runSuites() {921 return runSuitesLocally();922 }923 private void runSuiteAlterationListeners() {924 for (IAlterSuiteListener l : m_alterSuiteListeners.values()) {925 l.alter(m_suites);926 }927 }928 private void runExecutionListeners(boolean start) {929 for (IExecutionListener l : m_configuration.getExecutionListeners()) {930 if (start) {931 l.onExecutionStart();932 } else {933 l.onExecutionFinish();934 }935 }936 }937 private static void usage() {938 if (m_jCommander == null) {939 m_jCommander = new JCommander(new CommandLineArgs());940 }941 m_jCommander.usage();942 }943 private void generateReports(List<ISuite> suiteRunners) {944 for (IReporter reporter : m_reporters.values()) {945 try {946 long start = System.currentTimeMillis();947 reporter.generateReport(m_suites, suiteRunners, m_outputDir);948 Utils.log(949 "TestNG",950 2,951 "Time taken by " + reporter + ": " + (System.currentTimeMillis() - start) + " ms");952 } catch (Exception ex) {953 System.err.println("[TestNG] Reporter " + reporter + " failed");954 ex.printStackTrace(System.err);955 }956 }957 }958 /**959 * This needs to be public for maven2, for now..At least until an alternative mechanism is found.960 * @return The locally run suites961 */962 public List<ISuite> runSuitesLocally() {963 if (m_suites.isEmpty()) {964 error("No test suite found. Nothing to run");965 usage();966 return Collections.emptyList();967 }968 SuiteRunnerMap suiteRunnerMap = new SuiteRunnerMap();969 // First initialize the suite runners to ensure there are no configuration issues.970 // Create a map with XmlSuite as key and corresponding SuiteRunner as value971 for (XmlSuite xmlSuite : m_suites) {972 createSuiteRunners(suiteRunnerMap, xmlSuite);973 }974 //975 // Run suites976 //977 if (m_suiteThreadPoolSize == 1 && !m_randomizeSuites) {978 // Single threaded and not randomized: run the suites in order979 for (XmlSuite xmlSuite : m_suites) {980 runSuitesSequentially(981 xmlSuite, suiteRunnerMap, getVerbose(xmlSuite), getDefaultSuiteName());982 }983 //984 // Generate the suites report985 //986 return Lists.newArrayList(suiteRunnerMap.values());987 }988 // Multithreaded: generate a dynamic graph that stores the suite hierarchy. This is then989 // used to run related suites in specific order. Parent suites are run only990 // once all the child suites have completed execution991 IDynamicGraph<ISuite> suiteGraph = new DynamicGraph<>();992 for (XmlSuite xmlSuite : m_suites) {993 populateSuiteGraph(suiteGraph, suiteRunnerMap, xmlSuite);994 }995 IThreadWorkerFactory<ISuite> factory =996 new SuiteWorkerFactory(997 suiteRunnerMap, 0 /* verbose hasn't been set yet */, getDefaultSuiteName());998 ITestNGThreadPoolExecutor pooledExecutor = this.getExecutorFactory().newSuiteExecutor(999 "suites",1000 suiteGraph,1001 factory,1002 m_suiteThreadPoolSize,1003 m_suiteThreadPoolSize,1004 Integer.MAX_VALUE,1005 TimeUnit.MILLISECONDS,1006 new LinkedBlockingQueue<>(),1007 null);1008 Utils.log("TestNG", 2, "Starting executor for all suites");1009 // Run all suites in parallel1010 pooledExecutor.run();1011 try {1012 pooledExecutor.awaitTermination(Long.MAX_VALUE, TimeUnit.MILLISECONDS);1013 pooledExecutor.shutdownNow();1014 } catch (InterruptedException handled) {1015 Thread.currentThread().interrupt();1016 error("Error waiting for concurrent executors to finish " + handled.getMessage());1017 }1018 //1019 // Generate the suites report1020 //1021 return Lists.newArrayList(suiteRunnerMap.values());1022 }1023 private static void error(String s) {1024 LOGGER.error(s);1025 }1026 /**1027 * @return the verbose level, checking in order: the verbose level on the suite, the verbose level1028 * on the TestNG object, or 1.1029 */1030 private int getVerbose(XmlSuite xmlSuite) {1031 return xmlSuite.getVerbose() != null1032 ? xmlSuite.getVerbose()1033 : (m_verbose != null ? m_verbose : DEFAULT_VERBOSE);1034 }1035 /**1036 * Recursively runs suites. Runs the children suites before running the parent suite. This is done1037 * so that the results for parent suite can reflect the combined results of the children suites.1038 *1039 * @param xmlSuite XML Suite to be executed1040 * @param suiteRunnerMap Maps {@code XmlSuite}s to respective {@code ISuite}1041 * @param verbose verbose level1042 * @param defaultSuiteName default suite name1043 */1044 private void runSuitesSequentially(1045 XmlSuite xmlSuite, SuiteRunnerMap suiteRunnerMap, int verbose, String defaultSuiteName) {1046 for (XmlSuite childSuite : xmlSuite.getChildSuites()) {1047 runSuitesSequentially(childSuite, suiteRunnerMap, verbose, defaultSuiteName);1048 }1049 SuiteRunnerWorker srw =1050 new SuiteRunnerWorker(1051 suiteRunnerMap.get(xmlSuite), suiteRunnerMap, verbose, defaultSuiteName);1052 srw.run();1053 }1054 /**1055 * Populates the dynamic graph with the reverse hierarchy of suites. Edges are added pointing from1056 * child suite runners to parent suite runners, hence making parent suite runners dependent on all1057 * the child suite runners1058 *1059 * @param suiteGraph dynamic graph representing the reverse hierarchy of SuiteRunners1060 * @param suiteRunnerMap Map with XMLSuite as key and its respective SuiteRunner as value1061 * @param xmlSuite XML Suite1062 */1063 private void populateSuiteGraph(1064 IDynamicGraph<ISuite> suiteGraph /* OUT */, SuiteRunnerMap suiteRunnerMap, XmlSuite xmlSuite) {1065 ISuite parentSuiteRunner = suiteRunnerMap.get(xmlSuite);1066 if (xmlSuite.getChildSuites().isEmpty()) {1067 suiteGraph.addNode(parentSuiteRunner);1068 } else {1069 for (XmlSuite childSuite : xmlSuite.getChildSuites()) {1070 suiteGraph.addEdge(0, parentSuiteRunner, suiteRunnerMap.get(childSuite));1071 populateSuiteGraph(suiteGraph, suiteRunnerMap, childSuite);1072 }1073 }1074 }1075 /**1076 * Creates the {@code SuiteRunner}s and populates the suite runner map with this information1077 *1078 * @param suiteRunnerMap Map with XMLSuite as key and it's respective SuiteRunner as value. This1079 * is updated as part of this method call1080 * @param xmlSuite Xml Suite (and its children) for which {@code SuiteRunner}s are created1081 */1082 private void createSuiteRunners(SuiteRunnerMap suiteRunnerMap /* OUT */, XmlSuite xmlSuite) {1083 if (null != m_isJUnit && !m_isJUnit.equals(XmlSuite.DEFAULT_JUNIT)) {1084 xmlSuite.setJUnit(m_isJUnit);1085 }1086 // If the skip flag was invoked on the command line, it1087 // takes precedence1088 if (null != m_skipFailedInvocationCounts) {1089 xmlSuite.setSkipFailedInvocationCounts(m_skipFailedInvocationCounts);1090 }1091 // Override the XmlSuite verbose value with the one from TestNG1092 if (m_verbose != null) {1093 xmlSuite.setVerbose(m_verbose);1094 }1095 if (null != m_configFailurePolicy) {1096 xmlSuite.setConfigFailurePolicy(m_configFailurePolicy);1097 }1098 Set<XmlMethodSelector> selectors = Sets.newHashSet();1099 for (XmlTest t : xmlSuite.getTests()) {1100 for (Map.Entry<String, Integer> ms : m_methodDescriptors.entrySet()) {1101 XmlMethodSelector xms = new XmlMethodSelector();1102 xms.setName(ms.getKey());1103 xms.setPriority(ms.getValue());1104 selectors.add(xms);1105 }1106 selectors.addAll(m_selectors);1107 t.getMethodSelectors().addAll(Lists.newArrayList(selectors));1108 }1109 suiteRunnerMap.put(xmlSuite, createSuiteRunner(xmlSuite));1110 for (XmlSuite childSuite : xmlSuite.getChildSuites()) {1111 createSuiteRunners(suiteRunnerMap, childSuite);1112 }1113 }1114 /** Creates a suite runner and configures its initial state */1115 private SuiteRunner createSuiteRunner(XmlSuite xmlSuite) {1116 DataProviderHolder holder = new DataProviderHolder();1117 holder.addListeners(m_dataProviderListeners.values());1118 holder.addInterceptors(m_dataProviderInterceptors.values());1119 SuiteRunner result =1120 new SuiteRunner(1121 getConfiguration(),1122 xmlSuite,1123 m_outputDir,1124 m_testRunnerFactory,1125 m_useDefaultListeners,1126 m_methodInterceptors,1127 m_invokedMethodListeners.values(),1128 m_testListeners.values(),1129 m_classListeners.values(),1130 holder,1131 Systematiser.getComparator());1132 for (ISuiteListener isl : m_suiteListeners.values()) {1133 result.addListener(isl);1134 }1135 for (IReporter r : result.getReporters()) {1136 maybeAddListener(m_reporters, r.getClass(), r, true);1137 }1138 for (IConfigurationListener cl : m_configuration.getConfigurationListeners()) {1139 result.addConfigurationListener(cl);1140 }1141 m_executionVisualisers.values().forEach(result::addListener);1142 return result;1143 }1144 protected IConfiguration getConfiguration() {1145 return m_configuration;1146 }1147 /**1148 * The TestNG entry point for command line execution.1149 *1150 * @param argv the TestNG command line parameters.1151 */1152 public static void main(String[] argv) {1153 TestNG testng = privateMain(argv, null);1154 System.exit(testng.getStatus());1155 }1156 /**1157 * <B>Note</B>: this method is not part of the public API and is meant for internal usage only.1158 *1159 * @param argv The param arguments1160 * @param listener The listener1161 * @return The TestNG instance1162 */1163 public static TestNG privateMain(String[] argv, ITestListener listener) {1164 TestNG result = new TestNG();1165 if (null != listener) {1166 result.addListener(listener);1167 }1168 //1169 // Parse the arguments1170 //1171 try {1172 CommandLineArgs cla = new CommandLineArgs();1173 m_jCommander = new JCommander(cla);1174 m_jCommander.parse(argv);1175 validateCommandLineParameters(cla);1176 result.configure(cla);1177 } catch (ParameterException ex) {1178 exitWithError(ex.getMessage());1179 }1180 //1181 // Run1182 //1183 try {1184 result.run();1185 } catch (TestNGException ex) {1186 if (TestRunner.getVerbose() > 1) {1187 ex.printStackTrace(System.out);1188 } else {1189 error(ex.getMessage());1190 }1191 result.exitCode = ExitCode.newExitCodeRepresentingFailure();1192 }1193 return result;1194 }1195 /**1196 * Configure the TestNG instance based on the command line parameters.1197 *1198 * @param cla The command line parameters1199 */1200 protected void configure(CommandLineArgs cla) {1201 if (cla.verbose != null) {1202 setVerbose(cla.verbose);1203 }1204 if (cla.dependencyInjectorFactoryClass != null) {1205 Class<?> clazz = ClassHelper.forName(cla.dependencyInjectorFactoryClass);1206 if (clazz != null && IInjectorFactory.class.isAssignableFrom(clazz)) {1207 m_configuration.setInjectorFactory(InstanceCreator.newInstance((Class<IInjectorFactory>) clazz));1208 }1209 }1210 if (cla.threadPoolFactoryClass != null) {1211 setExecutorFactoryClass(cla.threadPoolFactoryClass);1212 }1213 setOutputDirectory(cla.outputDirectory);1214 String testClasses = cla.testClass;1215 if (null != testClasses) {1216 String[] strClasses = testClasses.split(",");1217 List<Class<?>> classes = Lists.newArrayList();1218 for (String c : strClasses) {1219 classes.add(ClassHelper.fileToClass(c));1220 }1221 setTestClasses(classes.toArray(new Class[0]));1222 }1223 setOutputDirectory(cla.outputDirectory);1224 if (cla.testNames != null) {1225 setTestNames(Arrays.asList(cla.testNames.split(",")));...

Full Screen

Full Screen

Source:SchedulerTest.java Github

copy

Full Screen

...77 final Scheduler scheduler = new Scheduler();78 final ExecutorService executorService;79 //executorService = Executors.newSingleThreadExecutor();80 executorService = Executors.newCachedThreadPool();81 scheduler.setExecutorFactory(executorService);82 scheduler.addTask("*", new Task() {83 @Override84 public void execute(TaskContext context) {85 int id = _id.getAndIncrement();86 println(" start " + id, context.getTime());87 sleep(125 * 1000);88 println(" end " + id, context.getTime());89 }90 @Override91 public String getTaskName() {92 return "*";93 }94 });95 scheduler.addTask("*", new Task() {...

Full Screen

Full Screen

Source:JCacheExpiryAndMaximumSizeTest.java Github

copy

Full Screen

...63 CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration =64 new MutableCacheEntryListenerConfiguration<>(() -> listener,65 /* filterFactory */ null, /* isOldValueRequired */ false, /* isSynchronous */ true);66 configuration.addCacheEntryListenerConfiguration(listenerConfiguration);67 configuration.setExecutorFactory(MoreExecutors::directExecutor);68 configuration.setExpiryFactory(Optional.of(() -> expiry));69 configuration.setTickerFactory(() -> ticker::read);70 return configuration;71 }72 @Test73 public void expiry() {74 jcache.put(KEY_1, VALUE_1);75 verify(expiry, times(1)).expireAfterCreate(anyInt(), anyInt(), anyLong());76 jcache.put(KEY_1, VALUE_2);77 verify(expiry).expireAfterUpdate(anyInt(), anyInt(), anyLong(), anyLong());78 jcache.get(KEY_1);79 verify(expiry).expireAfterRead(anyInt(), anyInt(), anyLong(), anyLong());80 }81 @Test...

Full Screen

Full Screen

Source:Configuration.java Github

copy

Full Screen

...88 public void setAlwaysRunListeners(boolean alwaysRunListeners) {89 this.alwaysRunListeners = alwaysRunListeners;90 }91 @Override92 public void setExecutorFactory(IExecutorFactory factory) {93 this.m_executorFactory = factory;94 }95 @Override96 public IExecutorFactory getExecutorFactory() {97 return this.m_executorFactory;98 }99 @Override100 public boolean alwaysRunListeners() {101 return alwaysRunListeners;102 }103 @Override104 public void setInjectorFactory(IInjectorFactory factory) {105 this.injectorFactory = factory;106 }...

Full Screen

Full Screen

Source:JCacheMaximumWeightTest.java Github

copy

Full Screen

...47 CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration =48 new MutableCacheEntryListenerConfiguration<Integer, Integer>(() -> listener,49 /* filterFactory */ null, /* isOldValueRequired */ true, /* isSynchronous */ true);50 configuration.addCacheEntryListenerConfiguration(listenerConfiguration);51 configuration.setExecutorFactory(MoreExecutors::directExecutor);52 return configuration;53 }54 @Test55 public void evict() {56 for (int i = 0; i < MAXIMUM; i++) {57 jcache.put(i, 1);58 }59 jcache.put(2 * MAXIMUM, MAXIMUM / 2);60 assertThat(removedWeight.get(), is(MAXIMUM / 2));61 }62}...

Full Screen

Full Screen

Source:JCacheMaximumSizeTest.java Github

copy

Full Screen

...43 CacheEntryListenerConfiguration<Integer, Integer> listenerConfiguration =44 new MutableCacheEntryListenerConfiguration<Integer, Integer>(() -> listener,45 /* filterFactory */ null, /* isOldValueRequired */ false, /* isSynchronous */ true);46 configuration.addCacheEntryListenerConfiguration(listenerConfiguration);47 configuration.setExecutorFactory(MoreExecutors::directExecutor);48 return configuration;49 }50 @Test51 public void evict() {52 for (int i = 0; i < 2 * MAXIMUM; i++) {53 jcache.put(i, i);54 }55 assertThat(removed.get(), is(MAXIMUM));56 }57}...

Full Screen

Full Screen

Source:IConfiguration.java Github

copy

Full Screen

...20 List<IConfigurationListener> getConfigurationListeners();21 void addConfigurationListener(IConfigurationListener cl);22 boolean alwaysRunListeners();23 void setAlwaysRunListeners(boolean alwaysRun);24 void setExecutorFactory(IExecutorFactory factory);25 IExecutorFactory getExecutorFactory();26 IInjectorFactory getInjectorFactory();27 void setInjectorFactory(IInjectorFactory factory);28 boolean getOverrideIncludedMethods();29 void setOverrideIncludedMethods(boolean overrideIncludedMethods);30}...

Full Screen

Full Screen

setExecutorFactory

Using AI Code Generation

copy

Full Screen

1import java.util.concurrent.ExecutorService;2import java.util.concurrent.Executors;3import org.testng.TestNG;4public class TestNGExample {5 public static void main(String[] args) {6 TestNG testNG = new TestNG();7 testNG.setExecutorFactory(() -> Executors.newFixedThreadPool(5));8 testNG.setTestClasses(new Class[] { TestClass1.class, TestClass2.class });9 testNG.run();10 }11}12import org.testng.annotations.Test;13public class TestClass1 {14 public void testMethod1() throws InterruptedException {15 System.out.println("TestNG Thread Pool Example!");16 Thread.sleep(1000);17 System.out.printf("Thread Id : %s%n", Thread.currentThread().getId());18 }19}20import org.testng.annotations.Test;21public class TestClass2 {22 public void testMethod2() throws InterruptedException {23 System.out.println("TestNG Thread Pool Example!");24 Thread.sleep(1000);25 System.out.printf("Thread Id : %s%n", Thread.currentThread().getId());26 }27}

Full Screen

Full Screen

setExecutorFactory

Using AI Code Generation

copy

Full Screen

1import org.testng.TestNG;2import org.testng.annotations.Test;3import org.testng.xml.XmlSuite;4import java.util.ArrayList;5import java.util.List;6public class TestNGParallelSuite {7 public void test() {8 TestNG myTestNG = new TestNG();9 XmlSuite mySuite = new XmlSuite();10 mySuite.setName("MySuite");11 XmlSuite myTest = new XmlSuite();12 myTest.setName("MyTest");13 myTest.setParameters(null);14 List<String> myClasses = new ArrayList<String>();15 myClasses.add("TestNGTest1");16 myClasses.add("TestNGTest2");17 myTest.setXmlClasses(myClasses);18 List<XmlSuite> myTests = new ArrayList<XmlSuite>();19 myTests.add(myTest);20 mySuite.setTests(myTests);21 List<XmlSuite> mySuites = new ArrayList<XmlSuite>();22 mySuites.add(mySuite);23 myTestNG.setXmlSuites(mySuites);24 myTestNG.setParallel(XmlSuite.ParallelMode.METHODS);25 myTestNG.setThreadCount(2);26 myTestNG.setExecutorFactory(new MyExecutorFactory());27 myTestNG.run();28 }29}30public class MyExecutorFactory implements IExecutorFactory {31 public IExecutor newInstance(IHookable hookable, ITestNGMethod method, ITestResult testResult) {32 return new MyExecutor(hookable, method, testResult);33 }34}35public class MyExecutor implements IExecutor {36 private final IHookable hookable;

Full Screen

Full Screen

TestNG tutorial

TestNG is a Java-based open-source framework for test automation that includes various test types, such as unit testing, functional testing, E2E testing, etc. TestNG is in many ways similar to JUnit and NUnit. But in contrast to its competitors, its extensive features make it a lot more reliable framework. One of the major reasons for its popularity is its ability to structure tests and improve the scripts' readability and maintainability. Another reason can be the important characteristics like the convenience of using multiple annotations, reliance, and priority that make this framework popular among developers and testers for test design. You can refer to the TestNG tutorial to learn why you should choose the TestNG framework.

Chapters

  1. JUnit 5 vs. TestNG: Compare and explore the core differences between JUnit 5 and TestNG from the Selenium WebDriver viewpoint.
  2. Installing TestNG in Eclipse: Start installing the TestNG Plugin and learn how to set up TestNG in Eclipse to begin constructing a framework for your test project.
  3. Create TestNG Project in Eclipse: Get started with creating a TestNG project and write your first TestNG test script.
  4. Automation using TestNG: Dive into how to install TestNG in this Selenium TestNG tutorial, the fundamentals of developing an automation script for Selenium automation testing.
  5. Parallel Test Execution in TestNG: Here are some essential elements of parallel testing with TestNG in this Selenium TestNG tutorial.
  6. Creating TestNG XML File: Here is a step-by-step tutorial on creating a TestNG XML file to learn why and how it is created and discover how to run the TestNG XML file being executed in parallel.
  7. Automation with Selenium, Cucumber & TestNG: Explore for an in-depth tutorial on automation using Selenium, Cucumber, and TestNG, as TestNG offers simpler settings and more features.
  8. JUnit Selenium Tests using TestNG: Start running your regular and parallel tests by looking at how to run test cases in Selenium using JUnit and TestNG without having to rewrite the tests.
  9. Group Test Cases in TestNG: Along with the explanation and demonstration using relevant TestNG group examples, learn how to group test cases in TestNG.
  10. Prioritizing Tests in TestNG: Get started with how to prioritize test cases in TestNG for Selenium automation testing.
  11. Assertions in TestNG: Examine what TestNG assertions are, the various types of TestNG assertions, and situations that relate to Selenium automated testing.
  12. DataProviders in TestNG: Deep dive into learning more about TestNG's DataProvider and how to effectively use it in our test scripts for Selenium test automation.
  13. Parameterization in TestNG: Here are the several parameterization strategies used in TestNG tests and how to apply them in Selenium automation scripts.
  14. TestNG Listeners in Selenium WebDriver: Understand the various TestNG listeners to utilize them effectively for your next plan when working with TestNG and Selenium automation.
  15. TestNG Annotations: Learn more about the execution order and annotation attributes, and refer to the prerequisites required to set up TestNG.
  16. TestNG Reporter Log in Selenium: Find out how to use the TestNG Reporter Log and learn how to eliminate the need for external software with TestNG Reporter Class to boost productivity.
  17. TestNG Reports in Jenkins: Discover how to generate TestNG reports in Jenkins if you want to know how to create, install, and share TestNG reports in Jenkins.

Certification

You can push your abilities to do automated testing using TestNG and advance your career by earning a TestNG certification. Check out our TestNG certification.

YouTube

Watch this complete tutorial to learn how you can leverage the capabilities of the TestNG framework for Selenium automation testing.

Run Testng automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful