Ejemplo n.º 1
0
  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());
  }
Ejemplo n.º 2
0
 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());
 }
Ejemplo n.º 3
0
  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) {
    }
  }
Ejemplo n.º 4
0
 public void testGetNextHatchedIfAvailable() {
   assertEquals(null, qi.getNextHatchedIfAvailable());
   qi.incubate(a);
   assertEquals(null, qi.getNextHatchedIfAvailable());
   qi.hatch(a);
   assertEquals(a, qi.getNextHatchedIfAvailable());
 }
Ejemplo n.º 5
0
  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) {
    }
  }
Ejemplo n.º 6
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());
 }
Ejemplo n.º 7
0
 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());
 }
Ejemplo n.º 8
0
 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());
 }