Skip to content

Commit

Permalink
Revert DocumentDB source hosts array to host string
Browse files Browse the repository at this point in the history
Signed-off-by: Dinu John <[email protected]>
  • Loading branch information
dinujoh committed Apr 24, 2024
1 parent 92efb15 commit ab46266
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ private static String getConnectionString(final MongoDBSourceConfig sourceConfig
throw new RuntimeException("Unsupported characters in password.");
}

if (sourceConfig.getHosts() == null || sourceConfig.getHosts().length == 0) {
throw new RuntimeException("The hosts array should at least have one host.");
if (sourceConfig.getHost() == null || sourceConfig.getHost().isBlank()) {
throw new RuntimeException("The host should not be null or empty.");
}

// Support for only single host
final String hostname = sourceConfig.getHosts()[0];
final String hostname = sourceConfig.getHost();
final int port = sourceConfig.getPort();
final String tls = sourceConfig.getTls().toString();
final String invalidHostAllowed = sourceConfig.getSslInsecureDisableVerification().toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@ public class MongoDBSourceConfig {
private static final int DEFAULT_PORT = 27017;
private static final Boolean DEFAULT_INSECURE = false;
private static final Boolean DEFAULT_INSECURE_DISABLE_VERIFICATION = false;
private static final String DEFAULT_SNAPSHOT_FETCH_SIZE = "1000";
private static final String DEFAULT_READ_PREFERENCE = "primaryPreferred";
private static final Boolean DEFAULT_DIRECT_CONNECT = true;
private static final Duration DEFAULT_ACKNOWLEDGEMENT_SET_TIMEOUT = Duration.ofHours(2);
@JsonProperty("hosts")
private @NotNull String[] hosts;
@JsonProperty("host")
private @NotNull String host;
@JsonProperty("port")
private int port = DEFAULT_PORT;
@JsonProperty("trust_store_file_path")
Expand All @@ -27,8 +26,6 @@ public class MongoDBSourceConfig {
@JsonProperty("authentication")
private AuthenticationConfig authenticationConfig;

@JsonProperty("snapshot_fetch_size")
private String snapshotFetchSize;
@JsonProperty("read_preference")
private String readPreference;
@JsonProperty("collections")
Expand Down Expand Up @@ -61,7 +58,6 @@ public class MongoDBSourceConfig {
private AwsConfig awsConfig;

public MongoDBSourceConfig() {
this.snapshotFetchSize = DEFAULT_SNAPSHOT_FETCH_SIZE;
this.readPreference = DEFAULT_READ_PREFERENCE;
this.collections = new ArrayList<>();
this.insecure = DEFAULT_INSECURE;
Expand All @@ -74,8 +70,8 @@ public AuthenticationConfig getAuthenticationConfig() {
return this.authenticationConfig;
}

public String[] getHosts() {
return this.hosts;
public String getHost() {
return this.host;
}

public int getPort() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void setUp() {
when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig);
when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID());
when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID());
when(mongoDBSourceConfig.getHosts()).thenReturn(new String[] { UUID.randomUUID().toString() });
when(mongoDBSourceConfig.getHost()).thenReturn(UUID.randomUUID().toString());
when(mongoDBSourceConfig.getPort()).thenReturn(getRandomInteger());
when(mongoDBSourceConfig.getTls()).thenReturn(getRandomBoolean());
when(mongoDBSourceConfig.getSslInsecureDisableVerification()).thenReturn(getRandomBoolean());
Expand Down Expand Up @@ -71,7 +71,7 @@ public void getMongoClientNullHost() {
when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig);
when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID());
when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID());
when(mongoDBSourceConfig.getHosts()).thenReturn(null);
when(mongoDBSourceConfig.getHost()).thenReturn(null);
assertThrows(RuntimeException.class, () -> MongoDBConnection.getMongoClient(mongoDBSourceConfig));
}

Expand All @@ -80,7 +80,7 @@ public void getMongoClientEmptyHost() {
when(mongoDBSourceConfig.getAuthenticationConfig()).thenReturn(authenticationConfig);
when(authenticationConfig.getUsername()).thenReturn("\uD800\uD800" + UUID.randomUUID());
when(authenticationConfig.getPassword()).thenReturn("aЯ ⾀sd?q=%%l€0£.lo" + UUID.randomUUID());
when(mongoDBSourceConfig.getHosts()).thenReturn(new String[]{});
when(mongoDBSourceConfig.getHost()).thenReturn(" ");
assertThrows(RuntimeException.class, () -> MongoDBConnection.getMongoClient(mongoDBSourceConfig));
}

Expand Down

0 comments on commit ab46266

Please sign in to comment.