Package org.elasticsearch.test
Class BackgroundIndexer
java.lang.Object
org.elasticsearch.test.BackgroundIndexer
- All Implemented Interfaces:
java.lang.AutoCloseable
public class BackgroundIndexer
extends java.lang.Object
implements java.lang.AutoCloseable
-
Constructor Summary
Constructors Constructor Description BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs)
Start indexing in the background using a random number of threads.BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs, int writerCount)
Start indexing in the background using a given number of threads.BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs, int writerCount, boolean autoStart, java.util.Random random)
Start indexing in the background using a given number of threads. -
Method Summary
Modifier and Type Method Description void
assertNoFailures()
void
awaitStopped()
void
close()
void
continueIndexing(int numOfDocs)
Continue indexing after it has paused.org.elasticsearch.client.Client
getClient()
java.util.Set<java.lang.String>
getIds()
Returns the ID set of all documents indexed by this indexer runvoid
pauseIndexing()
Pausing indexing by setting current document limit to 0void
setFailureAssertion(java.util.function.Consumer<java.lang.Exception> failureAssertion)
Set a consumer that can be used to run assertions on failures during indexing.void
setIgnoreIndexingFailures(boolean ignoreIndexingFailures)
void
setRequestTimeout(org.elasticsearch.common.unit.TimeValue timeout)
void
start(int numOfDocs)
Start indexingvoid
stop()
Stop all background threads but don't wait for ongoing indexing operations to finish *void
stopAndAwaitStopped()
Stop all background threads and wait for ongoing indexing operations to finish *long
totalIndexedDocs()
-
Constructor Details
-
BackgroundIndexer
public BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs)Start indexing in the background using a random number of threads. Indexing will be paused after numOfDocs docs has been indexed.- Parameters:
index
- index name to index intotype
- document typeclient
- client to usenumOfDocs
- number of document to index before pausing. Set to -1 to have no limit.
-
BackgroundIndexer
public BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs, int writerCount)Start indexing in the background using a given number of threads. Indexing will be paused after numOfDocs docs has been indexed.- Parameters:
index
- index name to index intotype
- document typeclient
- client to usenumOfDocs
- number of document to index before pausing. Set to -1 to have no limit.writerCount
- number of indexing threads to use
-
BackgroundIndexer
public BackgroundIndexer(java.lang.String index, java.lang.String type, org.elasticsearch.client.Client client, int numOfDocs, int writerCount, boolean autoStart, java.util.Random random)Start indexing in the background using a given number of threads. Indexing will be paused after numOfDocs docs has been indexed.- Parameters:
index
- index name to index intotype
- document typeclient
- client to usenumOfDocs
- number of document to index before pausing. Set to -1 to have no limit.writerCount
- number of indexing threads to useautoStart
- set to true to start indexing as soon as all threads have been created.random
- random instance to use
-
-
Method Details
-
setRequestTimeout
public void setRequestTimeout(org.elasticsearch.common.unit.TimeValue timeout) -
setIgnoreIndexingFailures
public void setIgnoreIndexingFailures(boolean ignoreIndexingFailures) -
start
public void start(int numOfDocs)Start indexing- Parameters:
numOfDocs
- number of document to index before pausing. Set to -1 to have no limit.
-
pauseIndexing
public void pauseIndexing()Pausing indexing by setting current document limit to 0 -
continueIndexing
public void continueIndexing(int numOfDocs)Continue indexing after it has paused.- Parameters:
numOfDocs
- number of document to index before pausing. Set to -1 to have no limit.
-
stop
public void stop()Stop all background threads but don't wait for ongoing indexing operations to finish * -
awaitStopped
public void awaitStopped() throws java.lang.InterruptedException- Throws:
java.lang.InterruptedException
-
stopAndAwaitStopped
public void stopAndAwaitStopped() throws java.lang.InterruptedExceptionStop all background threads and wait for ongoing indexing operations to finish *- Throws:
java.lang.InterruptedException
-
totalIndexedDocs
public long totalIndexedDocs() -
assertNoFailures
public void assertNoFailures() -
setFailureAssertion
public void setFailureAssertion(java.util.function.Consumer<java.lang.Exception> failureAssertion)Set a consumer that can be used to run assertions on failures during indexing. If such a consumer is set then it disables adding failures tofailures
. Should be used if the number of expected failures during indexing could become very large. -
close
public void close() throws java.lang.Exception- Specified by:
close
in interfacejava.lang.AutoCloseable
- Throws:
java.lang.Exception
-
getClient
public org.elasticsearch.client.Client getClient() -
getIds
public java.util.Set<java.lang.String> getIds()Returns the ID set of all documents indexed by this indexer run
-