1 5 6 package com.hp.hpl.jena.rdf.arp; 7 8 import junit.framework.TestCase; 9 import java.util.*; 10 11 16 public class PushMePullYouTest extends TestCase { 17 PushMePullYouPipe pipe; 18 19 public void testBuf4() throws Exception { 20 testBuffer(4); 21 } 22 public void testBuf5() throws Exception { 23 testBuffer(5); 24 } 25 public void testBuf8() throws Exception { 26 testBuffer(8); 27 } 28 public void testBuf10() throws Exception { 29 testBuffer(10); 30 } 31 public void testBuf11() throws Exception { 32 testBuffer(11); 33 } 34 public void testBuf12() throws Exception { 35 testBuffer(12); 36 } 37 private void testBuffer(final int ii) throws Exception { 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 } 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 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 e){ 68 69 } 70 } 71 72 } 73 74 75 101 102 | Popular Tags |