Skip to content

Commit

Permalink
Improve Indexers test flow (Azure#303)
Browse files Browse the repository at this point in the history
- Remove unneeded code.
- Move methods from SearchServiceTestBase to sub-base classes
- Remove circular static import.
- re-record Indexers tests
  • Loading branch information
rabee333 authored Nov 27, 2019
1 parent 75bd774 commit 4fb8d40
Show file tree
Hide file tree
Showing 39 changed files with 1,008 additions and 1,207 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public Mono<Void> deleteDataSource(String name, AccessCondition accessCondition,
@Override
public void createAndListDataSources() {
DataSource dataSource1 = createTestBlobDataSource(null);
DataSource dataSource2 = createTestSqlDataSource(null, null);
DataSource dataSource2 = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);

client.createOrUpdateDataSource(dataSource1).block();
client.createOrUpdateDataSource(dataSource2).block();
Expand Down Expand Up @@ -131,12 +131,12 @@ public void deleteDataSourceIsIdempotent() {

@Override
public void canUpdateDataSource() {
DataSource initial = createTestDataSource();
DataSource initial = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);

// Create the data source
client.createOrUpdateDataSource(initial).block();

DataSource updatedExpected = createTestDataSource()
DataSource updatedExpected = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME)
.setName(initial.getName())
.setContainer(new DataContainer().setName("somethingdifferent"))
.setDescription("somethingdifferent")
Expand Down Expand Up @@ -251,7 +251,7 @@ public void existsReturnsFalseForNonExistingDatasource() {

@Override
public void existsReturnsTrueForExistingDatasource() {
DataSource dataSource = createTestDataSource();
DataSource dataSource = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);
client.createOrUpdateDataSource(dataSource).block();

StepVerifier
Expand All @@ -262,7 +262,7 @@ public void existsReturnsTrueForExistingDatasource() {

@Override
public void createDataSourceFailsWithUsefulMessageOnUserError() {
DataSource dataSource = createTestSqlDataSource(null, null);
DataSource dataSource = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);
dataSource.setType(DataSourceType.fromString("thistypedoesnotexist"));

StepVerifier
Expand All @@ -287,10 +287,10 @@ public void createDataSourceReturnsCorrectDefinition() {
.setHighWaterMarkColumnName("fakecolumn");

// AzureSql
createAndValidateDataSource(createTestSqlDataSource(null, null));
createAndValidateDataSource(createTestSqlDataSource(deletionDetectionPolicy, null));
createAndValidateDataSource(createTestSqlDataSource(null, new SqlIntegratedChangeTrackingPolicy()));
createAndValidateDataSource(createTestSqlDataSource(deletionDetectionPolicy, changeDetectionPolicy));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, null, null));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, deletionDetectionPolicy, null));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, null, new SqlIntegratedChangeTrackingPolicy()));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, deletionDetectionPolicy, changeDetectionPolicy));

