EMMA Coverage Report (generated Thu Jan 20 11:39:44 EST 2011)
[all classes][com.hammurapi.common.tests]

COVERAGE SUMMARY FOR SOURCE FILE [CommonTests.java]

nameclass, %method, %block, %line, %
CommonTests.java100% (3/3)89%  (8/9)90%  (219/242)87%  (40.8/47)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class CommonTests$1100% (1/1)50%  (1/2)29%  (6/21)40%  (2/5)
onProblem (Throwable, List): void 0%   (0/1)0%   (0/15)0%   (0/3)
CommonTests$1 (CommonTests): void 100% (1/1)100% (6/6)100% (2/2)
     
class CommonTests100% (1/1)100% (5/5)96%  (135/141)91%  (30/33)
testLocalTrackingServiceJoin (): void 100% (1/1)94%  (93/99)86%  (18/21)
CommonTests (): void 100% (1/1)100% (3/3)100% (1/1)
setUp (): void 100% (1/1)100% (5/5)100% (2/2)
tearDown (): void 100% (1/1)100% (4/4)100% (2/2)
testInvocationRecordingProxyFactoryTest (): void 100% (1/1)100% (30/30)100% (7/7)
     
class CommonTests$1TestTask100% (1/1)100% (2/2)98%  (78/80)98%  (9.8/10)
call (): Boolean 100% (1/1)96%  (48/50)94%  (3.8/4)
CommonTests$1TestTask (CommonTests, long, int, Collection, AtomicInteger, Loc... 100% (1/1)100% (30/30)100% (6/6)

1package com.hammurapi.common.tests;
2 
3import static org.junit.Assert.assertEquals;
4import static org.junit.Assert.*;
5 
6import java.util.ArrayList;
7import java.util.Collection;
8import java.util.Collections;
9import java.util.List;
10import java.util.Random;
11import java.util.concurrent.Callable;
12import java.util.concurrent.ExecutionException;
13import java.util.concurrent.ExecutorService;
14import java.util.concurrent.Executors;
15import java.util.concurrent.Future;
16import java.util.concurrent.atomic.AtomicBoolean;
17import java.util.concurrent.atomic.AtomicInteger;
18 
19import org.junit.After;
20import org.junit.Before;
21import org.junit.Test;
22 
23import com.hammurapi.common.FreezeableCollection;
24import com.hammurapi.common.InvocationRecordingProxyFactory;
25import com.hammurapi.common.InvocationRecordingProxyFactory.InvocationRecord;
26import com.hammurapi.common.InvocationRecordingProxyFactory.ProblemListener;
27import com.hammurapi.common.concurrent.LocalTrackingExecutorService;
28 
29public class CommonTests {                
30        
31        private ExecutorService executorService;
32 
33        @Before
34        public void setUp() throws Exception {
35                executorService = Executors.newFixedThreadPool(10);
36        }
37 
38        @After
39        public void tearDown() throws Exception {
40                executorService.shutdown();
41        }
42        
43        
44        /**
45         * Tests that no tasks are executed after join() returns.
46         * @throws InterruptedException
47         */
48        @Test
49        public void testLocalTrackingServiceJoin() throws InterruptedException {
50                
51                final AtomicBoolean afterJoin = new AtomicBoolean(false);
52                final Random random = new Random(System.currentTimeMillis());
53                final AtomicInteger createdTasks = new AtomicInteger();
54                
55                final LocalTrackingExecutorService ltes = new LocalTrackingExecutorService(executorService, true, null);
56                final int numberOfTasks = 5;
57                                
58                class TestTask implements Callable<Boolean> {
59                        
60                        private int depth;
61                        private Collection<Future<Boolean>> collector;
62 
63                        public TestTask(long delay, int depth, Collection<Future<Boolean>> collector) {
64                                createdTasks.incrementAndGet();
65                                this.delay = delay;
66                                this.depth = depth;
67                                this.collector = collector;
68                        }
69                        
70                        long delay;
71                        
72                        @Override
73                        public Boolean call() throws Exception {
74//                                Thread.sleep(delay);
75                                if (depth>0) {
76                                        for (int i=0; i<numberOfTasks; ++i) {
77                                                collector.add(ltes.submit(new TestTask(random.nextInt(100), depth-1, collector)));
78                                        }
79                                }
80                                return !afterJoin.get();
81                        }
82                };
83                
84                FreezeableCollection<Future<Boolean>> collector = new FreezeableCollection<Future<Boolean>>(Collections.synchronizedCollection(new ArrayList<Future<Boolean>>()));                
85                
86                int depth = 3;
87                for (int i=0; i<numberOfTasks; ++i) {
88                        collector.add(ltes.submit(new TestTask(random.nextInt(100), depth, collector)));
89                }
90                
91                ltes.join();                
92                collector.freeze();
93                
94                int counter = 0;
95                for (Future<Boolean> fb: collector) {
96                        try {
97                                assertNotNull(fb);
98                                assertTrue(fb.get());
99                                ++counter;
100                        } catch (ExecutionException e) {
101                                e.printStackTrace();
102                                fail(e.toString());
103                        }
104                }
105                assertEquals(createdTasks.get(), counter);
106 
107        }
108        
109        @Test
110        public void testInvocationRecordingProxyFactoryTest() {                                
111                ArrayList<String> target = new ArrayList<String>();
112                
113                InvocationRecordingProxyFactory.ProblemListener problemListener = new ProblemListener() {
114 
115                        @Override
116                        public void onProblem(Throwable th, List<InvocationRecord> records) {
117                                for (InvocationRecord record: records) {
118                                        System.out.println(record);
119                                }
120                        }
121                        
122                };
123                
124                List<String> proxy = InvocationRecordingProxyFactory.wrap(List.class, target, problemListener);
125                
126                proxy.add("Hello");                
127                proxy.iterator().next();
128                
129                assertEquals(3, InvocationRecordingProxyFactory.getInvocationRecords(proxy).size());
130                
131        }
132                
133}

[all classes][com.hammurapi.common.tests]
EMMA 2.0.5312 EclEmma Fix 2 (C) Vladimir Roubtsov