@Test public void concurrentScopeRemovals_shouldNotCrash() throws InterruptedException { //GIVEN final int removalNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < removalNodeThreadCount; indexThread++) { RemoveNodeThread runnable = new RemoveNodeThread(ROOT_SCOPE); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentScopeRemovals_shouldNotCrash() throws InterruptedException { //GIVEN final int removalNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < removalNodeThreadCount; indexThread++) { RemoveNodeThread runnable = new RemoveNodeThread(ROOT_SCOPE); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentScopeAdditions_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { AddNodeThread runnable = new AddNodeThread(ROOT_SCOPE); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentOpenScopes_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { AddScopeToListThread runnable = new AddScopeToListThread(scopeNames); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentOpenAndCloseScopes_shouldNotCrash() throws InterruptedException { //GIVEN final int removalNodeThreadCount = STANDARD_THREAD_COUNT; final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); final Random random = new Random(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount + removalNodeThreadCount; indexThread++) { final TestableThread runnable; if (random.nextInt(100) < 50) { runnable = new RemoveScopeFromListThread(scopeNames); } else { runnable = new AddScopeToListThread(scopeNames); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentBindingInstall_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { InstallBindingThread runnable = new InstallBindingThread(classCreator, ROOT_SCOPE); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentScopeAdditions_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { AddNodeThread runnable = new AddNodeThread(ROOT_SCOPE); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentCloseScopes_shouldNotCrash() throws InterruptedException { //GIVEN final int scopeCount = 100; for (int indexScope = 0; indexScope < scopeCount; indexScope++) { Object newScopeName = new Object(); scopeNames.add(newScopeName); Toothpick.openScopes(ROOT_SCOPE, newScopeName); } final int removalNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < removalNodeThreadCount; indexThread++) { RemoveScopeFromListThread runnable = new RemoveScopeFromListThread(scopeNames); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentBindingInstallAndToString_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); Random random = new Random(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { TestableThread runnable; if (random.nextInt(100) < 20) { runnable = new InstallBindingThread(classCreator, ROOT_SCOPE); } else { runnable = new ScopeToStringThread(ROOT_SCOPE); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentOpenScopes_shouldAddChildScopeOnlyOnce_withSameChildScope() throws InterruptedException { //GIVEN final int addSameScopeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); //WHEN for (int indexThread = 0; indexThread < addSameScopeThreadCount; indexThread++) { final TestableThread runnable = new AddSameScopeThread(ROOT_SCOPE, "childScope"); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } assertThat(ToothpickVisibilityExposer.getScopeNamesSize(), is(2)); }
@Test public void concurrentScopedGetInstance_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); Random random = new Random(); FactoryRegistryLocator.setRootRegistry(new DynamicTestClassesFactoryRegistry(true)); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { TestableThread runnable = new GetInstanceThread(ROOT_SCOPE, classCreator.allClasses[random.nextInt(classCreator.allClasses.length)]); threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done boolean timeout = ThreadTestUtil.shutdown(); assertTrue("Executor service should not timeout.", timeout); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }
@Test public void concurrentScopeAdditionsAndRemovals_shouldNotCrash() throws InterruptedException { //GIVEN final int removalNodeThreadCount = STANDARD_THREAD_COUNT / 2; final int addNodeThreadCount = STANDARD_THREAD_COUNT / 2; List<TestableThread> threadList = new ArrayList<>(); final Random random = new Random(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount + removalNodeThreadCount; indexThread++) { final TestableThread runnable; if (random.nextInt(100) < 50) { runnable = new RemoveNodeThread(ROOT_SCOPE); } else { runnable = new AddNodeThread(ROOT_SCOPE); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } } }
@Test public void concurrentScopeAdditionsAndRemovals_shouldNotCrash() throws InterruptedException { //GIVEN final int removalNodeThreadCount = STANDARD_THREAD_COUNT / 2; final int addNodeThreadCount = STANDARD_THREAD_COUNT / 2; List<TestableThread> threadList = new ArrayList<>(); final Random random = new Random(); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount + removalNodeThreadCount; indexThread++) { final TestableThread runnable; if (random.nextInt(100) < 50) { runnable = new RemoveNodeThread(ROOT_SCOPE); } else { runnable = new AddNodeThread(ROOT_SCOPE); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } } }
@Test public void concurrentOpenScopes_shouldAddChildScopeAtMostOnce_withSameChildScope() throws InterruptedException { //GIVEN final int addSameScopeThreadCount = STANDARD_THREAD_COUNT / 2; final int removeSameScopeThreadCount = STANDARD_THREAD_COUNT / 2; List<TestableThread> threadList = new ArrayList<>(); final Random random = new Random(); //WHEN for (int indexThread = 0; indexThread < addSameScopeThreadCount + removeSameScopeThreadCount; indexThread++) { final TestableThread runnable; if (random.nextInt(100) < 50) { runnable = new RemoveSameScopeThread("childScope"); } else { runnable = new AddSameScopeThread(ROOT_SCOPE, "childScope"); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN ThreadTestUtil.shutdown(); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } assertThat(ToothpickVisibilityExposer.getScopeNamesSize(), anyOf(is(1), is(2))); } }
@Test public void concurrentBindingInstallAndGetInstance_shouldNotCrash() throws InterruptedException { //GIVEN final int addNodeThreadCount = STANDARD_THREAD_COUNT; List<TestableThread> threadList = new ArrayList<>(); Random random = new Random(); FactoryRegistryLocator.setRootRegistry(new DynamicTestClassesFactoryRegistry(true)); //WHEN for (int indexThread = 0; indexThread < addNodeThreadCount; indexThread++) { TestableThread runnable; if (random.nextInt(100) < 20) { runnable = new InstallBindingThread(classCreator, ROOT_SCOPE); } else { runnable = new GetInstanceThread(ROOT_SCOPE, classCreator.allClasses[random.nextInt(classCreator.allClasses.length)]); } threadList.add(runnable); ThreadTestUtil.submit(runnable); } //THEN //we simply should not have crashed when all threads are done boolean timeout = ThreadTestUtil.shutdown(); assertTrue("Executor service should not timeout.", timeout); for (TestableThread thread : threadList) { assertTrue(String.format("test of thread %s failed", thread.getName()), thread.isSuccessful()); } }