// CosmosDB
createAndValidateDataSource(createTestCosmosDbDataSource(null, false));
Expand Down Expand Up @@ -323,7 +323,7 @@ public void getDataSourceReturnsCorrectDefinition() {

createGetAndValidateDataSource(createTestBlobDataSource(null));
createGetAndValidateDataSource(createTestTableStorageDataSource(null));
createGetAndValidateDataSource(createTestSqlDataSource(null, null));
createGetAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME));
createGetAndValidateDataSource(createTestCosmosDbDataSource(null, false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void deleteDataSource(String name, AccessCondition accessCondition, Reque
@Override
public void createAndListDataSources() {
DataSource dataSource1 = createTestBlobDataSource(null);
DataSource dataSource2 = createTestSqlDataSource(null, null);
DataSource dataSource2 = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);

client.createOrUpdateDataSource(dataSource1);
client.createOrUpdateDataSource(dataSource2);
Expand Down Expand Up @@ -132,7 +132,7 @@ public void deleteDataSourceIsIdempotent() {
public void createDataSourceFailsWithUsefulMessageOnUserError() {
client = getSearchServiceClientBuilder().buildClient();

DataSource dataSource = createTestSqlDataSource(null, null);
DataSource dataSource = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);
dataSource.setType(DataSourceType.fromString("thistypedoesnotexist"));

try {
Expand All @@ -147,12 +147,12 @@ public void createDataSourceFailsWithUsefulMessageOnUserError() {

@Override
public void canUpdateDataSource() {
DataSource initial = createTestDataSource();
DataSource initial = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);

// Create the data source
client.createOrUpdateDataSource(initial);

DataSource updatedExpected = createTestDataSource()
DataSource updatedExpected = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME)
.setName(initial.getName())
.setContainer(new DataContainer().setName("somethingdifferent"))
.setDescription("somethingdifferent")
Expand Down Expand Up @@ -261,7 +261,7 @@ public void existsReturnsFalseForNonExistingDatasource() {

@Override
public void existsReturnsTrueForExistingDatasource() {
DataSource dataSource = createTestDataSource();
DataSource dataSource = createTestSqlDataSourceObject(SQL_DATASOURCE_NAME);
client.createOrUpdateDataSource(dataSource);

Assert.assertTrue(client.datasourceExists(dataSource.getName()));
Expand All @@ -279,10 +279,10 @@ public void createDataSourceReturnsCorrectDefinition() {
.setHighWaterMarkColumnName("fakecolumn");

// AzureSql
createAndValidateDataSource(createTestSqlDataSource(null, null));
createAndValidateDataSource(createTestSqlDataSource(deletionDetectionPolicy, null));
createAndValidateDataSource(createTestSqlDataSource(null, new SqlIntegratedChangeTrackingPolicy()));
createAndValidateDataSource(createTestSqlDataSource(deletionDetectionPolicy, changeDetectionPolicy));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, null, null));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, deletionDetectionPolicy, null));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, null, new SqlIntegratedChangeTrackingPolicy()));
createAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME, deletionDetectionPolicy, changeDetectionPolicy));

