Search in sources :

Example 6 with OptionsMap

use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.

the class MapBasedDriverConfigLoaderTest method should_reflect_changes_in_real_time.

@Test
public void should_reflect_changes_in_real_time() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 1);
    DriverConfigLoader loader = DriverConfigLoader.fromMap(source);
    DriverConfig config = loader.getInitialConfig();
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(1);
    source.put(MockTypedOptions.INT1, 2);
    assertThat(config.getDefaultProfile().getInt(MockOptions.INT1)).isEqualTo(2);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) Test(org.junit.Test)

Example 7 with OptionsMap

use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.

the class MapBasedDriverConfigTest method should_create_derived_profile_with_new_option.

@Test
public void should_create_derived_profile_with_new_option() {
    OptionsMap source = new OptionsMap();
    source.put(MockTypedOptions.INT1, 42);
    DriverConfig config = DriverConfigLoader.fromMap(source).getInitialConfig();
    DriverExecutionProfile base = config.getDefaultProfile();
    DriverExecutionProfile derived = base.withInt(MockOptions.INT2, 43);
    assertThat(base.isDefined(MockOptions.INT2)).isFalse();
    assertThat(derived.isDefined(MockOptions.INT2)).isTrue();
    assertThat(derived.getInt(MockOptions.INT2)).isEqualTo(43);
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) Test(org.junit.Test)

Example 8 with OptionsMap

use of com.datastax.oss.driver.api.core.config.OptionsMap in project spring-boot by spring-projects.

the class CassandraPropertiesTests method defaultValuesInManualMetadataAreConsistent.

/**
 * To let a configuration file override values, {@link CassandraProperties} can't have
 * any default hardcoded. This test makes sure that the default that we moved to
 * manual meta-data are accurate.
 */
@Test
void defaultValuesInManualMetadataAreConsistent() {
    OptionsMap driverDefaults = OptionsMap.driverDefaults();
    // spring.data.cassandra.connection.connection-timeout
    assertThat(driverDefaults.get(TypedDriverOption.CONNECTION_CONNECT_TIMEOUT)).isEqualTo(Duration.ofSeconds(5));
    // spring.data.cassandra.connection.init-query-timeout
    assertThat(driverDefaults.get(TypedDriverOption.CONNECTION_INIT_QUERY_TIMEOUT)).isEqualTo(Duration.ofSeconds(5));
    // spring.data.cassandra.request.timeout
    assertThat(driverDefaults.get(TypedDriverOption.REQUEST_TIMEOUT)).isEqualTo(Duration.ofSeconds(2));
    // spring.data.cassandra.request.page-size
    assertThat(driverDefaults.get(TypedDriverOption.REQUEST_PAGE_SIZE)).isEqualTo(5000);
    // spring.data.cassandra.request.throttler.type
    assertThat(driverDefaults.get(TypedDriverOption.REQUEST_THROTTLER_CLASS)).isEqualTo(// "none"
    "PassThroughRequestThrottler");
    // spring.data.cassandra.pool.heartbeat-interval
    assertThat(driverDefaults.get(TypedDriverOption.HEARTBEAT_INTERVAL)).isEqualTo(Duration.ofSeconds(30));
    // spring.data.cassandra.pool.idle-timeout
    assertThat(driverDefaults.get(TypedDriverOption.HEARTBEAT_TIMEOUT)).isEqualTo(Duration.ofSeconds(5));
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) Test(org.junit.jupiter.api.Test)

Example 9 with OptionsMap

use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.

the class CrossDatacenterFailover method connect.

/**
 * Initiates a connection to the cluster.
 */
private void connect() {
    // For simplicity, this example uses a 100% in-memory configuration loader, but the same
    // configuration can be achieved with the more traditional file-based approach.
    // Simply put the below snippet in your application.conf file to get the same config:
    /*
    datastax-java-driver {
      basic.contact-points = [ "127.0.0.1:9042" ]
      basic.load-balancing-policy.local-datacenter = "dc1"
      basic.request.consistency = LOCAL_QUORUM
      profiles {
        remote {
          basic.load-balancing-policy.local-datacenter = "dc2"
          basic.request.consistency = LOCAL_ONE
        }
      }
    }
    */
    OptionsMap options = OptionsMap.driverDefaults();
    // set the datacenter to dc1 in the default profile; this makes dc1 the local datacenter
    options.put(TypedDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, "dc1");
    // set the datacenter to dc2 in the "remote" profile
    options.put("remote", TypedDriverOption.LOAD_BALANCING_LOCAL_DATACENTER, "dc2");
    // make sure to provide a contact point belonging to dc1, not dc2!
    options.put(TypedDriverOption.CONTACT_POINTS, Collections.singletonList("127.0.0.1:9042"));
    // in this example, the default consistency level is LOCAL_QUORUM
    options.put(TypedDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM");
    // but when failing over, the consistency level will be automatically downgraded to LOCAL_ONE
    options.put("remote", TypedDriverOption.REQUEST_CONSISTENCY, "LOCAL_ONE");
    session = CqlSession.builder().withConfigLoader(DriverConfigLoader.fromMap(options)).build();
    System.out.println("Connected to cluster with session: " + session.getName());
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap)

Example 10 with OptionsMap

use of com.datastax.oss.driver.api.core.config.OptionsMap in project java-driver by datastax.

the class MapBasedConfigLoaderIT method should_resize_pool_when_config_changes.

/**
 * Checks that runtime changes to the pool size are reflected in the driver. This is a special
 * case because unlike other options, the driver does not re-read the option at regular intervals;
 * instead, it relies on the {@link ConfigChangeEvent} being fired.
 */
@Test
public void should_resize_pool_when_config_changes() {
    OptionsMap optionsMap = OptionsMap.driverDefaults();
    try (CqlSession session = CqlSession.builder().addContactEndPoints(SIMULACRON_RULE.getContactPoints()).withLocalDatacenter("dc1").withConfigLoader(DriverConfigLoader.fromMap(optionsMap)).build()) {
        Node node = session.getMetadata().getNodes().values().iterator().next();
        // control connection + pool (default 1)
        assertThat(node.getOpenConnections()).isEqualTo(2);
        optionsMap.put(TypedDriverOption.CONNECTION_POOL_LOCAL_SIZE, 2);
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> node.getOpenConnections() == 3);
    }
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) Node(com.datastax.oss.driver.api.core.metadata.Node) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Test(org.junit.Test)

Aggregations

OptionsMap (com.datastax.oss.driver.api.core.config.OptionsMap)13 Test (org.junit.Test)10 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)7 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)2 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)2 DefaultDriverConfigLoader (com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader)2 AllNodesFailedException (com.datastax.oss.driver.api.core.AllNodesFailedException)1 ResultSet (com.datastax.oss.driver.api.core.cql.ResultSet)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 Before (org.junit.Before)1 Test (org.junit.jupiter.api.Test)1