예제 #1
0
  /** iterator.remove removes current element */
  public void testDescendingIteratorRemove() {
    final NavigableSet q = dset0();
    q.add(new Integer(2));
    q.add(new Integer(1));
    q.add(new Integer(3));

    Iterator it = q.iterator();
    it.next();
    it.remove();

    it = q.iterator();
    assertEquals(2, it.next());
    assertEquals(3, it.next());
    assertFalse(it.hasNext());
  }
예제 #2
0
 /**
  * Marks an offset has committed. This method has side effects - it sets the internal state in
  * such a way that future calls to {@link #findNextCommitOffset()} will return offsets greater
  * than the offset specified, if any.
  *
  * @param committedOffset offset to be marked as committed
  */
 public void commit(OffsetAndMetadata committedOffset) {
   long numCommittedOffsets = 0;
   if (committedOffset != null) {
     final long oldCommittedOffset = this.committedOffset;
     numCommittedOffsets = committedOffset.offset() - this.committedOffset;
     this.committedOffset = committedOffset.offset();
     for (Iterator<KafkaSpoutMessageId> iterator = ackedMsgs.iterator(); iterator.hasNext(); ) {
       if (iterator.next().offset() <= committedOffset.offset()) {
         iterator.remove();
       } else {
         break;
       }
     }
     numUncommittedOffsets -= numCommittedOffsets;
     LOG.debug(
         "Committed offsets [{}-{} = {}] for topic-partition [{}]. [{}] uncommitted offsets across all topic partitions",
         oldCommittedOffset + 1,
         this.committedOffset,
         numCommittedOffsets,
         tp,
         numUncommittedOffsets);
   } else {
     LOG.debug(
         "Committed [{}] offsets for topic-partition [{}]. [{}] uncommitted offsets across all topic partitions",
         numCommittedOffsets,
         tp,
         numUncommittedOffsets);
   }
   LOG.trace("{}", this);
 }
예제 #3
0
 /** iterator iterates through all elements */
 public void testIterator() {
   NavigableSet q = populatedSet(SIZE);
   Iterator it = q.iterator();
   int i;
   for (i = 0; it.hasNext(); i++) assertTrue(q.contains(it.next()));
   assertEquals(i, SIZE);
   assertIteratorExhausted(it);
 }
예제 #4
0
 /** iterator of empty set has no elements */
 public void testDescendingEmptyIterator() {
   NavigableSet q = dset0();
   int i = 0;
   Iterator it = q.iterator();
   while (it.hasNext()) {
     assertTrue(q.contains(it.next()));
     ++i;
   }
   assertEquals(0, i);
 }
예제 #5
0
 /** iterator iterates through all elements */
 public void testDescendingIterator() {
   NavigableSet q = populatedSet(SIZE);
   int i = 0;
   Iterator it = q.iterator();
   while (it.hasNext()) {
     assertTrue(q.contains(it.next()));
     ++i;
   }
   assertEquals(i, SIZE);
 }
예제 #6
0
  public void testKeyDeleteRandomGaussian() throws Exception {
    NavigableSet<Integer> keys = new TreeSet<Integer>();

    long seed = System.currentTimeMillis();

    System.out.println("testKeyDeleteRandomGaussian seed : " + seed);
    MersenneTwisterFast random = new MersenneTwisterFast(seed);

    while (keys.size() < KEYS_COUNT) {
      int key = (int) (random.nextGaussian() * Integer.MAX_VALUE / 2 + Integer.MAX_VALUE);
      if (key < 0) continue;

      sbTree.put(key, createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      keys.add(key);

      Assert.assertEquals(
          sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));

      doReset();
    }

    Iterator<Integer> keysIterator = keys.iterator();

    while (keysIterator.hasNext()) {
      int key = keysIterator.next();

      if (key % 3 == 0) {
        sbTree.remove(key);
        keysIterator.remove();
      }

      doReset();
    }

    Assert.assertEquals(sbTree.firstKey(), keys.first());
    doReset();

    Assert.assertEquals(sbTree.lastKey(), keys.last());
    doReset();

    for (int key : keys) {
      if (key % 3 == 0) {
        Assert.assertNull(sbTree.get(key));
      } else {
        Assert.assertEquals(
            sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      }

      doReset();
    }
  }
 @SuppressWarnings("EmptyCatchBlock")
 static void ensureNotDirectlyModifiable(NavigableSet<Integer> unmod) {
   try {
     unmod.add(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.remove(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.addAll(Collections.singleton(4));
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollFirst();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollLast();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.iterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.descendingIterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
 }
예제 #8
0
파일: SetsTest.java 프로젝트: cjosw/guava
 @GwtIncompatible("NavigableSet")
 void ensureNotDirectlyModifiable(NavigableSet<Integer> unmod) {
   try {
     unmod.add(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.remove(4);
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.addAll(Collections.singleton(4));
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollFirst();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     unmod.pollLast();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.iterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
   try {
     Iterator<Integer> iterator = unmod.descendingIterator();
     iterator.next();
     iterator.remove();
     fail("UnsupportedOperationException expected");
   } catch (UnsupportedOperationException expected) {
   }
 }
예제 #9
0
  public void testKeyDeleteRandomUniform() throws Exception {
    NavigableSet<Integer> keys = new TreeSet<Integer>();
    for (int i = 0; i < KEYS_COUNT; i++) {
      sbTree.put(i, createValue(i, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      keys.add(i);

      doReset();
    }

    Iterator<Integer> keysIterator = keys.iterator();
    while (keysIterator.hasNext()) {
      int key = keysIterator.next();
      if (key % 3 == 0) {
        sbTree.remove(key);
        keysIterator.remove();
      }

      doReset();
    }

    Assert.assertEquals(sbTree.firstKey(), keys.first());
    doReset();

    Assert.assertEquals(sbTree.lastKey(), keys.last());
    doReset();

    for (int key : keys) {
      if (key % 3 == 0) {
        Assert.assertNull(sbTree.get(key));
      } else {
        Assert.assertEquals(
            sbTree.get(key), createValue(key, OSBTreeValuePage.MAX_BINARY_VALUE_SIZE + 4));
      }

      doReset();
    }
  }