Package org.apache.lucene.util

Examples of org.apache.lucene.util.Counter$SerialCounter


* tests basic {@link IntBlockPool} functionality
*/
public class TestIntBlockPool extends LuceneTestCase {
 
  public void testSingleWriterReader() {
    Counter bytesUsed = Counter.newCounter();
    IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
   
    for (int j = 0; j < 2; j++) {
      IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
      int start = writer.startNewSlice();
      int num = atLeast(100);
      for (int i = 0; i < num; i++) {
        writer.writeInt(i);
      }
     
      int upto = writer.getCurrentOffset();
      IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
      reader.reset(start, upto);
      for (int i = 0; i < num; i++) {
        assertEquals(i, reader.readInt());
      }
      assertTrue(reader.endOfSlice());
      if (random().nextBoolean()) {
        pool.reset(true, false);
        assertEquals(0, bytesUsed.get());
      } else {
        pool.reset(true, true);
        assertEquals(IntBlockPool.INT_BLOCK_SIZE
            * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.get());
      }
    }
  }
View Full Code Here


      }
    }
  }
 
  public void testMultipleWriterReader() {
    Counter bytesUsed = Counter.newCounter();
    IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
    for (int j = 0; j < 2; j++) {
      List<StartEndAndValues> holders = new ArrayList<TestIntBlockPool.StartEndAndValues>();
      int num = atLeast(4);
      for (int i = 0; i < num; i++) {
        holders.add(new StartEndAndValues(random().nextInt(1000)));
      }
      IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
      IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
     
      int numValuesToWrite = atLeast(10000);
      for (int i = 0; i < numValuesToWrite; i++) {
        StartEndAndValues values = holders
            .get(random().nextInt(holders.size()));
        if (values.valueCount == 0) {
          values.start = writer.startNewSlice();
        } else {
          writer.reset(values.end);
        }
        writer.writeInt(values.nextValue());
        values.end = writer.getCurrentOffset();
        if (random().nextInt(5) == 0) {
          // pick one and reader the ints
          assertReader(reader, holders.get(random().nextInt(holders.size())));
        }
      }
     
      while (!holders.isEmpty()) {
        StartEndAndValues values = holders.remove(random().nextInt(
            holders.size()));
        assertReader(reader, values);
      }
      if (random().nextBoolean()) {
        pool.reset(true, false);
        assertEquals(0, bytesUsed.get());
      } else {
        pool.reset(true, true);
        assertEquals(IntBlockPool.INT_BLOCK_SIZE
            * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.get());
      }
    }
  }
View Full Code Here

  private Collector decorateWithTimeOutCollector(Collector collector) {
    Collector maybeTimeLimitingCollector = collector;
    if ( timeoutManager.getType() == TimeoutManager.Type.LIMIT ) {
      final Long timeoutLeft = timeoutManager.getTimeoutLeftInMilliseconds();
      if ( timeoutLeft != null ) {
        Counter counter = timeoutManager.getLuceneTimeoutCounter();
        maybeTimeLimitingCollector = new TimeLimitingCollector( collector, counter, timeoutLeft);
      }
    }
    return maybeTimeLimitingCollector;
  }
View Full Code Here

  private Collector decorateWithTimeOutCollector(Collector collector) {
    Collector maybeTimeLimitingCollector = collector;
    if ( timeoutManager.getType() == TimeoutManager.Type.LIMIT ) {
      final Long timeoutLeft = timeoutManager.getTimeoutLeftInMilliseconds();
      if ( timeoutLeft != null ) {
        Counter counter = timeoutManager.getLuceneTimeoutCounter();
        maybeTimeLimitingCollector = new TimeLimitingCollector( collector, counter, timeoutLeft);
      }
    }
    return maybeTimeLimitingCollector;
  }
View Full Code Here

  private Collector decorateWithTimeOutCollector(Collector collector) {
    Collector maybeTimeLimitingCollector = collector;
    if ( timeoutManager.getType() == TimeoutManager.Type.LIMIT ) {
      final Long timeoutLeft = timeoutManager.getTimeoutLeftInMilliseconds();
      if ( timeoutLeft != null ) {
        Counter counter = timeoutManager.getLuceneTimeoutCounter();
        maybeTimeLimitingCollector = new TimeLimitingCollector( collector, counter, timeoutLeft);
      }
    }
    return maybeTimeLimitingCollector;
  }
