How to use ConcurrentModificationExceptionOnMultiThreadedVerificationTest class of org.mockitousage.bugs package

Best Mockito code snippet using org.mockitousage.bugs.ConcurrentModificationExceptionOnMultiThreadedVerificationTest

Run Mockito automation tests on LambdaTest cloud grid

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

copy
1/**
2 * Copyright (c) 2007 Mockito contributors
3 * This program is made available under the terms of the MIT License.
4 */
5package org.mockitousage.bugs;
6
7
8import java.util.concurrent.Callable;
9import java.util.concurrent.ExecutorService;
10import org.junit.Test;
11import org.mockito.Mockito;
12
13
14// issue 322
15// the only evidence of this failing test was shown on a RHEL with IBM J9 JVM 64bits
16// 
17// details
18// java.fullversion=JRE 1.6.0 IBM J9 2.6 Linux amd64-64 20111113_94967  (JIT enabled, AOT enabled)
19// Linux2.6.32-220.4.2.el6.x86_64 #1SMP Mon Feb 6 16:39:28EST 2012x86_64 x86_64 x86_64 GNU/Linux
20public class ConcurrentModificationExceptionOnMultiThreadedVerificationTest {
21    int nThreads = 1;
22
23    static final int TIMES = 100;
24
25    static final int INTERVAL_MILLIS = 10;
26
27    ConcurrentModificationExceptionOnMultiThreadedVerificationTest.ITarget target = Mockito.mock(ConcurrentModificationExceptionOnMultiThreadedVerificationTest.ITarget.class);
28
29    ExecutorService fixedThreadPool;
30
31    @Test
32    public void shouldSuccessfullyVerifyConcurrentInvocationsWithTimeout() throws Exception {
33        int potentialOverhead = 1000;// Leave 1000ms extra before timing out as leeway for test overheads
34
35        int expectedMaxTestLength = ((ConcurrentModificationExceptionOnMultiThreadedVerificationTest.TIMES) * (ConcurrentModificationExceptionOnMultiThreadedVerificationTest.INTERVAL_MILLIS)) + potentialOverhead;
36        Mockito.reset(target);
37        startInvocations();
38        Mockito.verify(target, Mockito.timeout(expectedMaxTestLength).times(((ConcurrentModificationExceptionOnMultiThreadedVerificationTest.TIMES) * (nThreads)))).targetMethod("arg");
39        Mockito.verifyNoMoreInteractions(target);
40    }
41
42    public class TargetInvoker implements Callable<Object> {
43        private final int seq;
44
45        TargetInvoker(int seq) {
46            this.seq = seq;
47        }
48
49        public Object call() throws Exception {
50            System.err.println(("started " + (seq)));
51            for (int i = 0; i < (ConcurrentModificationExceptionOnMultiThreadedVerificationTest.TIMES); i++) {
52                Thread.yield();
53                target.targetMethod("arg");
54                Thread.sleep(((long) (ConcurrentModificationExceptionOnMultiThreadedVerificationTest.INTERVAL_MILLIS)));
55            }
56            System.err.println(("finished" + (seq)));
57            return seq;
58        }
59    }
60
61    public interface ITarget {
62        String targetMethod(String arg);
63    }
64}
65
66
Full Screen
copy
1package fr.inria.astor.test.repair.evaluation.regression;
2
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.assertTrue;
5
6import java.io.File;
7import java.util.ArrayList;
8import java.util.Arrays;
9import java.util.List;
10
11import org.apache.log4j.Level;
12import org.junit.Before;
13import org.junit.Ignore;
14import org.junit.Test;
15
16import fr.inria.astor.core.entities.ProgramVariant;
17import fr.inria.main.CommandSummary;
18import fr.inria.main.FileLauncher;
19import fr.inria.main.evolution.AstorMain;
20
21/**
22 * 
23 * @author Matias Martinez
24 *
25 */
26@Ignore
27public class MockitoTest {
28
29	
30	String exampleRoot = "./examples/";
31	ClassLoader classLoader = null;
32	File dataDir = null;
33	
34	@Before
35	public void setUp(){
36		classLoader = getClass().getClassLoader();
37		dataDir = new File(classLoader.getResource("data_projects").getPath());
38	}
39	
40	
41	
42	public List<String> getParticularIssueLibs(File f ){
43		if(!f.exists())
44			throw new IllegalAccessError(f.getAbsolutePath() + " not found");
45		List<String> otherlibs = new ArrayList<>();
46		if(f.isFile())
47			return otherlibs;
48		for(File folder : f.listFiles()){
49			if(folder.getName().endsWith(".jar")){
50				otherlibs.add(folder.getAbsolutePath());
51			}
52			else{
53				otherlibs.addAll(getParticularIssueLibs(folder));
54			}
55		}
56		return otherlibs;
57	}
58	
59	@Test
60	public void testMockito29() throws Exception{
61		int id = 29;
62		testMockito(id);
63	}
64	
65	@Test
66	public void testMockito22() throws Exception{
67		/*fr.inria.main.AbstractMain.processArguments(AbstractMain.java:286) -
68		//command line arguments: [-out  /local/scr/mtufano/Mockito/22/b/random-global-default/1  
69		 * -jvm4testexecution  /usr/local/jdk1.7.0_80/bin/  -maxgen  1000000 
70		 *  -population  1  -maxtime  180  -timezone  America/New_York  
71		 *  -customop  fr.inria.astor.approaches.jgenprog.operators.InsertAfterOp:fr.inria.astor.approaches.jgenprog.operators.InsertBeforeOp:fr.inria.astor.approaches.jgenprog.operators.ReplaceOp  
72		 *  -seed  1  -javacompliancelevel  6  -package  org.mockito  -binjavafolder  target/classes  -bintestfolder  target/test-classes  
73		 *  -srcjavafolder  src  -srctestfolder  test  -learningdir  ../../out/learningdir/Mockito/22/b/ 
74		 *   -location  ../../dat/defects4j/Mockito/22/b/  -failing  org.mockito.internal.matchers.EqualityTest  
75		 *   -dependencies  ../../dat/defects4j/Mockito/22/b/lib/build/ant-googlecode-0.0.3.jar:
76		 *   ../../dat/defects4j/Mockito/22/b/lib/build/bnd-0.0.313.jar:
77		 *   ../../dat/defects4j/Mockito/22/b/lib/build/ant4hg-V0.07.jar:
78		 *   ../../dat/defects4j/Mockito/22/b/lib/build/jaxen-1.1.1.jar:.
79		 *   ./../dat/defects4j/Mockito/22/b/lib/build/asm-3.1.jar:
80		 *   ../../dat/defects4j/Mockito/22/b/lib/build/sorcerer.jar:
81		 *   ../../dat/defects4j/Mockito/22/b/lib/build/pmd-4.1.jar:
82		 *   ../../dat/defects4j/Mockito/22/b/lib/build/maven-ant-tasks-2.0.9.jar:
83		 *   ../../dat/defects4j/Mockito/22/b/lib/build/jarjar-1.0.jar:
84		 *   ../../dat/defects4j/Mockito/22/b/lib/compile/junit-4.10.jar:
85		 *   ../../dat/defects4j/Mockito/22/b/lib/test/fest-util-1.1.4.jar:
86		 *   ../../dat/defects4j/Mockito/22/b/lib/test/fest-assert-1.3.jar:
87		 *   ../../dat/defects4j/Mockito/22/b/lib/test/powermock-reflect-1.2.5.jar:
88		 *   ../../dat/defects4j/Mockito/22/b/lib/sources/com.springsource.org.hamcrest.core-1.1.0-sources.jar:
89		 *   ../../dat/defects4j/Mockito/22/b/lib/sources/cglib-and-asm-1.0-sources.jar:
90		 *   ../../dat/defects4j/Mockito/22/b/lib/sources/objenesis-2.1-sources.jar:
91		 *   ../../dat/defects4j/Mockito/22/b/lib/repackaged/cglib-and-asm-1.0.jar:
92		 *   ../../dat/defects4j/Mockito/22/b/lib/run/com.springsource.org.hamcrest.core-1.1.0.jar:
93		 *   ../../dat/defects4j/Mockito/22/b/lib/run/objenesis-2.1.jar  
94		 *   -scope  fr.inria.astor.core.loop.spaces.ingredients.scopes.ctscopes.CtGlobalIngredientScope  
95		 *   -ingredientstrategy  fr.inria.astor.core.loop.spaces.ingredients.ingredientSearch.EfficientIngredientStrategy  
96		 *   -classestoinstrument  org.mockito.internal.progress.ThreadSafeMockingProgress:org.mockito.MockitoAnnotations:org.mockito.exceptions.misusing.MockitoConfigurationException:org.mockito.internal.configuration.injection.filter.MockCandidateFilter:org.mockito.internal.invocation.realmethod.RealMethod:org.mockito.exceptions.misusing.NullInsteadOfMockException:org.mockito.Mock:org.mockito.internal.configuration.ClassPathLoader:org.mockito.exceptions.base.MockitoException:org.mockito.internal.configuration.InjectingAnnotationEngine:org.mockito.exceptions.base.MockitoAssertionError:org.mockito.exceptions.verification.TooLittleActualInvocations:org.mockito.invocation.MockHandler:org.mockito.internal.configuration.SpyAnnotationEngine:org.mockito.exceptions.verification.NeverWantedButInvoked:org.mockito.internal.invocation.MockitoMethod:org.mockito.internal.configuration.injection.ConstructorInjection:org.mockito.stubbing.Answer:org.mockito.exceptions.misusing.FriendlyReminderException:org.mockito.exceptions.misusing.InvalidUseOfMatchersException:org.mockito.internal.configuration.injection.scanner.InjectMocksScanner:org.mockito.exceptions.verification.NoInteractionsWanted:org.mockito.internal.matchers.Equality:org.mockito.invocation.Invocation:org.mockito.internal.configuration.GlobalConfiguration:org.mockito.exceptions.PrintableInvocation:org.mockito.plugins.MockMaker:org.mockito.configuration.IMockitoConfiguration:org.mockito.internal.configuration.injection.MockInjection:org.mockito.internal.util.collections.Sets:org.mockito.exceptions.misusing.WrongTypeOfReturnValue:org.mockito.invocation.InvocationOnMock:org.mockito.internal.configuration.MockAnnotationProcessor:org.mockito.exceptions.misusing.UnfinishedStubbingException:org.mockito.internal.util.MockUtil:org.mockito.exceptions.Reporter:org.mockito.exceptions.misusing.MissingMethodInvocationException:org.mockito.internal.configuration.injection.scanner.MockScanner:org.mockito.exceptions.misusing.UnfinishedVerificationException:org.mockito.internal.configuration.injection.filter.FinalMockCandidateFilter:org.mockito.mock.MockName:org.mockito.internal.configuration.injection.filter.NameBasedCandidateFilter:org.mockito.exceptions.verification.WantedButNotInvoked:org.mockito.configuration.DefaultMockitoConfiguration:org.mockito.internal.configuration.injection.filter.TypeBasedCandidateFilter:org.mockito.internal.util.reflection.FieldInitializer:org.mockito.exceptions.misusing.CannotVerifyStubOnlyMock:org.mockito.internal.progress.ArgumentMatcherStorageImpl:org.mockito.internal.configuration.MockitoAnnotationsMockAnnotationProcessor:org.mockito.exceptions.verification.TooManyActualInvocations:org.mockito.internal.util.Checks:org.mockito.Captor:org.mockito.internal.invocation.AbstractAwareMethod:org.mockito.internal.util.collections.ListUtil:org.mockito.internal.progress.ArgumentMatcherStorage:org.mockito.internal.configuration.injection.MockInjectionStrategy:org.mockito.exceptions.verification.VerificationInOrderFailure:org.mockito.internal.configuration.FieldAnnotationProcessor:org.mockito.internal.configuration.injection.PropertyAndSetterInjection:org.mockito.internal.configuration.DefaultAnnotationEngine:org.mockito.internal.creation.CglibMockMaker:org.mockito.invocation.DescribedInvocation:org.mockito.internal.progress.MockingProgress:org.mockito.internal.exceptions.stacktrace.DefaultStackTraceCleanerProvider:org.mockito.exceptions.misusing.NotAMockException:org.mockito.configuration.AnnotationEngine:org.mockito.exceptions.verification.ArgumentsAreDifferent:org.mockito.internal.configuration.injection.SpyOnInjectedFieldsHandler:org.mockito.internal.configuration.CaptorAnnotationProcessor:org.mockito.plugins.StackTraceCleanerProvider:org.mockito.invocation.Location:org.mockito.internal.progress.MockingProgressImpl:org.mockito.internal.util.reflection.FieldInitializationReport:org.mockito.internal.configuration.DefaultInjectionEngine:org.mockito.internal.configuration.injection.filter.OngoingInjecter:org.mockito.internal.util.collections.HashCodeAndEqualsSafeSet:org.mockito.exceptions.verification.SmartNullPointerException:  -regressiontestcases4fl  org.concurrentmockito.ThreadsShareAMockTest:org.concurrentmockito.ThreadsShareGenerouslyStubbedMockTest:org.mockito.internal.InvalidStateDetectionTest:org.mockito.internal.debugging.WarningsFinderTest:org.mockito.internal.handler.InvocationNotifierHandlerTest:org.mockito.internal.invocation.ArgumentsComparatorTest:org.mockito.internal.invocation.InvocationMatcherTest:org.mockito.internal.matchers.EqualityTest:org.mockito.internal.matchers.EqualsTest:org.mockito.internal.progress.MockingProgressImplTest:org.mockito.internal.stubbing.defaultanswers.ReturnsGenericDeepStubsTest:org.mockito.internal.verification.argumentmatching.ArgumentMatchingToolTest:org.mockito.internal.verification.checkers.AtLeastXNumberOfInvocationsCheckerTest:org.mockito.verification.TimeoutTest:org.mockitousage.PlaygroundWithDemoOfUnclonedParametersProblemTest:org.mockitousage.annotation.MockInjectionUsingConstructorTest$ATest:org.mockitousage.annotation.MockInjectionUsingConstructorTest:org.mockitousage.annotation.SpyAnnotationTest:org.mockitousage.basicapi.MocksSerializationForAnnotationTest:org.mockitousage.basicapi.MocksSerializationTest:org.mockitousage.basicapi.UsingVarargsTest:org.mockitousage.bugs.ActualInvocationHasNullArgumentNPEBugTest:org.mockitousage.bugs.ConcurrentModificationExceptionOnMultiThreadedVerificationTest:org.mockitousage.bugs.MultipleInOrdersTest:org.mockitousage.bugs.NPEWithCertainMatchersTest:org.mockitousage.bugs.ShouldAllowInlineMockCreationTest:org.mockitousage.bugs.SpyShouldHaveNiceNameTest:org.mockitousage.bugs.VerifyingWithAnExtraCallToADifferentMockTest:org.mockitousage.bugs.varargs.VarargsAndAnyObjectPicksUpExtraInvocationsTest:org.mockitousage.bugs.varargs.VarargsNotPlayingWithAnyObjectTest:org.mockitousage.configuration.CustomizedAnnotationForSmartMockTest:org.mockitousage.customization.BDDMockitoTest:org.mockitousage.debugging.InvocationListenerCallbackTest:org.mockitousage.debugging.PrintingInvocationsDetectsUnusedStubTest:org.mockitousage.debugging.PrintingInvocationsWhenEverythingOkTest:org.mockitousage.debugging.PrintingInvocationsWhenStubNotUsedTest:org.mockitousage.debugging.VerboseLoggingOfInvocationsOnMockTest:org.mockitousage.examples.use.ExampleTest:org.mockitousage.junitrunner.JUnit44RunnerTest:org.mockitousage.junitrunner.JUnit45RunnerTest:org.mockitousage.matchers.CapturingArgumentsTest:org.mockitousage.matchers.GenericMatchersTest:org.mockitousage.matchers.MatchersTest:org.mockitousage.matchers.VerificationAndStubbingUsingMatchersTest:org.mockitousage.puzzlers.BridgeMethodPuzzleTest:org.mockitousage.puzzlers.OverloadingPuzzleTest:org.mockitousage.serialization.DeepStubsSerializableTest:org.mockitousage.spies.SpyingOnInterfacesTest:org.mockitousage.spies.SpyingOnRealObjectsTest:org.mockitousage.stacktrace.ClickableStackTracesTest:org.mockitousage.stacktrace.PointingStackTraceToActualInvocationChunkInOrderTest:org.mockitousage.stacktrace.PointingStackTraceToActualInvocationInOrderTest:org.mockitousage.stacktrace.PointingStackTraceToActualInvocationTest:org.mockitousage.stacktrace.StackTraceFilteringTest:org.mockitousage.stubbing.BasicStubbingTest:org.mockitousage.stubbing.CloningParameterTest:org.mockitousage.stubbing.DeepStubbingTest:org.mockitousage.stubbing.DeprecatedStubbingTest:org.mockitousage.stubbing.StubbingUsingDoReturnTest:org.mockitousage.stubbing.StubbingWithThrowablesTest:org.mockitousage.verification.AtLeastXVerificationTest:org.mockitousage.verification.BasicVerificationInOrderTest:org.mockitousage.verification.BasicVerificationTest:org.mockitousage.verification.DescriptiveMessagesOnVerificationInOrderErrorsTest:org.mockitousage.verification.DescriptiveMessagesWhenVerificationFailsTest:org.mockitousage.verification.ExactNumberOfTimesVerificationTest:org.mockitousage.verification.FindingRedundantInvocationsInOrderTest:org.mockitousage.verification.NoMoreInteractionsVerificationTest:org.mockitousage.verification.OnlyVerificationTest:org.mockitousage.verification.PrintingVerboseTypesWithArgumentsTest:org.mockitousage.verification.RelaxedVerificationInOrderTest:org.mockitousage.verification.SelectedMocksInOrderVerificationTest:org.mockitousage.verification.VerificationExcludingStubsTest:org.mockitousage.verification.VerificationInOrderMixedWithOrdiraryVerificationTest:org.mockitousage.verification.VerificationInOrderTest:org.mockitousage.verification.VerificationInOrderWithCallsTest:org.mockitousage.verification.VerificationOnMultipleMocksUsingMatchersTest:org.mockitousage.verification.VerificationUsingMatchersTest:]
97*/
98		int id = 22;
99		testMockito(id);
100	}
101	
102	public void testMockito(int id) throws Exception{
103		FileLauncher l = new FileLauncher();
104		
105	
106		System.out.println("##Testing "+29);
107		String location = new File(exampleRoot + "/mockito_"+id).getAbsolutePath();
108		
109		
110		String[] args = new String[] { "-mode", "jgenprog", 
111				//
112				"-location", location, "-flthreshold", "0.1", 
113				//
114				"-seed", "1", "-maxgen", "50", "-stopfirst", "true", "-maxtime", "100", 
115				//
116				"-scope", "package",
117				
118				"-loglevel",Level.ERROR.toString(),
119				//"
120		};
121	
122		
123		String sharedlibs = "/Users/matias/develop/defects4j/framework/projects/Mockito/lib/";
124
125		File f = new File(location+File.separator+"lib");
126		List<String> otherlibs = getParticularIssueLibs(f);
127		System.out.println("libs from projects: "+otherlibs);
128		
129		String[] command = l.getCommand(args, new File(dataDir.getAbsolutePath()+"/mockito.json"), id, sharedlibs,location,otherlibs);
130		System.out.println(Arrays.toString(args));
131
132		AstorMain main1 = new AstorMain();
133
134		CommandSummary cs = new CommandSummary(command);
135		cs.command.put("-javacompliancelevel", "6");
136		cs.command.put("-loglevel", "DEBUG");
137		main1.execute(cs.flat());
138
139		List<ProgramVariant> solutions = main1.getEngine().getSolutions();
140		assertTrue(solutions.size() > 0);
141		assertEquals(1, solutions.size());
142	}
143}
144
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

...Most popular Stackoverflow questions on ConcurrentModificationExceptionOnMultiThreadedVerificationTest

    No relevant questions found for this class 😞

Most used methods in ConcurrentModificationExceptionOnMultiThreadedVerificationTest

Run Selenium Automation Tests on LambdaTest Cloud Grid

Trigger Selenium automation tests on a cloud-based Grid of 3000+ real browsers and operating systems.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)