Skip to content

Commit 2137c69

Browse files
fixing up.
1 parent 27bbd79 commit 2137c69

File tree

5 files changed

+20
-38
lines changed

5 files changed

+20
-38
lines changed

amazon-redshift-plugin/src/test/java/io/cdap/plugin/amazon/redshift/RedshiftFailedConnectionTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,4 @@ public void test() throws ClassNotFoundException, IOException {
3535
"{user=username}. Error: ConnectException: Connection refused " +
3636
"(Connection refused).");
3737
}
38-
}
38+
}

database-commons/src/main/java/io/cdap/plugin/db/config/AbstractDBSpecificSourceConfig.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ public String getBoundingQuery() {
130130
return cleanQuery(boundingQuery);
131131
}
132132

133-
134-
public void validate(FailureCollector collector) {
133+
public void validate(FailureCollector collector) {
135134
boolean hasOneSplit = false;
136135
if (!containsMacro(NUM_SPLITS) && numSplits != null) {
137136
if (numSplits < 1) {
@@ -171,13 +170,12 @@ public void validate(FailureCollector collector) {
171170
.withConfigProperty(TABLE_NAME);
172171
}
173172
}
174-
if (!Strings.isNullOrEmpty(importQuery) &&
175-
(!hasOneSplit && !containsMacro(IMPORT_QUERY) && !getImportQuery().contains("$CONDITIONS"))) {
176-
collector.addFailure(String.format(
177-
"Import Query %s must contain the string '$CONDITIONS'. " +
178-
"if Number of Splits is not set to 1.", importQuery),
179-
"Include '$CONDITIONS' in the Import Query")
180-
.withConfigProperty(IMPORT_QUERY);
173+
174+
if (!hasOneSplit && !containsMacro(IMPORT_QUERY) && !getImportQuery().contains("$CONDITIONS")) {
175+
collector.addFailure(String.format(
176+
"Import Query %s must contain the string '$CONDITIONS'. if Number of Splits is not set to 1.", importQuery),
177+
"Include '$CONDITIONS' in the Import Query")
178+
.withConfigProperty(IMPORT_QUERY);
181179
}
182180

183181
if (!hasOneSplit && !containsMacro(SPLIT_BY) && (splitBy == null || splitBy.isEmpty())) {
@@ -219,8 +217,9 @@ public void validateSchema(Schema actualSchema, FailureCollector collector) {
219217
Schema actualFieldSchema = actualField.getSchema().isNullable() ?
220218
actualField.getSchema().getNonNullable() : actualField.getSchema();
221219
Schema expectedFieldSchema = field.getSchema().isNullable() ?
222-
field.getSchema().getNonNullable() : field.getSchema();
223-
validateField(collector, field, actualFieldSchema, expectedFieldSchema);
220+
field.getSchema().getNonNullable() : field.getSchema();
221+
222+
validateField(collector, field, actualFieldSchema, expectedFieldSchema);
224223
}
225224
}
226225

database-commons/src/main/java/io/cdap/plugin/db/source/AbstractDBSource.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,14 +166,11 @@ public Schema getSchema() throws SQLException {
166166
executeInitQueries(connection, sourceConfig.getInitQueries());
167167
String query = sourceConfig.getImportQuery();
168168
ImportQueryType type = ImportQueryType.fromString(sourceConfig.getImportQueryType());
169-
if (type == ImportQueryType.IMPORT_QUERY) {
170-
return loadSchemaFromDBwithQuery(connection, query);
171-
} else if (type == ImportQueryType.TABLE_NAME) {
169+
if (type == ImportQueryType.TABLE_NAME) {
172170
List<Schema.Field> fields = getSchemaReader().getSchemaFields(connection, sourceConfig.getTableName());
173171
return Schema.recordOf("schema", fields);
174-
} else {
175-
throw new SQLException("Either importQuery or tableName must be provided to get schema.");
176172
}
173+
return loadSchemaFromDBwithQuery(connection, query);
177174
}
178175
}
179176

@@ -501,7 +498,7 @@ public String getTableName() {
501498
}
502499

503500
public String getImportQueryType() {
504-
return " ";
501+
return null;
505502
}
506503

507504
public String getBoundingQuery() {

database-commons/src/test/java/io/cdap/plugin/db/source/AbstractDBSourceTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public String getConnectionString() {
4949
return "";
5050
}
5151
public String getTableName() {
52-
return " ";
52+
return "";
5353
}
5454
};
5555

postgresql-plugin/src/test/java/io/cdap/plugin/postgres/PostgresFailedConnectionTest.java

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.junit.Test;
2121

2222
import java.io.IOException;
23-
import static org.junit.Assert.assertTrue;
2423

2524
public class PostgresFailedConnectionTest extends DBSpecificFailedConnectionTest {
2625
private static final String JDBC_DRIVER_CLASS_NAME = "org.postgresql.Driver";
@@ -29,24 +28,11 @@ public class PostgresFailedConnectionTest extends DBSpecificFailedConnectionTest
2928
public void test() throws ClassNotFoundException, IOException {
3029

3130
PostgresConnector connector = new PostgresConnector(
32-
new PostgresConnectorConfig("localhost", 5432, "username", "password",
33-
"jdbc", ""));
31+
new PostgresConnectorConfig("localhost", 5432, "username", "password", "jdbc", ""));
3432

35-
String expectedPrefix = "Failed to create connection to database via connection string: " +
36-
"jdbc:postgresql://localhost:5432/null and arguments: {user=username}. Error:";
37-
38-
try {
39-
super.test(JDBC_DRIVER_CLASS_NAME, connector, expectedPrefix + " ConnectException:" +
40-
" Connection refused (Connection refused).");
41-
} catch (AssertionError e) {
42-
// Accept either ConnectException or authentication failure as a valid error
43-
String message = e.getMessage();
44-
assertTrue(
45-
"Expected connection failure due to either connection refused or authentication " +
46-
"failed, but got: " + message,
47-
message.contains("ConnectException: Connection refused") ||
48-
message.contains("FATAL: password authentication failed")
49-
);
50-
}
33+
super.test(JDBC_DRIVER_CLASS_NAME, connector, "Failed to create connection to database via connection string: " +
34+
"jdbc:postgresql://localhost:5432/null and arguments: " +
35+
"{user=username}. Error: ConnectException: Connection refused " +
36+
"(Connection refused).");
5137
}
5238
}

0 commit comments

Comments
 (0)