Search in sources :

Example 11 with DriverExecutionProfile

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

the class TypeSafeDriverConfigOverrideDefaultsTest method should_handle_profiles.

@Test
public void should_handle_profiles() {
    // Given
    TypesafeDriverConfig config = config("datastax-java-driver.profiles.profile1.basic.request.consistency = TWO\n" + "datastax-java-driver.profiles.profile2.basic.request.timeout = 5 seconds");
    DriverExecutionProfile profile1 = config.getProfile("profile1");
    DriverExecutionProfile profile2 = config.getProfile("profile2");
    DriverExecutionProfile derivedProfile21 = profile2.withDuration(DefaultDriverOption.REQUEST_TIMEOUT, Duration.ofSeconds(10));
    DriverExecutionProfile derivedProfile22 = profile2.withString(DefaultDriverOption.REQUEST_CONSISTENCY, "QUORUM");
    assertThat(profile1.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("TWO");
    assertThat(profile2.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// inherited from default profile in reference.conf
    "LOCAL_ONE");
    assertThat(derivedProfile21.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// inherited from default profile in reference.conf
    "LOCAL_ONE");
    assertThat(derivedProfile22.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo(// overridden programmatically
    "QUORUM");
    // When
    config.overrideDefaults(ImmutableMap.of(DefaultDriverOption.REQUEST_CONSISTENCY, "LOCAL_QUORUM"));
    // Then
    // Unaffected because it was set manually in application.conf:
    assertThat(profile1.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("TWO");
    // Affected because it was using the default from reference.conf:
    assertThat(profile2.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("LOCAL_QUORUM");
    // Same:
    assertThat(derivedProfile21.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("LOCAL_QUORUM");
    // Unaffected because it was overridden programmatically:
    assertThat(derivedProfile22.getString(DefaultDriverOption.REQUEST_CONSISTENCY)).isEqualTo("QUORUM");
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test)

Example 12 with DriverExecutionProfile

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

the class MockedDriverContextFactory method defaultDriverContext.

public static DefaultDriverContext defaultDriverContext(Optional<DriverExecutionProfile> profileOption) {
    /* If the caller provided a profile use that, otherwise make a new one */
    final DriverExecutionProfile profile = profileOption.orElseGet(() -> {
        DriverExecutionProfile blankProfile = mock(DriverExecutionProfile.class);
        when(blankProfile.getString(DefaultDriverOption.PROTOCOL_COMPRESSION, "none")).thenReturn("none");
        when(blankProfile.getDuration(DefaultDriverOption.METRICS_NODE_EXPIRE_AFTER)).thenReturn(Duration.ofMinutes(5));
        when(blankProfile.isDefined(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn(true);
        when(blankProfile.getString(DefaultDriverOption.METRICS_FACTORY_CLASS)).thenReturn("DefaultMetricsFactory");
        return blankProfile;
    });
    /* Setup machinery to connect the input DriverExecutionProfile to the config loader */
    final DriverConfig driverConfig = mock(DriverConfig.class);
    final DriverConfigLoader configLoader = mock(DriverConfigLoader.class);
    when(configLoader.getInitialConfig()).thenReturn(driverConfig);
    when(driverConfig.getDefaultProfile()).thenReturn(profile);
    ProgrammaticArguments args = ProgrammaticArguments.builder().withNodeStateListener(mock(NodeStateListener.class)).withSchemaChangeListener(mock(SchemaChangeListener.class)).withRequestTracker(mock(RequestTracker.class)).withLocalDatacenters(Maps.newHashMap()).withNodeDistanceEvaluators(Maps.newHashMap()).build();
    return new DefaultDriverContext(configLoader, args);
}
Also used : SchemaChangeListener(com.datastax.oss.driver.api.core.metadata.schema.SchemaChangeListener) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) DriverConfig(com.datastax.oss.driver.api.core.config.DriverConfig) DriverConfigLoader(com.datastax.oss.driver.api.core.config.DriverConfigLoader) ProgrammaticArguments(com.datastax.oss.driver.api.core.session.ProgrammaticArguments)

Example 13 with DriverExecutionProfile

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

the class MapBasedDriverConfigLoaderTest method should_fill_default_profile_like_reference_file.

/**
 * Checks that, if we ask to pre-fill the default profile, then we get the same set of options as
 * the built-in reference.conf.
 */
@Test
public void should_fill_default_profile_like_reference_file() {
    OptionsMap optionsMap = OptionsMap.driverDefaults();
    DriverExecutionProfile mapBasedConfig = DriverConfigLoader.fromMap(optionsMap).getInitialConfig().getDefaultProfile();
    DriverExecutionProfile fileBasedConfig = new DefaultDriverConfigLoader(() -> {
        // Only load reference.conf since we are focusing on driver defaults
        ConfigFactory.invalidateCaches();
        return defaultReference().getConfig(DefaultDriverConfigLoader.DEFAULT_ROOT_PATH);
    }).getInitialConfig().getDefaultProfile();
    // Make sure we're not missing any options. -1 is for CONFIG_RELOAD_INTERVAL, which is not
    // defined by OptionsMap because it is irrelevant for the map-based config.
    assertThat(mapBasedConfig.entrySet()).hasSize(fileBasedConfig.entrySet().size() - 1);
    for (TypedDriverOption<?> option : TypedDriverOption.builtInValues()) {
        if (option.getRawOption() == DefaultDriverOption.CONFIG_RELOAD_INTERVAL) {
            continue;
        }
        Optional<Object> fileBasedValue = get(fileBasedConfig, option);
        Optional<Object> mapBasedValue = get(mapBasedConfig, option);
        assertThat(mapBasedValue).as("Wrong value for %s in OptionsMap", option.getRawOption()).isEqualTo(fileBasedValue);
    }
}
Also used : OptionsMap(com.datastax.oss.driver.api.core.config.OptionsMap) DefaultDriverConfigLoader(com.datastax.oss.driver.internal.core.config.typesafe.DefaultDriverConfigLoader) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test)

Example 14 with DriverExecutionProfile

use of com.datastax.oss.driver.api.core.config.DriverExecutionProfile 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 15 with DriverExecutionProfile

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

the class TypesafeDriverConfigTest method should_create_derived_profile_with_string_map.

@Test
public void should_create_derived_profile_with_string_map() {
    TypesafeDriverConfig config = parse("int1 = 42");
    Map<String, String> authThingMap = new HashMap<>();
    authThingMap.put("auth_thing_one", "one");
    authThingMap.put("auth_thing_two", "two");
    authThingMap.put("auth_thing_three", "three");
    DriverExecutionProfile base = config.getDefaultProfile();
    DriverExecutionProfile mapBase = base.withStringMap(MockOptions.AUTH_PROVIDER, authThingMap);
    Map<String, String> fetchedMap = mapBase.getStringMap(MockOptions.AUTH_PROVIDER);
    assertThat(fetchedMap).isEqualTo(authThingMap);
}
Also used : HashMap(java.util.HashMap) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) Test(org.junit.Test)

Aggregations

DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)140 Test (org.junit.Test)81 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)29 DriverConfig (com.datastax.oss.driver.api.core.config.DriverConfig)20 CqlSession (com.datastax.oss.driver.api.core.CqlSession)19 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)17 Node (com.datastax.oss.driver.api.core.metadata.Node)14 ByteBuffer (java.nio.ByteBuffer)13 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)12 Duration (java.time.Duration)11 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)10 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)10 Row (com.datastax.oss.driver.api.core.cql.Row)9 Test (org.junit.jupiter.api.Test)9 LoggerTest (com.datastax.oss.driver.internal.core.util.LoggerTest)8 DefaultNodeMetric (com.datastax.oss.driver.api.core.metrics.DefaultNodeMetric)7 NodeMetric (com.datastax.oss.driver.api.core.metrics.NodeMetric)7 Message (com.datastax.oss.protocol.internal.Message)7 DriverTimeoutException (com.datastax.oss.driver.api.core.DriverTimeoutException)6 DriverConfigLoader (com.datastax.oss.driver.api.core.config.DriverConfigLoader)6