EMMA Coverage Report (generated Sun Feb 05 10:43:15 CET 2012)
[all classes][de.uka.ipd.sdq.prototype.framework.tests]

COVERAGE SUMMARY FOR SOURCE FILE [PassiveResourcesTest.java]

nameclass, %method, %block, %line, %
PassiveResourcesTest.java0%   (0/3)0%   (0/7)0%   (0/142)0%   (0/35)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class PassiveResourcesTest0%   (0/1)0%   (0/3)0%   (0/105)0%   (0/25)
PassiveResourcesTest (): void 0%   (0/1)0%   (0/3)0%   (0/1)
initialise (): void 0%   (0/1)0%   (0/29)0%   (0/7)
testPassiveResources (): void 0%   (0/1)0%   (0/73)0%   (0/17)
     
class PassiveResourcesTest$AcquiringThread0%   (0/1)0%   (0/2)0%   (0/16)0%   (0/4)
PassiveResourcesTest$AcquiringThread (PassiveResourcesTest): void 0%   (0/1)0%   (0/6)0%   (0/1)
run (): void 0%   (0/1)0%   (0/10)0%   (0/3)
     
class PassiveResourcesTest$TryingThread0%   (0/1)0%   (0/2)0%   (0/21)0%   (0/6)
PassiveResourcesTest$TryingThread (PassiveResourcesTest): void 0%   (0/1)0%   (0/6)0%   (0/1)
run (): void 0%   (0/1)0%   (0/15)0%   (0/5)

1package de.uka.ipd.sdq.prototype.framework.tests;
2 
3import java.io.IOException;
4 
5import junit.framework.Assert;
6 
7import org.apache.log4j.ConsoleAppender;
8import org.apache.log4j.Logger;
9import org.apache.log4j.SimpleLayout;
10import org.junit.Before;
11import org.junit.Test;
12 
13import de.uka.ipd.sdq.prototype.framework.strategies.PassiveResource;
14import de.uka.ipd.sdq.prototype.framework.strategies.PassiveResourceRegistry;
15 
16public class PassiveResourcesTest {
17        private static final int CAPACITY = 1;
18        private static final String PR1 = "pr1";
19        private static final String PR2 = "pr2";
20        
21        @Before
22        public void initialise(){
23                 PassiveResource pr1 = new PassiveResource(CAPACITY,PR1);
24                 PassiveResource pr2 = new PassiveResource(CAPACITY+1,PR2);
25                 PassiveResourceRegistry.singleton().addPassiveResource(pr1);
26                 PassiveResourceRegistry.singleton().addPassiveResource(pr2);
27                 
28                 Logger.getLogger(PassiveResource.class.getName())
29                         .addAppender(new ConsoleAppender(new SimpleLayout()));
30        }
31        
32        @Test
33        public void testPassiveResources() throws IOException, InterruptedException {
34                ThreadGroup tg = new ThreadGroup("Acquiring Threads");
35                
36                PassiveResourceRegistry.singleton().getResource(PR1).acquire();
37                
38                AcquiringThread at = new AcquiringThread();
39                new Thread(tg, at).start();
40                
41                Thread.sleep(1000);
42                Assert.assertTrue(tg.activeCount() == 1);
43                
44                PassiveResourceRegistry.singleton().getResource(PR1).release();
45                
46                Thread.sleep(100);
47                Assert.assertTrue(tg.activeCount() == 0);
48                
49                PassiveResourceRegistry.singleton().getResource(PR2).acquire();
50                PassiveResourceRegistry.singleton().getResource(PR2).acquire();
51                PassiveResourceRegistry.singleton().getResource(PR2).release();
52                PassiveResourceRegistry.singleton().getResource(PR2).release();
53                
54                TryingThread tt = new TryingThread();
55                new Thread(tg, tt).start();
56                
57                Thread.sleep(100);
58                
59        }
60        
61        class TryingThread implements Runnable {
62                public void run() {
63                        PassiveResourceRegistry.singleton().getResource(PR2).acquire();
64                        PassiveResourceRegistry.singleton().getResource(PR2).acquire();
65                        PassiveResourceRegistry.singleton().getResource(PR2).acquire();
66                        
67                        Assert.assertTrue(false);
68                }
69        }
70        
71        class AcquiringThread implements Runnable {
72                public void run() {
73                        PassiveResourceRegistry.singleton().getResource(PR1).acquire();
74                        Logger.getLogger(PassiveResource.class.getName()).debug("ACQUIRED! ");
75                }
76        }
77}

[all classes][de.uka.ipd.sdq.prototype.framework.tests]
EMMA 2.0.9414 (unsupported private build) (C) Vladimir Roubtsov