io.r2dbc.spi.ConnectionFactories Java Examples

The following examples show how to use io.r2dbc.spi.ConnectionFactories. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CloudConfig.java    From cf-butler with Apache License 2.0 8 votes vote down vote up
@Bean
@ConditionalOnProperty(VCAP_SERVICE_VARIABLE)
ConnectionFactory connectionFactory() {
    R2dbcProperties properties = r2dbcProperties();
    ConnectionFactoryOptions.Builder builder = ConnectionFactoryOptions
            .parse(properties.getUrl()).mutate();
    String username = properties.getUsername();
    if (StringUtils.hasText(username)) {
        builder.option(ConnectionFactoryOptions.USER, username);
    }
    String password = properties.getPassword();
    if (StringUtils.hasText(password)) {
        builder.option(ConnectionFactoryOptions.PASSWORD, password);
    }
    String databaseName = properties.getName();
    if (StringUtils.hasText(databaseName)) {
        builder.option(ConnectionFactoryOptions.DATABASE, databaseName);
    }
    if (properties.getProperties() != null) {
        properties.getProperties()
                .forEach((key, value) -> builder
                        .option(Option.valueOf(key), value));
    }
    return ConnectionFactories.get(builder.build());
}
 
Example #2
Source File: TestcontainersR2DBCConnectionFactoryTest.java    From testcontainers-java with MIT License 7 votes vote down vote up
@Test
public void reusesUntilConnectionFactoryIsClosed() {
    String url = "r2dbc:tc:postgresql:///db?TC_IMAGE_TAG=10-alpine";
    ConnectionFactory connectionFactory = ConnectionFactories.get(url);

    Integer updated = Flux
        .usingWhen(
            connectionFactory.create(),
            connection -> {
                return Mono
                    .from(connection.createStatement("CREATE TABLE test(id integer PRIMARY KEY)").execute())
                    .thenMany(connection.createStatement("INSERT INTO test(id) VALUES(123)").execute())
                    .flatMap(Result::getRowsUpdated);
            },
            Connection::close
        )
        .blockFirst();

    assertThat(updated).isEqualTo(1);

    Flux<Long> select = Flux
        .usingWhen(
            Flux.defer(connectionFactory::create),
            connection -> {
                return Flux
                    .from(connection.createStatement("SELECT COUNT(*) FROM test").execute())
                    .flatMap(it -> it.map((row, meta) -> (Long) row.get(0)));
            },
            Connection::close
        );

    Long rows = select.blockFirst();

    assertThat(rows).isEqualTo(1);

    close(connectionFactory);

    Assertions
        .assertThatThrownBy(select::blockFirst)
        .isInstanceOf(PostgresqlException.class)
        // relation "X" does not exists
        // https://github.com/postgres/postgres/blob/REL_10_0/src/backend/utils/errcodes.txt#L349
        .returns("42P01", e -> ((PostgresqlException) e).getErrorDetails().getCode());
}
 
Example #3
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 7 votes vote down vote up
@Test
void invalidProgrammatic() {
    assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, true)
        .build()))
        .getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql")
                .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
                .option(USER, "root")
                .option(Option.valueOf("sslMode"), mode.name().toLowerCase())
                .build()))
                .getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #4
Source File: DatasourceConfig.java    From tutorials with MIT License 6 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory(R2DBCConfigurationProperties properties) {
    
    ConnectionFactoryOptions baseOptions = ConnectionFactoryOptions.parse(properties.getUrl());
    Builder ob = ConnectionFactoryOptions.builder().from(baseOptions);
    if ( !StringUtil.isNullOrEmpty(properties.getUser())) {
        ob = ob.option(USER, properties.getUser());
    }

    if ( !StringUtil.isNullOrEmpty(properties.getPassword())) {
        ob = ob.option(PASSWORD, properties.getPassword());
    }
    
    ConnectionFactory cf = ConnectionFactories.get(ob.build());
    return cf;
}
 