// CosmosDB
createAndValidateDataSource(createTestCosmosDbDataSource(null, false));
Expand Down Expand Up @@ -315,7 +315,7 @@ public void getDataSourceReturnsCorrectDefinition() {

createGetAndValidateDataSource(createTestBlobDataSource(null));
createGetAndValidateDataSource(createTestTableStorageDataSource(null));
createGetAndValidateDataSource(createTestSqlDataSource(null, null));
createGetAndValidateDataSource(createTestSqlDataSourceObject(SQL_DATASOURCE_NAME));
createGetAndValidateDataSource(createTestCosmosDbDataSource(null, false));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,9 @@
package com.azure.search;

import com.azure.search.common.DataSources;
import com.azure.search.models.DataChangeDetectionPolicy;
import com.azure.search.models.DataContainer;
import com.azure.search.models.DataDeletionDetectionPolicy;
import com.azure.search.models.DataSource;
import com.azure.search.models.DataSourceCredentials;
import com.azure.search.models.HighWaterMarkChangeDetectionPolicy;
import com.azure.search.models.SoftDeleteColumnDeletionDetectionPolicy;
import org.junit.Assert;
import org.junit.Test;

Expand All @@ -19,18 +15,6 @@
public abstract class DataSourceTestBase extends SearchServiceTestBase {

private static final String FAKE_DESCRIPTION = "Some data source";
private static final String RESOURCE_NAME_PREFIX = "azs-";
// The connection string we use here, as well as table name and target index schema, use the USGS database
// that we set up to support our code samples.
//
// ASSUMPTION: Change tracking has already been enabled on the database with ALTER DATABASE ... SET CHANGE_TRACKING = ON
// and it has been enabled on the table with ALTER TABLE ... ENABLE CHANGE_TRACKING
private static final String SQL_CONN_STRING_FIXTURE = "Server=tcp:azs-playground.database.windows.net,1433;Database=usgs;User ID=reader;Password=EdrERBt3j6mZDP;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;";

@Override
protected void beforeTest() {
super.beforeTest();
}

@Test
public abstract void createAndListDataSources();
Expand Down Expand Up @@ -116,10 +100,6 @@ protected DataSource createTestBlobDataSource(DataDeletionDetectionPolicy deleti
);
}

protected DataSource createTestDataSource() {
return createTestSqlDataSource(null, null);
}

protected DataSource createTestTableStorageDataSource(DataDeletionDetectionPolicy deletionDetectionPolicy) {
return DataSources.azureTableStorage(
"azs-java-test-tablestorage",
Expand All @@ -131,17 +111,6 @@ protected DataSource createTestTableStorageDataSource(DataDeletionDetectionPolic
);
}

protected DataSource createTestSqlDataSource(DataDeletionDetectionPolicy deletionDetectionPolicy, DataChangeDetectionPolicy changeDetectionPolicy) {
return azureSql(
SQL_DATASOURCE_NAME,
SQL_CONN_STRING_FIXTURE,
"GeoNamesRI",
changeDetectionPolicy,
deletionDetectionPolicy,
FAKE_DESCRIPTION
);
}

protected DataSource createTestCosmosDbDataSource(
DataDeletionDetectionPolicy deletionDetectionPolicy,
boolean useChangeDetection) {
Expand All @@ -157,60 +126,6 @@ protected DataSource createTestCosmosDbDataSource(
);
}

/**
* Creates a new DataSource to connect to an Azure SQL database.
*
* @param name The name of the datasource.
* @param sqlConnectionString The connection string for the Azure SQL database.
* @param tableOrViewName The name of the table or view from which to read rows.
* @param changeDetectionPolicy The change detection policy for the datasource.
* Note that only high watermark change detection
* is allowed for Azure SQL when deletion detection is enabled.
* @param deletionDetectionPolicy The data deletion detection policy for the datasource.
* @param description Optional. Description of the datasource.
* @return A new DataSource instance.
*/
public static DataSource azureSql(
String name,
String sqlConnectionString,
String tableOrViewName,
DataChangeDetectionPolicy changeDetectionPolicy,
DataDeletionDetectionPolicy deletionDetectionPolicy,
String description) {
return DataSources.azureSql(
name,
sqlConnectionString,
tableOrViewName,
description,
changeDetectionPolicy,
deletionDetectionPolicy);
}

protected DataSource updateDatasource(DataSource initial) {
DataSource updatedExpected =
createTestBlobDataSource(null);

updatedExpected.setName(initial.getName());
DataContainer container = new DataContainer();
container.setName("somethingdifferent");
updatedExpected.setContainer(container);
updatedExpected.setDescription("somethingdifferent");
HighWaterMarkChangeDetectionPolicy policy = new HighWaterMarkChangeDetectionPolicy();
policy.setHighWaterMarkColumnName("rowversion");
SoftDeleteColumnDeletionDetectionPolicy policy2 = new SoftDeleteColumnDeletionDetectionPolicy();
policy2.setSoftDeleteMarkerValue("1");
policy2.setSoftDeleteColumnName("isDeleted");
updatedExpected.setDataDeletionDetectionPolicy(policy2);

return updatedExpected;
}

protected void removeConnectionString(DataSource datasource) {
DataSourceCredentials cred = new DataSourceCredentials();
cred.setConnectionString(null);
datasource.setCredentials(cred);
}

protected void assertDataSourcesEqual(DataSource updatedExpected, DataSource actualDataSource) {
// Using assertReflectionEquals also checks the etag, however we do not care
// for that value, hence, we change both to the same value to make sure it
Expand Down
Loading

0 comments on commit 4fb8d40

Please sign in to comment.