Skip to content

Commit

Permalink
Set tinyInt1isBit to false
Browse files Browse the repository at this point in the history
Signed-off-by: Hai Yan <[email protected]>
  • Loading branch information
oeyh committed Nov 25, 2024
1 parent 539d599 commit 496976b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@

public class ConnectionManager {
static final String JDBC_URL_FORMAT = "jdbc:mysql://%s:%d";
static final String USERNAME_KEY = "user";
static final String PASSWORD_KEY = "password";
static final String USE_SSL_KEY = "useSSL";
static final String REQUIRE_SSL_KEY = "requireSSL";
static final String TINY_INT_ONE_IS_BIT_KEY = "tinyInt1isBit";
static final String TRUE_VALUE = "true";
static final String FALSE_VALUE = "false";
private final String hostName;
private final int port;
private final String username;
Expand All @@ -28,14 +35,15 @@ public ConnectionManager(String hostName, int port, String username, String pass

public Connection getConnection() throws SQLException {
final Properties props = new Properties();
props.setProperty("user", username);
props.setProperty("password", password);
props.setProperty(USERNAME_KEY, username);
props.setProperty(PASSWORD_KEY, password);
if (requireSSL) {
props.setProperty("useSSL", "true");
props.setProperty("requireSSL", "true");
props.setProperty(USE_SSL_KEY, TRUE_VALUE);
props.setProperty(REQUIRE_SSL_KEY, TRUE_VALUE);
} else {
props.setProperty("useSSL", "false");
props.setProperty(USE_SSL_KEY, FALSE_VALUE);
}
props.setProperty(TINY_INT_ONE_IS_BIT_KEY, FALSE_VALUE);
final String jdbcUrl = String.format(JDBC_URL_FORMAT, hostName, port);
return doGetConnection(jdbcUrl, props);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.FALSE_VALUE;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.PASSWORD_KEY;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.REQUIRE_SSL_KEY;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.TINY_INT_ONE_IS_BIT_KEY;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.TRUE_VALUE;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.USERNAME_KEY;
import static org.opensearch.dataprepper.plugins.source.rds.schema.ConnectionManager.USE_SSL_KEY;


class ConnectionManagerTest {
Expand Down Expand Up @@ -51,10 +58,11 @@ void test_getConnection_when_requireSSL_is_true() throws SQLException {

assertThat(jdbcUrlArgumentCaptor.getValue(), is(String.format(ConnectionManager.JDBC_URL_FORMAT, hostName, port)));
final Properties properties = propertiesArgumentCaptor.getValue();
assertThat(properties.getProperty("user"), is(username));
assertThat(properties.getProperty("password"), is(password));
assertThat(properties.getProperty("useSSL"), is("true"));
assertThat(properties.getProperty("requireSSL"), is("true"));
assertThat(properties.getProperty(USERNAME_KEY), is(username));
assertThat(properties.getProperty(PASSWORD_KEY), is(password));
assertThat(properties.getProperty(USE_SSL_KEY), is(TRUE_VALUE));
assertThat(properties.getProperty(REQUIRE_SSL_KEY), is(TRUE_VALUE));
assertThat(properties.getProperty(TINY_INT_ONE_IS_BIT_KEY), is(FALSE_VALUE));
}

@Test
Expand All @@ -69,9 +77,10 @@ void test_getConnection_when_requireSSL_is_false() throws SQLException {

assertThat(jdbcUrlArgumentCaptor.getValue(), is(String.format(ConnectionManager.JDBC_URL_FORMAT, hostName, port)));
final Properties properties = propertiesArgumentCaptor.getValue();
assertThat(properties.getProperty("user"), is(username));
assertThat(properties.getProperty("password"), is(password));
assertThat(properties.getProperty("useSSL"), is("false"));
assertThat(properties.getProperty(USERNAME_KEY), is(username));
assertThat(properties.getProperty(PASSWORD_KEY), is(password));
assertThat(properties.getProperty(USE_SSL_KEY), is(FALSE_VALUE));
assertThat(properties.getProperty(TINY_INT_ONE_IS_BIT_KEY), is(FALSE_VALUE));
}

private ConnectionManager createObjectUnderTest() {
Expand Down

0 comments on commit 496976b

Please sign in to comment.