Example #5
Source File: TestcontainersR2DBCConnectionFactory.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Override
public Publisher<? extends Connection> create() {
    return new ConnectionPublisher(
        () -> {
            if (future == null) {
                synchronized (this) {
                    if (future == null) {
                        future = CompletableFuture.supplyAsync(() -> {
                            R2DBCDatabaseContainer container = containerProvider.createContainer(options);
                            container.start();
                            return container;
                        }, EXECUTOR);
                    }
                }
            }
            return future.thenApply(it -> {
                return ConnectionFactories.find(
                    it.configure(options)
                );
            });
        }
    );
}
 
Example #6
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidServerPreparing() {
    assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, NotPredicate.class.getTypeName())
        .build()));

    assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, NotPredicate.class.getPackage() + "NonePredicate")
        .build()));
}
 
Example #7
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidUrl() {
    assertThat(assertThrows(
        IllegalArgumentException.class,
        () -> ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306?" +
            "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8"))).getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(
                IllegalArgumentException.class,
                () -> ConnectionFactories.get("r2dbc:mysql://root@localhost:3306?" +
                    "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8") +
                    "&sslMode=" + mode.name().toLowerCase())).getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #8
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void validUrl() throws UnsupportedEncodingException {
    assertThat(ConnectionFactories.get("r2dbc:mysql://root@localhost:3306")).isExactlyInstanceOf(MySqlConnectionFactory.class);
    assertThat(ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306")).isExactlyInstanceOf(MySqlConnectionFactory.class);
    assertThat(ConnectionFactories.get("r2dbc:mysql://root@localhost:3306?unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8")))
        .isExactlyInstanceOf(MySqlConnectionFactory.class);

    assertThat(ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306?" +
        "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8") +
        "&sslMode=disabled")).isNotNull();

    assertThat(ConnectionFactories.get(
        "r2dbcs:mysql://root:[email protected]:3306/r2dbc?" +
            "zeroDate=use_round&" +
            "sslMode=verify_identity&" +
            "serverPreparing=true" +
            String.format("tlsVersion=%s&", URLEncoder.encode("TLSv1.1,TLSv1.2,TLSv1.3", "UTF-8")) +
            String.format("sslCa=%s&", URLEncoder.encode("/path/to/ca.pem", "UTF-8")) +
            String.format("sslKey=%s&", URLEncoder.encode("/path/to/client-key.pem", "UTF-8")) +
            String.format("sslCert=%s&", URLEncoder.encode("/path/to/client-cert.pem", "UTF-8")) +
            "sslKeyPassword=ssl123456"
    )).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #9
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidServerPreparing() {
    assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, NotPredicate.class.getTypeName())
        .build()));

    assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, NotPredicate.class.getPackage() + "NonePredicate")
        .build()));
}
 
Example #10
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidProgrammatic() {
    assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, true)
        .build()))
        .getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(IllegalArgumentException.class, () -> ConnectionFactories.get(ConnectionFactoryOptions.builder()
                .option(DRIVER, "mysql")
                .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
                .option(USER, "root")
                .option(Option.valueOf("sslMode"), mode.name().toLowerCase())
                .build()))
                .getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #11
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void invalidUrl() {
    assertThat(assertThrows(
        IllegalArgumentException.class,
        () -> ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306?" +
            "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8"))).getMessage())
        .contains("sslMode");

    for (SslMode mode : SslMode.values()) {
        if (mode.startSsl()) {
            assertThat(assertThrows(
                IllegalArgumentException.class,
                () -> ConnectionFactories.get("r2dbc:mysql://root@localhost:3306?" +
                    "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8") +
                    "&sslMode=" + mode.name().toLowerCase())).getMessage())
                .contains("sslMode");
        }
    }
}
 
