Skip to content

Commit ad2fc34

Browse files
committed
Adding a new test
1 parent 6a66350 commit ad2fc34

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package org.javaee7.concurrency.managedexecutor;
7+
8+
import java.util.ArrayList;
9+
import java.util.Collection;
10+
import java.util.List;
11+
import java.util.concurrent.Callable;
12+
import java.util.concurrent.Future;
13+
import javax.annotation.Resource;
14+
import javax.enterprise.concurrent.ManagedExecutorService;
15+
import org.jboss.arquillian.container.test.api.Deployment;
16+
import org.jboss.arquillian.container.test.api.TargetsContainer;
17+
import org.jboss.arquillian.junit.Arquillian;
18+
import org.jboss.shrinkwrap.api.ShrinkWrap;
19+
import org.jboss.shrinkwrap.api.spec.WebArchive;
20+
import org.junit.Test;
21+
import static org.junit.Assert.*;
22+
import org.junit.runner.RunWith;
23+
24+
/**
25+
* @author Arun Gupta
26+
*/
27+
@RunWith(Arquillian.class)
28+
public class ExecutorInvokeAllServletTest {
29+
30+
@Resource(name = "DefaultManagedExecutorService")
31+
ManagedExecutorService executor;
32+
33+
/**
34+
* Arquillian specific method for creating a file which can be deployed
35+
* while executing the test.
36+
*
37+
* @return a war file
38+
*/
39+
@Deployment
40+
@TargetsContainer("wildfly-arquillian")
41+
public static WebArchive createDeployment() {
42+
WebArchive war = ShrinkWrap.create(WebArchive.class).
43+
addClass(MyCallableTask.class).
44+
addClass(Product.class);
45+
System.out.println(war.toString(true));
46+
47+
return war;
48+
}
49+
50+
Collection<Callable<Product>> tasks = new ArrayList<>();
51+
52+
public ExecutorInvokeAllServletTest() {
53+
for (int i = 0; i < 5; i++) {
54+
tasks.add(new MyCallableTask(i));
55+
}
56+
}
57+
58+
/**
59+
* Test of invokeAll method.
60+
*/
61+
@Test
62+
public void testProcessRequest() throws Exception {
63+
List<Future<Product>> results = executor.invokeAll(tasks);
64+
int count = 0;
65+
for (Future<Product> f : results) {
66+
assertEquals(count++, f.get().getId());
67+
}
68+
}
69+
70+
}

0 commit comments

Comments
 (0)