Search in sources :

Example 1 with BatchMapperIterator

use of com.baidu.hugegraph.iterator.BatchMapperIterator in project hugegraph-common by hugegraph.

the class BatchMapperIteratorTest method testMapperReturnEmptyThenHasNext.

@Test
public void testMapperReturnEmptyThenHasNext() {
    Iterator<Integer> results;
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        return Collections.emptyIterator();
    });
    Assert.assertFalse(results.hasNext());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count1 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count1.incrementAndGet() == 1) {
            return Collections.emptyIterator();
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(5, results.next());
    Assert.assertEquals(6, results.next());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count2 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count2.incrementAndGet() == 2) {
            return Collections.emptyIterator();
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(4, results.next());
    Assert.assertEquals(6, results.next());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count3 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count3.incrementAndGet() == 3) {
            return Collections.emptyIterator();
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(4, results.next());
    Assert.assertEquals(5, results.next());
    Assert.assertFalse(results.hasNext());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) CloseableItor(com.baidu.hugegraph.unit.iterator.ExtendableIteratorTest.CloseableItor) Test(org.junit.Test) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) NoSuchElementException(java.util.NoSuchElementException) Assert(com.baidu.hugegraph.testutil.Assert) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Example 2 with BatchMapperIterator

use of com.baidu.hugegraph.iterator.BatchMapperIterator in project hugegraph-common by hugegraph.

the class BatchMapperIteratorTest method testMapperReturnNullThenHasNext.

@Test
public void testMapperReturnNullThenHasNext() {
    Iterator<Integer> results;
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        return null;
    });
    Assert.assertFalse(results.hasNext());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count1 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count1.incrementAndGet() == 1) {
            return null;
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(5, results.next());
    Assert.assertEquals(6, results.next());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count2 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count2.incrementAndGet() == 2) {
            return null;
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(4, results.next());
    Assert.assertEquals(6, results.next());
    Assert.assertFalse(results.hasNext());
    AtomicInteger count3 = new AtomicInteger(0);
    results = new BatchMapperIterator<>(1, DATA3.iterator(), batch -> {
        if (count3.incrementAndGet() == 3) {
            return null;
        }
        return batch.iterator();
    });
    Assert.assertTrue(results.hasNext());
    Assert.assertEquals(4, results.next());
    Assert.assertEquals(5, results.next());
    Assert.assertFalse(results.hasNext());
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Iterator(java.util.Iterator) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) CloseableItor(com.baidu.hugegraph.unit.iterator.ExtendableIteratorTest.CloseableItor) Test(org.junit.Test) Function(java.util.function.Function) ArrayList(java.util.ArrayList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BatchMapperIterator(com.baidu.hugegraph.iterator.BatchMapperIterator) NoSuchElementException(java.util.NoSuchElementException) Assert(com.baidu.hugegraph.testutil.Assert) Collections(java.util.Collections) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) BaseUnitTest(com.baidu.hugegraph.unit.BaseUnitTest) Test(org.junit.Test)

Aggregations

BatchMapperIterator (com.baidu.hugegraph.iterator.BatchMapperIterator)2 Assert (com.baidu.hugegraph.testutil.Assert)2 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)2 CloseableItor (com.baidu.hugegraph.unit.iterator.ExtendableIteratorTest.CloseableItor)2 ImmutableList (com.google.common.collect.ImmutableList)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 Iterator (java.util.Iterator)2 List (java.util.List)2 NoSuchElementException (java.util.NoSuchElementException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Function (java.util.function.Function)2 Test (org.junit.Test)2