Example #12
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 6 votes vote down vote up
@Test
void validUrl() throws UnsupportedEncodingException {
    assertThat(ConnectionFactories.get("r2dbc:mysql://root@localhost:3306")).isExactlyInstanceOf(MySqlConnectionFactory.class);
    assertThat(ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306")).isExactlyInstanceOf(MySqlConnectionFactory.class);
    assertThat(ConnectionFactories.get("r2dbc:mysql://root@localhost:3306?unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8")))
        .isExactlyInstanceOf(MySqlConnectionFactory.class);

    assertThat(ConnectionFactories.get("r2dbcs:mysql://root@localhost:3306?" +
        "unixSocket=" + URLEncoder.encode("/path/to/mysql.sock", "UTF-8") +
        "&sslMode=disabled")).isNotNull();

    assertThat(ConnectionFactories.get(
        "r2dbcs:mysql://root:[email protected]:3306/r2dbc?" +
            "zeroDate=use_round&" +
            "sslMode=verify_identity&" +
            "serverPreparing=true" +
            String.format("tlsVersion=%s&", URLEncoder.encode("TLSv1.1,TLSv1.2,TLSv1.3", "UTF-8")) +
            String.format("sslCa=%s&", URLEncoder.encode("/path/to/ca.pem", "UTF-8")) +
            String.format("sslKey=%s&", URLEncoder.encode("/path/to/client-key.pem", "UTF-8")) +
            String.format("sslCert=%s&", URLEncoder.encode("/path/to/client-cert.pem", "UTF-8")) +
            "sslKeyPassword=ssl123456"
    )).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #13
Source File: SpringDataR2dbcApp.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
@Bean
public static ConnectionFactory spannerConnectionFactory() {
  ConnectionFactory connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
      .option(Option.valueOf("project"), GCP_PROJECT)
      .option(DRIVER, DRIVER_NAME)
      .option(INSTANCE, SPANNER_INSTANCE)
      .option(DATABASE, SPANNER_DATABASE)
      .build());

  return connectionFactory;
}
 
Example #14
Source File: BookExampleApp.java    From cloud-spanner-r2dbc with Apache License 2.0 5 votes vote down vote up
/**
 * Constructor.
 *
 * @param sampleInstance the sample instance to use.
 * @param sampleDatabase the sample database to use.
 * @param sampleProjectId the sample project to use.
 */
public BookExampleApp(String sampleInstance, String sampleDatabase,
    String sampleProjectId) {
  this.connectionFactory = ConnectionFactories.get(ConnectionFactoryOptions.builder()
      .option(Option.valueOf("project"), sampleProjectId)
      .option(DRIVER, DRIVER_NAME)
      .option(INSTANCE, sampleInstance)
      .option(DATABASE, sampleDatabase)
      .build());
}
 
Example #15
Source File: R2DBCDatabaseContainerProvider.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Nullable
default ConnectionFactoryMetadata getMetadata(ConnectionFactoryOptions options) {
    ConnectionFactoryOptions.Builder builder = options.mutate();
    if (!options.hasOption(ConnectionFactoryOptions.HOST)) {
        builder.option(ConnectionFactoryOptions.HOST, "localhost");
    }
    if (!options.hasOption(ConnectionFactoryOptions.PORT)) {
        builder.option(ConnectionFactoryOptions.PORT, 65535);
    }

    ConnectionFactory connectionFactory = ConnectionFactories.find(builder.build());
    return connectionFactory != null ? connectionFactory.getMetadata() : null;
}
 
Example #16
Source File: AbstractR2DBCDatabaseContainerTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public final void testGetOptions() {
    try (T container = createContainer()) {
        container.start();

        ConnectionFactory connectionFactory = ConnectionFactories.get(getOptions(container));
        runTestQuery(connectionFactory);
    }
}
 
Example #17
Source File: TestcontainersR2DBCConnectionFactoryTest.java    From testcontainers-java with MIT License 5 votes vote down vote up
@Test
public void failsOnUnknownProvider() {
    String nonExistingProvider = UUID.randomUUID().toString();
    Assertions
        .assertThatThrownBy(() -> {
            ConnectionFactories.get(String.format("r2dbc:tc:%s:///db", nonExistingProvider));
        })
        .hasMessageContaining("Missing provider")
        .hasMessageContaining(nonExistingProvider);
}
 
