public void testGetNextHatchedIfAvailable() {
   assertEquals(null, qi.getNextHatchedIfAvailable());
   qi.incubate(a);
   assertEquals(null, qi.getNextHatchedIfAvailable());
   qi.hatch(a);
   assertEquals(a, qi.getNextHatchedIfAvailable());
 }
 public void testIncubate() {
   qi.incubate(a);
   try {
     qi.incubate(a);
     fail();
   } catch (IllegalArgumentException e) {
   }
 }
 public void testGetNextHatched() throws InterruptedException {
   qi.incubate(a);
   new Thread() {
     public void run() {
       try {
         Thread.sleep(10);
       } catch (InterruptedException e) {
       }
       qi.hatch(a);
     }
   }.run();
   assertEquals(a, qi.getNextHatched());
 }
  public void testRemoveNextHatchedUninterruptibly() {
    qi.incubate(a);
    qi.incubate(b);
    qi.incubate(c);

    qi.hatch(c);
    qi.hatch(b);
    qi.hatch(a);

    assertEquals(a, qi.removeNextHatchedUninterruptibly());
    assertEquals(b, qi.removeNextHatchedUninterruptibly());
    assertEquals(c, qi.removeNextHatchedUninterruptibly());

    qi.incubate(d);
    new Thread() {
      public void run() {
        try {
          Thread.sleep(10);
        } catch (InterruptedException e) {
        }
        qi.hatch(d);
      }
    }.run();
    assertEquals(d, qi.removeNextHatchedUninterruptibly());
  }
 public void testRemoveNextHatchedIfAvailable() {
   qi.incubate(a);
   qi.incubate(b);
   qi.incubate(c);
   assertNull(qi.removeNextHatchedIfAvailable());
   qi.hatch(c);
   assertNull(qi.removeNextHatchedIfAvailable());
   qi.hatch(b);
   assertNull(qi.removeNextHatchedIfAvailable());
   qi.hatch(a);
   assertEquals(a, qi.removeNextHatchedIfAvailable());
   assertEquals(b, qi.removeNextHatchedIfAvailable());
   assertEquals(c, qi.removeNextHatchedIfAvailable());
 }
  public void testHatch() {
    qi.incubate(a);
    qi.incubate(b);
    qi.incubate(c);

    qi.hatch(c);
    qi.hatch(b);
    qi.hatch(a);

    try {
      qi.hatch(d);
      fail();
    } catch (IllegalArgumentException e) {
    }
  }
  public void testIdentityQueue() throws InterruptedException {
    ByteBuffer a = ByteBuffer.allocate(1);
    qi.incubate(a);
    a.put((byte) 5);
    qi.hatch(a);
    ByteBuffer b = (ByteBuffer) qi.getNext();
    assertEquals(a, b);

    a = ByteBuffer.allocate(1);
    qe.incubate(a);
    a.put((byte) 5);
    try {
      qe.hatch(a);
      throw new RuntimeException("Hatch fail expected");
    } catch (IllegalArgumentException e) {
    }
  }
 public void testIsEmpty() {
   assertEquals(true, qi.isEmpty());
   qi.incubate(a);
   assertEquals(false, qi.isEmpty());
   qi.hatch(a);
   assertEquals(false, qi.isEmpty());
   qi.removeNextHatchedUninterruptibly();
   assertEquals(true, qi.isEmpty());
 }
 public void testNextIsHatched() {
   assertEquals(false, qi.nextIsHatched());
   qi.incubate(a);
   assertEquals(false, qi.nextIsHatched());
   qi.hatch(a);
   assertEquals(true, qi.nextIsHatched());
   qi.removeNextHatchedIfAvailable();
   assertEquals(false, qi.nextIsHatched());
 }
Пример #10
0
 public void testSize() {
   qi.incubate(a);
   assertEquals(1, qi.size());
   qi.incubate(b);
   assertEquals(2, qi.size());
   qi.hatch(b);
   assertEquals(2, qi.size());
 }
Пример #11
0
 public void testClear() {
   assertEquals(0, qi.size());
   qi.incubate(a);
   qi.clear();
   assertEquals(0, qi.size());
 }
Пример #12
0
 public void testGetNext() throws InterruptedException {
   qi.incubate(a);
   assertEquals(a, qi.getNext());
 }