KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > rdf > arp > PushMePullYouTest


1 /*
2  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
3  * [See end of file]
4  */

5
6 package com.hp.hpl.jena.rdf.arp;
7
8 import junit.framework.TestCase;
9 import java.util.*;
10
11 /**
12  * Not part of API.
13  * @author Jeremy J. Carroll
14  *
15  */

16 public class PushMePullYouTest extends TestCase {
17     PushMePullYouPipe pipe;
18     
19     public void testBuf4() throws Exception JavaDoc {
20         testBuffer(4);
21     }
22     public void testBuf5() throws Exception JavaDoc {
23         testBuffer(5);
24     }
25     public void testBuf8() throws Exception JavaDoc {
26         testBuffer(8);
27     }
28     public void testBuf10() throws Exception JavaDoc {
29         testBuffer(10);
30     }
31     public void testBuf11() throws Exception JavaDoc {
32         testBuffer(11);
33     }
34     public void testBuf12() throws Exception JavaDoc {
35         testBuffer(12);
36     }
37     private void testBuffer(final int ii) throws Exception JavaDoc {
38         final Vector v = new Vector();
39         ARPRunnable puller = new ARPRunnable() {
40             public void run() {
41                     for (int j=0; j<ii; j++) {
42                         Token t = pipe.getNextToken();
43                         v.add(t);
44                 // System.err.println(j + " " + (t==null?-1:t.kind));
45
}
46             }
47         };
48         pipe = new PushMePullYouPipe(puller);
49         pipe.start();
50         
51         for (int i=0;i<ii;i++){
52             pipe.putNextToken(new Token(i,null));
53         }
54         pipe.close();
55         for (int i=0;i<ii;i++)
56             assertEquals("pos "+i, i, ((Token)v.get(i)).kind);
57     }
58         
59     public void testInterrupt() {
60         Thread JavaDoc t = Thread.currentThread();
61         t.interrupt();
62         assertTrue(t.isInterrupted());
63         try {
64             Thread.sleep(50);
65             fail("Wasn't interrupted");
66         }
67         catch (InterruptedException JavaDoc e){
68             
69         }
70     }
71
72 }
73
74
75 /*
76  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
77  * All rights reserved.
78  *
79  * Redistribution and use in source and binary forms, with or without
80  * modification, are permitted provided that the following conditions
81  * are met:
82  * 1. Redistributions of source code must retain the above copyright
83  * notice, this list of conditions and the following disclaimer.
84  * 2. Redistributions in binary form must reproduce the above copyright
85  * notice, this list of conditions and the following disclaimer in the
86  * documentation and/or other materials provided with the distribution.
87  * 3. The name of the author may not be used to endorse or promote products
88  * derived from this software without specific prior written permission.
89  *
90  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
91  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
92  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
93  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
94  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
95  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
96  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
97  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
98  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
99  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
100  */

101  
102
Popular Tags