Search in sources :

Example 1 with VerboseCallable

use of com.jcabi.log.VerboseCallable in project jcabi-github by jcabi.

the class MkGithubTest method canHandleMultipleThreads.

/**
 * MkGithub can handle multiple threads in parallel.
 * @throws Exception if some problem inside
 */
@Test
public void canHandleMultipleThreads() throws Exception {
    final Repo repo = new MkGithub().randomRepo();
    final int threads = Tv.HUNDRED;
    final ExecutorService svc = Executors.newFixedThreadPool(threads);
    final Callable<Void> task = new VerboseCallable<Void>(new Callable<Void>() {

        @Override
        public Void call() throws Exception {
            repo.issues().create("", "");
            return null;
        }
    });
    final Collection<Callable<Void>> tasks = new ArrayList<Callable<Void>>(threads);
    for (int idx = 0; idx < threads; ++idx) {
        tasks.add(task);
    }
    svc.invokeAll(tasks);
    MatcherAssert.assertThat(repo.issues().iterate(new ArrayMap<String, String>()), Matchers.<Issue>iterableWithSize(threads));
}
Also used : ArrayList(java.util.ArrayList) ArrayMap(com.jcabi.immutable.ArrayMap) Callable(java.util.concurrent.Callable) VerboseCallable(com.jcabi.log.VerboseCallable) Repo(com.jcabi.github.Repo) VerboseCallable(com.jcabi.log.VerboseCallable) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Aggregations

Repo (com.jcabi.github.Repo)1 ArrayMap (com.jcabi.immutable.ArrayMap)1 VerboseCallable (com.jcabi.log.VerboseCallable)1 ArrayList (java.util.ArrayList)1 Callable (java.util.concurrent.Callable)1 ExecutorService (java.util.concurrent.ExecutorService)1 Test (org.junit.Test)1