@Override public void doRun() { Toothpick.closeScope(childScopeName); setIsSuccessful(true); } }
@Override public void doRun() { Toothpick.openScopes(parentScopeName, childScopeName); setIsSuccessful(true); } }
@Override public void doRun() { Toothpick.openScope(scopeName).toString(); setIsSuccessful(true); } }
@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 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 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 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 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 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)); }
@Override public void doRun() { Scope scope = Toothpick.openScope(rootScopeName); scope.installModules(new Module() { { Class clazz = classCreator.allClasses[random.nextInt(classCreator.allClasses.length)]; bind(clazz).toInstance(new Foo()); } }); setIsSuccessful(true); } }
@Override public final void run() { log(format("Thread %s starting", name)); try { doRun(); } catch (Exception e) { System.err.println(format("Thread %s crashed", name)); e.printStackTrace(); } log(format("Thread %s finished", name)); }
@Override public void doRun() { //pick a random node in the tree, starting from root //add a new child node to this node Scope scope = NodeUtil.findRandomNode(rootScopeName, ACCEPTANCE_THRESHOLD); if (scope == null) { setIsSuccessful(true); return; } //remove any node except root if (scope.getParentScope() == null) { setIsSuccessful(true); return; } Object scopeName = scope.getName(); Toothpick.closeScope(scopeName); setIsSuccessful(true); } }
@Override public void doRun() { Toothpick.openScope(scopeName).getInstance(clazz); setIsSuccessful(true); } }
@Override public void doRun() { //pick a random node in the tree, starting from root //add a new child node to this node Scope scope = NodeUtil.findRandomNode(scopeNames, ACCEPTANCE_THRESHOLD); if (scope == null) { setIsSuccessful(true); return; } //remove any node except root if (scope.getParentScope() == null) { setIsSuccessful(true); return; } Object scopeName = scope.getName(); Toothpick.closeScope(scopeName); setIsSuccessful(true); } }
@Override public void doRun() { //pick a random node in the tree, starting from root //add a new child node to this node Scope scopeName = NodeUtil.findRandomNode(rootScopeName, ACCEPTANCE_THRESHOLD); if (scopeName == null) { setIsSuccessful(true); return; } Object name = scopeName.getName(); Toothpick.openScopes(name, new Object()); setIsSuccessful(true); } }
@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 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()); } }