Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix random failure in BulkCopyColumnMapping test #165

Merged
merged 2 commits into from
Mar 7, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ void testRepetativeCM() {
@DisplayName("BulkCopy:test implicit mismatched column mapping")
void testImplicitMismatchCM() {

// create dest table with different schema from source table
DBTable destTable = new DBTable(true);
// create non unicode dest table with different schema from source table
DBTable destTable = new DBTable(true, false, true);
stmt.createTable(destTable);

// set up bulkCopy with explicit column mapping
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/microsoft/sqlserver/testframework/DBSchema.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package com.microsoft.sqlserver.testframework;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import com.microsoft.sqlserver.testframework.sqlType.SqlBigInt;
Expand Down Expand Up @@ -88,6 +89,19 @@ public class DBSchema {
}
}

/**
*
* @param autoGenerateSchema
* @param alternateSchema
*/
DBSchema(boolean autoGenerateSchema,
boolean alternateSchema) {
this(autoGenerateSchema);
if (alternateSchema) {
Collections.shuffle(this.sqlTypes);
}
}

/**
*
* @param index
Expand Down
46 changes: 26 additions & 20 deletions src/test/java/com/microsoft/sqlserver/testframework/DBTable.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,41 @@ public class DBTable extends AbstractSQLGenerator {
* <code>true</code> : generates schema with all available dataTypes in SqlType class
*/
public DBTable(boolean autoGenerateSchema) {
this(autoGenerateSchema, false, false);
}

this.tableName = RandomUtil.getIdentifier("table");
this.escapedTableName = escapeIdentifier(tableName);
this.schema = new DBSchema(autoGenerateSchema);
if (autoGenerateSchema) {
addColumns();
}
else {
this.columns = new ArrayList<DBColumn>();
}
this.totalColumns = columns.size();
/**
* Initializes {@link DBTable} with tableName, schema, and {@link DBColumns}
*
* @param autoGenerateSchema
* <code>true</code>: generates schema with all available dataTypes in SqlType class
* @param unicode
* <code>true</code>: sets unicode column names if autoGenerateSchema is also set to <code>true</code>
*/
public DBTable(boolean autoGenerateSchema,
boolean unicode) {
this(autoGenerateSchema, unicode, false);
}

/**
* Initializes {@link DBTable} with tableName, schema, and {@link DBColumns}
*
* @param autoGenerateSchema
* <code>true</code>: generates schema with all available
* dataTypes in SqlType class
* <code>true</code>: generates schema with all available dataTypes in SqlType class
* @param unicode
* <code>true</code>: sets unicode column names if autoGenerateSchema is also set to <code>true</code>
* <code>true</code>: sets unicode column names if autoGenerateSchema is also set to <code>true</code>
* @param alternateShcema
* <code>true</code>: creates table with alternate schema
*/
public DBTable(boolean autoGenerateSchema, boolean unicode) {
public DBTable(boolean autoGenerateSchema,
boolean unicode,
boolean alternateSchema) {

this.tableName = RandomUtil.getIdentifier("table");
this.escapedTableName = escapeIdentifier(tableName);
this.schema = new DBSchema(autoGenerateSchema);
this.schema = new DBSchema(autoGenerateSchema, alternateSchema);
if (autoGenerateSchema) {
if(unicode)
if (unicode)
addColumns(unicode);
else
addColumns();
Expand Down Expand Up @@ -105,11 +111,11 @@ private void addColumns() {

for (int i = 0; i < totalColumns; i++) {
SqlType sqlType = schema.getSqlType(i);
DBColumn column = new DBColumn(RandomUtil.getIdentifier(sqlType.getName()), sqlType);
DBColumn column = new DBColumn(RandomUtil.getIdentifier(sqlType.getName()), sqlType);
columns.add(column);
}
}

/**
* adds a columns for each SQL type in DBSchema
*/
Expand All @@ -120,7 +126,7 @@ private void addColumns(boolean unicode) {
for (int i = 0; i < totalColumns; i++) {
SqlType sqlType = schema.getSqlType(i);
DBColumn column;
if(unicode)
if (unicode)
column = new DBColumn(RandomUtil.getIdentifier(sqlType.getName()) + "ĀĂŎՖએДЕЖЗИЙਟਖਞ", sqlType);
else
column = new DBColumn(RandomUtil.getIdentifier(sqlType.getName()), sqlType);
Expand Down