Skip to content

Commit

Permalink
Adding tests for creating Indexers with Schedule and BatchSize (Azure…
Browse files Browse the repository at this point in the history
…#251)

Adding tests: 
* canCreateIndexerWithBatchSizeMaxFailedItems()
* canCreateIndexerWithSchedule()
  • Loading branch information
rabee333 authored Nov 14, 2019
1 parent b7b4ab9 commit 3cdb9e6
Show file tree
Hide file tree
Showing 5 changed files with 281 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -98,36 +98,50 @@ public void createIndexerFailsWithUsefulMessageOnUserError() {

@Override
public void canUpdateIndexer() {
Indexer updatedExpected = changeIndexerBasic();
Indexer updatedExpected = createIndexerWithDifferentDescription();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerFieldMapping() {
Indexer updatedExpected = changeIndexerFieldMapping();
Indexer updatedExpected = createIndexerWithDifferentFieldMapping();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerDisabled() {
Indexer updatedExpected = changeIndexerDisabled();
Indexer updatedExpected = createDisabledIndexer();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerSchedule() {
Indexer updatedExpected = changeIndexerSchedule();
Indexer updatedExpected = createIndexerWithDifferentSchedule();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canCreateIndexerWithSchedule() {
Indexer indexer = createIndexerWithDifferentSchedule();

createAndValidateIndexer(indexer);
}

@Override
public void canUpdateIndexerBatchSizeMaxFailedItems() {
Indexer updatedExpected = changeIndexerBatchSizeMaxFailedItems();
Indexer updatedExpected = createIndexerWithDifferentIndexingParameters();

createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canCreateIndexerWithBatchSizeMaxFailedItems() {
Indexer indexer = createIndexerWithDifferentIndexingParameters();

createUpdateValidateIndexer(updatedExpected);
createAndValidateIndexer(indexer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,36 +101,50 @@ public void createIndexerFailsWithUsefulMessageOnUserError() {

@Override
public void canUpdateIndexer() {
Indexer updatedExpected = changeIndexerBasic();
Indexer updatedExpected = createIndexerWithDifferentDescription();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerFieldMapping() {
Indexer updatedExpected = changeIndexerFieldMapping();
Indexer updatedExpected = createIndexerWithDifferentFieldMapping();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerDisabled() {
Indexer updatedExpected = changeIndexerDisabled();
Indexer updatedExpected = createDisabledIndexer();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canUpdateIndexerSchedule() {
Indexer updatedExpected = changeIndexerSchedule();
Indexer updatedExpected = createIndexerWithDifferentSchedule();

createUpdateValidateIndexer(updatedExpected);
createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canCreateIndexerWithSchedule() {
Indexer indexer = createIndexerWithDifferentSchedule();

createAndValidateIndexer(indexer);
}

@Override
public void canUpdateIndexerBatchSizeMaxFailedItems() {
Indexer updatedExpected = changeIndexerBatchSizeMaxFailedItems();
Indexer updatedExpected = createIndexerWithDifferentIndexingParameters();

createUpdateAndValidateIndexer(updatedExpected);
}

@Override
public void canCreateIndexerWithBatchSizeMaxFailedItems() {
Indexer indexer = createIndexerWithDifferentIndexingParameters();

createUpdateValidateIndexer(updatedExpected);
createAndValidateIndexer(indexer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.time.Duration;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Collections;
import java.util.List;

import static org.unitils.reflectionassert.ReflectionAssert.assertReflectionEquals;
Expand Down Expand Up @@ -44,9 +44,15 @@ public abstract class IndexersManagementTestBase extends SearchServiceTestBase {
@Test
public abstract void canUpdateIndexerSchedule();

@Test
public abstract void canCreateIndexerWithSchedule();

@Test
public abstract void canUpdateIndexerBatchSizeMaxFailedItems();

@Test
public abstract void canCreateIndexerWithBatchSizeMaxFailedItems();

protected void assertIndexersEqual(Indexer expected, Indexer actual) {
expected.setETag("none");
actual.setETag("none");
Expand Down Expand Up @@ -112,9 +118,8 @@ void assertException(Runnable exceptionThrower, Class<? extends Exception> expec
* Creates the index and indexer in the search service and then update the indexer
* @param updatedIndexer the indexer to be updated
*/
protected void createUpdateValidateIndexer(Indexer updatedIndexer) {
// Create the data source, note it's a valid DS with actual
// connection string
void createUpdateAndValidateIndexer(Indexer updatedIndexer) {
// Create the data source, note it's a valid DS with actual connection string
DataSource datasource = createTestSqlDataSource();
createDatasource(datasource);

Expand All @@ -138,94 +143,105 @@ protected void createUpdateValidateIndexer(Indexer updatedIndexer) {
assertIndexersEqual(updatedIndexer, updatedResponse);
}

void createAndValidateIndexer(Indexer indexer) {
// Create the data source, note it's a valid DS with actual connection string
DataSource datasource = createTestSqlDataSource();
createDatasource(datasource);

// Create an index
Index index = createTestIndexForLiveDatasource();
createIndex(index);

// create this indexer in the service
Indexer indexerResponse = createIndexer(indexer);

// verify the returned indexer is as expected
assertIndexersEqual(indexer, indexerResponse);
}

/**
* Change a basic property of an indexer and return it
* @return the updated indexer
* Create a new indexer and change its description property
* @return the created indexer
*/
protected Indexer changeIndexerBasic() {
// create another indexer object
Indexer updatedExpected =
createTestIndexer("indexer");
Indexer createIndexerWithDifferentDescription() {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer");

// modify it
updatedExpected.setDescription("somethingdifferent");
indexer.setDescription("somethingdifferent");

return updatedExpected;
return indexer;
}

/**
* Change the field mappings property of an indexer and return it
* @return the updated indexer
* Create a new indexer and change its field mappings property
* @return the created indexer
*/
protected Indexer changeIndexerFieldMapping() {
// Check field mappings can be changed
List<FieldMapping> lst = new LinkedList<>();
FieldMapping fm = new FieldMapping();
fm.setSourceFieldName("state_alpha");
fm.setTargetFieldName("state");
lst.add(fm);

Indexer createIndexerWithDifferentFieldMapping() {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer");

// create another indexer object
Indexer updatedExpected =
createTestIndexer("indexer");
// Create field mappings
List<FieldMapping> fieldMappings = Collections.singletonList(new FieldMapping()
.setSourceFieldName("state_alpha")
.setTargetFieldName("state"));

// modify it
updatedExpected.setFieldMappings(lst);
// modify the indexer
indexer.setFieldMappings(fieldMappings);

return updatedExpected;
return indexer;
}

/**
* Change the Disabled property of an indexer and return it
* @return the updated indexer
* Create a new indexer and set the Disabled property to true
* @return the created indexer
*/
protected Indexer changeIndexerDisabled() {
// create another indexer object
Indexer updatedExpected =
createTestIndexer("indexer");
Indexer createDisabledIndexer() {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer");

// modify it
updatedExpected.setIsDisabled(false);
indexer.setIsDisabled(false);

return updatedExpected;
return indexer;
}

/**
* Change the schedule property of an indexer and return it
* @return the updated indexer
* Create a new indexer and change its schedule property
* @return the created indexer
*/
protected Indexer changeIndexerSchedule() {
// create another indexer object
Indexer updatedExpected =
createTestIndexer("indexer");
Indexer createIndexerWithDifferentSchedule() {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer");

IndexingSchedule is = new IndexingSchedule();
is.setInterval(Duration.ofMinutes(10));
IndexingSchedule is = new IndexingSchedule()
.setInterval(Duration.ofMinutes(10));

// modify it
updatedExpected.setSchedule(is);
// modify the indexer
indexer.setSchedule(is);

return updatedExpected;
return indexer;
}

protected Indexer changeIndexerBatchSizeMaxFailedItems() {
// create another indexer object
Indexer updatedExpected =
createTestIndexer("indexer");
/**
* Create a new indexer and change its indexing parameters
* @return the created indexer
*/
Indexer createIndexerWithDifferentIndexingParameters() {
// create a new indexer object
Indexer indexer = createTestIndexer("indexer");

IndexingParameters ip = new IndexingParameters();
ip.setMaxFailedItems(121);
ip.setMaxFailedItemsPerBatch(11);
IndexingParameters ip = new IndexingParameters()
.setMaxFailedItems(121)
.setMaxFailedItemsPerBatch(11)
.setBatchSize(20);

ip.setBatchSize(20);
// modify it
updatedExpected.setParameters(ip);
// modify the indexer
indexer.setParameters(ip);

return updatedExpected;
return indexer;
}


protected abstract Index createIndex(Index index);

protected abstract DataSource createDatasource(DataSource datasource);
Expand Down
Loading

0 comments on commit 3cdb9e6

Please sign in to comment.