SOLR-3856: Improve tests for SqlEntityProcessor

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1407547 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Dyer 2012-11-09 17:17:54 +00:00
parent c87afb5a28
commit 18ed36adac
2 changed files with 40 additions and 13 deletions

View File

@ -37,7 +37,7 @@ import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
/**
* This sets up an in-memory Derby Sql database with a little sample data.
* This sets up an in-memory Sql database with a little sample data.
*/
public abstract class AbstractDIHJdbcTestCase extends AbstractDataImportHandlerTestCase {
//Start with "true" so the first test run will populate the data.
@ -99,14 +99,20 @@ public abstract class AbstractDIHJdbcTestCase extends AbstractDataImportHandlerT
}
protected void singleEntity(int numToExpect) throws Exception {
h.query("/dataimport", generateRequest());
assertQ(req("*:*"), "//*[@numFound='" + totalPeople() + "']");
Assert.assertTrue(totalDatabaseRequests() == numToExpect);
assertQ("There should be 1 document per person in the database: "
+ totalPeople(), req("*:*"), "//*[@numFound='" + totalPeople() + "']");
Assert.assertTrue("Expecting " + numToExpect
+ " database calls, but DIH reported " + totalDatabaseRequests(),
totalDatabaseRequests() == numToExpect);
}
protected void simpleTransform(int numToExpect) throws Exception {
rootTransformerName = "AddAColumnTransformer";
h.query("/dataimport", generateRequest());
assertQ(req("AddAColumn_s:Added"), "//*[@numFound='" + totalPeople() + "']");
Assert.assertTrue(totalDatabaseRequests() == numToExpect);
assertQ("There should be 1 document with a transformer-added column per person is the database: "
+ totalPeople(), req("AddAColumn_s:Added"), "//*[@numFound='" + totalPeople() + "']");
Assert.assertTrue("Expecting " + numToExpect
+ " database calls, but DIH reported " + totalDatabaseRequests(),
totalDatabaseRequests() == numToExpect);
}
/**
* A delta update will not clean up documents added by a transformer
@ -116,16 +122,19 @@ public abstract class AbstractDIHJdbcTestCase extends AbstractDataImportHandlerT
protected void complexTransform(int numToExpect, int numDeleted) throws Exception {
rootTransformerName = "TripleThreatTransformer";
h.query("/dataimport", generateRequest());
assertQ(req("q", "*:*", "rows", "" + (totalPeople() * 3), "sort", "id asc"), "//*[@numFound='" + ((totalPeople() * 3) + (numDeleted * 2)) + "']");
assertQ(req("id:TripleThreat-1-*"), "//*[@numFound='" + (totalPeople() + numDeleted) + "']");
assertQ(req("id:TripleThreat-2-*"), "//*[@numFound='" + (totalPeople() + numDeleted) + "']");
if(personNameExists("Michael") && countryCodeExists("NR") && countryCodeExists("RN"))
int totalDocs = ((totalPeople() * 3) + (numDeleted * 2));
int totalAddedDocs = (totalPeople() + numDeleted);
assertQ(req("q", "*:*", "rows", "" + (totalPeople() * 3), "sort", "id asc"), "//*[@numFound='" + totalDocs + "']");
assertQ(req("id:TripleThreat-1-*"), "//*[@numFound='" + totalAddedDocs + "']");
assertQ(req("id:TripleThreat-2-*"), "//*[@numFound='" + totalAddedDocs + "']");
if(personNameExists("Michael") && countryCodeExists("NR"))
{
assertQ(
"Michael and NR are assured to be in the database. Therefore the transformer should have added leahciM and RN on the same document as id:TripleThreat-1-3",
req("+id:TripleThreat-1-3 +NAME_mult_s:Michael +NAME_mult_s:leahciM +COUNTRY_CODES_mult_s:NR +COUNTRY_CODES_mult_s:RN"),
"//*[@numFound='1']");
}
assertQ(req("AddAColumn_s:Added"), "//*[@numFound='" + (totalPeople() + numDeleted) + "']");
assertQ(req("AddAColumn_s:Added"), "//*[@numFound='" + totalAddedDocs + "']");
Assert.assertTrue("Expecting " + numToExpect
+ " database calls, but DIH reported " + totalDatabaseRequests(),
totalDatabaseRequests() == numToExpect);
@ -177,9 +186,11 @@ public abstract class AbstractDIHJdbcTestCase extends AbstractDataImportHandlerT
}
h.query("/dataimport", generateRequest());
assertQ(req("*:*"), "//*[@numFound='" + (totalPeople()) + "']");
assertQ("There should be 1 document per person in the database: "
+ totalPeople(), req("*:*"), "//*[@numFound='" + (totalPeople()) + "']");
if(!underlyingDataModified && "AddAColumnTransformer".equals(rootTransformerName)) {
assertQ(req("AddAColumn_s:Added"), "//*[@numFound='" + (totalPeople()) + "']");
assertQ("There should be 1 document with a transformer-added column per person is the database: "
+ totalPeople(), req("AddAColumn_s:Added"), "//*[@numFound='" + (totalPeople()) + "']");
}
if(countryEntity) {
if(personNameExists("Jayden"))

View File

@ -1,6 +1,11 @@
package org.apache.solr.handler.dataimport;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import org.apache.solr.request.LocalSolrQueryRequest;
import org.junit.Assume;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -25,13 +30,20 @@ import org.junit.Test;
/**
* Test with various combinations of parameters, child entites, transformers.
*/
@Ignore("Investigate failures on Policeman Jenkins Linux")
public class TestSqlEntityProcessorDelta extends AbstractDIHJdbcTestCase {
private boolean delta = false;
private boolean useParentDeltaQueryParam = false;
private IntChanges personChanges = null;
private String[] countryChanges = null;
//TODO: remove this on fixing SOLR-4051 / SOLR-1916
private void assumeIncomaptibleLocale() {
Date d = new Date();
String badDateFormat = DataImporter.DATE_TIME_FORMAT.get().format(d);
String betterDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.ROOT).format(d);
Assume.assumeTrue(badDateFormat.equals(betterDateFormat));
}
@Before
public void setupDeltaTest() {
delta = false;
@ -40,6 +52,7 @@ public class TestSqlEntityProcessorDelta extends AbstractDIHJdbcTestCase {
}
@Test
public void testSingleEntity() throws Exception {
assumeIncomaptibleLocale();
singleEntity(1);
changeStuff();
int c = calculateDatabaseCalls();
@ -48,6 +61,7 @@ public class TestSqlEntityProcessorDelta extends AbstractDIHJdbcTestCase {
}
@Test
public void testWithSimpleTransformer() throws Exception {
assumeIncomaptibleLocale();
simpleTransform(1);
changeStuff();
simpleTransform(calculateDatabaseCalls());
@ -55,6 +69,7 @@ public class TestSqlEntityProcessorDelta extends AbstractDIHJdbcTestCase {
}
@Test
public void testWithComplexTransformer() throws Exception {
assumeIncomaptibleLocale();
complexTransform(1, 0);
changeStuff();
complexTransform(calculateDatabaseCalls(), personChanges.deletedKeys.length);
@ -62,6 +77,7 @@ public class TestSqlEntityProcessorDelta extends AbstractDIHJdbcTestCase {
}
@Test
public void testChildEntities() throws Exception {
assumeIncomaptibleLocale();
useParentDeltaQueryParam = random().nextBoolean();
withChildEntities(false, true);
changeStuff();