View Full Code Here

    }
  }

  private PossiblyLimitedTopDocs getTopDocs(Query query, Sort sort) throws IOException {
    final TopFieldCollector topCollector = TopFieldCollector.create(sort, maxHits, true, false, false, false);
    final Counter clock = Counter.newCounter(true);
    final int waitMillis = 1000;
    // TODO: if we interrupt the whole thread anyway, do we still need the TimeLimitingCollector?
    final TimeLimitingCollector collector = new TimeLimitingCollector(topCollector, clock, maxSearchTimeMillis / waitMillis);
    collector.setBaseline(0);
    final Thread counterThread = new Thread() {
      @Override
      public void run() {
        final long startTime = System.currentTimeMillis();
        while (true) {
          final long runTimeMillis = System.currentTimeMillis() - startTime;
          if (runTimeMillis > maxSearchTimeMillis) {
            // make sure there's no lingering thread for too long
            return;
          }
          clock.addAndGet(1);
          try {
            Thread.sleep(waitMillis);
          } catch (InterruptedException e) {
            throw new RuntimeException(e);
          }
View Full Code Here

  private Collector decorateWithTimeOutCollector(Collector collector) {
    Collector maybeTimeLimitingCollector = collector;
    if ( timeoutManager.getType() == TimeoutManager.Type.LIMIT ) {
      final Long timeoutLeft = timeoutManager.getTimeoutLeftInMilliseconds();
      if ( timeoutLeft != null ) {
        Counter counter = timeoutManager.getLuceneTimeoutCounter();
        maybeTimeLimitingCollector = new TimeLimitingCollector( collector, counter, timeoutLeft);
      }
    }
    return maybeTimeLimitingCollector;
  }
View Full Code Here

* tests basic {@link IntBlockPool} functionality
*/
public class TestIntBlockPool extends LuceneTestCase {
 
  public void testSingleWriterReader() {
    Counter bytesUsed = Counter.newCounter();
    IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
   
    for (int j = 0; j < 2; j++) {
      IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
      int start = writer.startNewSlice();
      int num = atLeast(100);
      for (int i = 0; i < num; i++) {
        writer.writeInt(i);
      }
     
      int upto = writer.getCurrentOffset();
      IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
      reader.reset(start, upto);
      for (int i = 0; i < num; i++) {
        assertEquals(i, reader.readInt());
      }
      assertTrue(reader.endOfSlice());
      if (random().nextBoolean()) {
        pool.reset(true, false);
        assertEquals(0, bytesUsed.get());
      } else {
        pool.reset(true, true);
        assertEquals(IntBlockPool.INT_BLOCK_SIZE
            * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.get());
      }
    }
  }
View Full Code Here

      }
    }
  }
 
  public void testMultipleWriterReader() {
    Counter bytesUsed = Counter.newCounter();
    IntBlockPool pool = new IntBlockPool(new ByteTrackingAllocator(bytesUsed));
    for (int j = 0; j < 2; j++) {
      List<StartEndAndValues> holders = new ArrayList<>();
      int num = atLeast(4);
      for (int i = 0; i < num; i++) {
        holders.add(new StartEndAndValues(random().nextInt(1000)));
      }
      IntBlockPool.SliceWriter writer = new IntBlockPool.SliceWriter(pool);
      IntBlockPool.SliceReader reader = new IntBlockPool.SliceReader(pool);
     
      int numValuesToWrite = atLeast(10000);
      for (int i = 0; i < numValuesToWrite; i++) {
        StartEndAndValues values = holders
            .get(random().nextInt(holders.size()));
        if (values.valueCount == 0) {
          values.start = writer.startNewSlice();
        } else {
          writer.reset(values.end);
        }
        writer.writeInt(values.nextValue());
        values.end = writer.getCurrentOffset();
        if (random().nextInt(5) == 0) {
          // pick one and reader the ints
          assertReader(reader, holders.get(random().nextInt(holders.size())));
        }
      }
     
      while (!holders.isEmpty()) {
        StartEndAndValues values = holders.remove(random().nextInt(
            holders.size()));
        assertReader(reader, values);
      }
      if (random().nextBoolean()) {
        pool.reset(true, false);
        assertEquals(0, bytesUsed.get());
      } else {
        pool.reset(true, true);
        assertEquals(IntBlockPool.INT_BLOCK_SIZE
            * RamUsageEstimator.NUM_BYTES_INT, bytesUsed.get());
      }
    }
  }
View Full Code Here

  private Collector decorateWithTimeOutCollector(Collector collector) {
    Collector maybeTimeLimitingCollector = collector;
    if ( timeoutManager.getType() == TimeoutManager.Type.LIMIT ) {
      final Long timeoutLeft = timeoutManager.getTimeoutLeftInMilliseconds();
      if ( timeoutLeft != null ) {
        Counter counter = timeoutManager.getLuceneTimeoutCounter();
        maybeTimeLimitingCollector = new TimeLimitingCollector( collector, counter, timeoutLeft);
      }
    }
    return maybeTimeLimitingCollector;
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.util.Counter$SerialCounter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.