SolrCore core = SolrCore.getSolrCore();
MapSolrParams params = new MapSolrParams( new HashMap<String, String>() );
// Add a single document
SolrQueryResponse rsp = new SolrQueryResponse();
SolrQueryRequestBase req = new SolrQueryRequestBase( core, params ) {};
for( int i=0; i<14; i++ ) {
req.setContentStreams( toContentStreams(
adoc("id", "A"+i, "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
}
// It should not be there right away
assertQ("shouldn't find any", req("id:A1") ,"//result[@numFound=0]" );
assertEquals( 0, tracker.autoCommitCount );
req.setContentStreams( toContentStreams(
adoc("id", "A14", "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
// Wait longer then the autocommit time
Thread.sleep( 500 );
// blocks until commit is complete
req.setContentStreams( toContentStreams(
adoc("id", "A15", "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
// Now make sure we can find it
assertQ("should find one", req("id:A14") ,"//result[@numFound=1]" );
assertEquals( 1, tracker.autoCommitCount );
// But not the one added afterward
assertQ("should find one", req("id:A15") ,"//result[@numFound=0]" );
assertEquals( 1, tracker.autoCommitCount );
// Now add some more
for( int i=0; i<14; i++ ) {
req.setContentStreams( toContentStreams(
adoc("id", "B"+i, "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
}
// It should not be there right away
assertQ("shouldn't find any", req("id:B1") ,"//result[@numFound=0]" );
assertEquals( 1, tracker.autoCommitCount );
req.setContentStreams( toContentStreams(
adoc("id", "B14", "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
Thread.sleep( 500 );
// add request will block if commit has already started or completed
req.setContentStreams( toContentStreams(
adoc("id", "B15", "subject", "info" ), null ) );
handler.handleRequest( req, rsp );
assertQ("should find one", req("id:B14") ,"//result[@numFound=1]" );
assertEquals( 2, tracker.autoCommitCount );