Example #18
Source File: R2dbcConfig.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Bean
public ConnectionFactory connectionFactory() {
    return ConnectionFactories.get(ConnectionFactoryOptions.builder()
            .option(DRIVER,"pool")
            .option(PROTOCOL,"postgresql")
            .option(HOST, host)
            .option(PORT, port)
            .option(USER, username)
            .option(PASSWORD, password)
            .option(DATABASE, name)
            .build());
}
 
Example #19
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void validProgrammatic() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(PORT, 3307)
        .option(USER, "root")
        .option(PASSWORD, "123456")
        .option(SSL, true)
        .option(CONNECT_TIMEOUT, Duration.ofSeconds(3))
        .option(DATABASE, "r2dbc")
        .option(Option.valueOf("zeroDate"), "use_round")
        .option(Option.valueOf("sslMode"), "verify_identity")
        .option(Option.valueOf("tlsVersion"), "TLSv1.2,TLSv1.3")
        .option(Option.valueOf("sslCa"), "/path/to/ca.pem")
        .option(Option.valueOf("sslKey"), "/path/to/client-key.pem")
        .option(Option.valueOf("sslCert"), "/path/to/client-cert.pem")
        .option(Option.valueOf("sslKeyPassword"), "ssl123456")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #20
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void serverPreparing() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, AllTruePredicate.class.getTypeName())
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, "true")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, "false")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, AllTruePredicate.INSTANCE)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #21
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void serverPreparing() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, AllTruePredicate.class.getTypeName())
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, "true")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, "false")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, AllTruePredicate.INSTANCE)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(USE_SERVER_PREPARE_STATEMENT, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #22
Source File: MySqlConnectionFactoryProviderTest.java    From r2dbc-mysql with Apache License 2.0 4 votes vote down vote up
@Test
void validProgrammatic() {
    ConnectionFactoryOptions options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(USER, "root")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(SSL, false)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(Option.valueOf("unixSocket"), "/path/to/mysql.sock")
        .option(USER, "root")
        .option(Option.valueOf("sslMode"), "disabled")
        .option(SSL, true)
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);

    options = ConnectionFactoryOptions.builder()
        .option(DRIVER, "mysql")
        .option(HOST, "127.0.0.1")
        .option(PORT, 3307)
        .option(USER, "root")
        .option(PASSWORD, "123456")
        .option(SSL, true)
        .option(CONNECT_TIMEOUT, Duration.ofSeconds(3))
        .option(DATABASE, "r2dbc")
        .option(Option.valueOf("zeroDate"), "use_round")
        .option(Option.valueOf("sslMode"), "verify_identity")
        .option(Option.valueOf("tlsVersion"), "TLSv1.2,TLSv1.3")
        .option(Option.valueOf("sslCa"), "/path/to/ca.pem")
        .option(Option.valueOf("sslKey"), "/path/to/client-key.pem")
        .option(Option.valueOf("sslCert"), "/path/to/client-cert.pem")
        .option(Option.valueOf("sslKeyPassword"), "ssl123456")
        .build();

    assertThat(ConnectionFactories.get(options)).isExactlyInstanceOf(MySqlConnectionFactory.class);
}
 
Example #23
Source File: AbstractR2DBCDatabaseContainerTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
@Test
public final void testUrlSupport() {
    ConnectionFactory connectionFactory = ConnectionFactories.get(createR2DBCUrl());
    runTestQuery(connectionFactory);
}
 
Example #24
Source File: AbstractR2DBCDatabaseContainerTest.java    From testcontainers-java with MIT License 4 votes vote down vote up
@Test
public final void testGetMetadata() {
    ConnectionFactory connectionFactory = ConnectionFactories.get(createR2DBCUrl());
    ConnectionFactoryMetadata metadata = connectionFactory.getMetadata();
    assertThat(metadata).isNotNull();
}