-
Notifications
You must be signed in to change notification settings - Fork 30
/
FuturesTest.java
52 lines (39 loc) · 1.49 KB
/
FuturesTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.edwise.pocs.futurepoc;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import static org.junit.Assert.assertEquals;
public class FuturesTest {
private final static Logger LOG = LoggerFactory.getLogger(FuturesTest.class);
private static ExecutorService executor;
@BeforeClass
public static void setUp() {
executor = Executors.newFixedThreadPool(5);
}
@AfterClass
public static void shutDown() {
executor.shutdown();
}
@Test
public void testFuture() throws InterruptedException, ExecutionException {
SomeBigProcess someBigProcess = new SomeBigProcess(executor);
LOG.info("Lanzamos el futuro...");
Future<String> future = someBigProcess.processVeryLong("test");
LOG.info("Futuro lanzado.");
assertEquals("test result", future.get());
}
@Test(expected = ExecutionException.class)
public void testFutureWithException() throws InterruptedException, ExecutionException {
SomeBigProcess someBigProcess = new SomeBigProcess(executor);
LOG.info("Lanzamos el futuro...");
Future<String> future = someBigProcess.processVeryLongThatThrowsException("test");
LOG.info("Futuro lanzado.");
future.get();
}
}