alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Lucene example source code file (PerfTaskTest.java)

This example Lucene source code file (PerfTaskTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Lucene tags/keywords

benchmarktestcase, config, exception, exception, fs, myperftask, myperftask, override, perfrundata, perfrundata, perftask, perftasktest, properties, properties, util

The Lucene PerfTaskTest.java source code

package org.apache.lucene.benchmark.byTask.tasks;

/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import java.util.Properties;

import org.apache.lucene.benchmark.BenchmarkTestCase;
import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.benchmark.byTask.utils.Config;

/** Tests the functionality of the abstract {@link PerfTask}. */
public class PerfTaskTest extends BenchmarkTestCase {

  private static final class MyPerfTask extends PerfTask {

    public MyPerfTask(PerfRunData runData) {
      super(runData);
    }

    @Override
    public int doLogic() throws Exception {
      return 0;
    }

    public int getLogStep() { return logStep; }
    
  }
  
  private PerfRunData createPerfRunData(boolean setLogStep, int logStepVal,
      boolean setTaskLogStep, int taskLogStepVal) throws Exception {
    Properties props = new Properties();
    if (setLogStep) {
      props.setProperty("log.step", Integer.toString(logStepVal));
    }
    if (setTaskLogStep) {
      props.setProperty("log.step.MyPerf", Integer.toString(taskLogStepVal));
    }
    props.setProperty("directory", "RAMDirectory"); // no accidental FS dir.
    Config config = new Config(props);
    return new PerfRunData(config);
  }
  
  private void doLogStepTest(boolean setLogStep, int logStepVal,
      boolean setTaskLogStep, int taskLogStepVal, int expLogStepValue) throws Exception {
    PerfRunData runData = createPerfRunData(setLogStep, logStepVal, setTaskLogStep, taskLogStepVal);
    MyPerfTask mpt = new MyPerfTask(runData);
    assertEquals(expLogStepValue, mpt.getLogStep());
  }
  
  public void testLogStep() throws Exception {
    doLogStepTest(false, -1, false, -1, PerfTask.DEFAULT_LOG_STEP);
    doLogStepTest(true, -1, false, -1, Integer.MAX_VALUE);
    doLogStepTest(true, 100, false, -1, 100);
    doLogStepTest(false, -1, true, -1, Integer.MAX_VALUE);
    doLogStepTest(false, -1, true, 100, 100);
  }
  
}

Other Lucene examples (source code examples)

Here is a short list of links related to this Lucene PerfTaskTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.