Search in sources :

Example 1 with SpeculativeExecutionInfo

use of com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo in project java-driver by datastax.

the class ExecutionProfilesInfoFinderTest method should_include_info_about_default_profile.

@Test
public void should_include_info_about_default_profile() {
    // given
    DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
    Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile);
    InternalDriverContext context = mockDriverContextWithProfiles(defaultExecutionProfile, profiles);
    // when
    Map<String, SpecificExecutionProfile> executionProfilesInfo = new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context);
    // then
    assertThat(executionProfilesInfo).isEqualTo(ImmutableMap.of("default", new SpecificExecutionProfile(100, new LoadBalancingInfo("LoadBalancingPolicyImpl", ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), DEFAULT_LOAD_BALANCING_PACKAGE), new SpeculativeExecutionInfo("SpeculativeExecutionImpl", ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), "LOCAL_ONE", "SERIAL", ImmutableMap.of("source", "src-graph"))));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo) ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo) Test(org.junit.Test)

Example 2 with SpeculativeExecutionInfo

use of com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo in project java-driver by datastax.

the class InsightsClientTest method should_construct_json_event_startup_message.

@Test
public void should_construct_json_event_startup_message() throws IOException {
    // given
    DefaultDriverContext context = mockDefaultDriverContext();
    PlatformInfoFinder platformInfoFinder = mock(PlatformInfoFinder.class);
    OS os = new OS("linux", "1.2", "x64");
    CPUS cpus = new CPUS(8, "intel i7");
    Map<String, RuntimeAndCompileTimeVersions> javaDeps = ImmutableMap.of("version", new RuntimeAndCompileTimeVersions("1.8.0", "1.8.0", false));
    Map<String, Map<String, RuntimeAndCompileTimeVersions>> runtimeInfo = ImmutableMap.of("java", javaDeps);
    InsightsPlatformInfo insightsPlatformInfo = new InsightsPlatformInfo(os, cpus, runtimeInfo);
    when(platformInfoFinder.getInsightsPlatformInfo()).thenReturn(insightsPlatformInfo);
    ConfigAntiPatternsFinder configAntiPatternsFinder = mock(ConfigAntiPatternsFinder.class);
    when(configAntiPatternsFinder.findAntiPatterns(any(DefaultDriverContext.class))).thenReturn(ImmutableMap.of("contactPointsMultipleDCs", "Contact points contain hosts from multiple data centers"));
    DataCentersFinder dataCentersFinder = mock(DataCentersFinder.class);
    when(dataCentersFinder.getDataCenters(any(DefaultDriverContext.class))).thenReturn(Sets.newHashSet("dc1", "dc2"));
    ReconnectionPolicyInfoFinder reconnectionPolicyInfoFinder = mock(ReconnectionPolicyInfoFinder.class);
    when(reconnectionPolicyInfoFinder.getReconnectionPolicyInfo(any(), any())).thenReturn(new ReconnectionPolicyInfo("reconnection-policy-a", ImmutableMap.of("opt-a", 1), "com.datastax.dse"));
    InsightsClient insightsClient = new InsightsClient(context, MOCK_TIME_SUPPLIER, INSIGHTS_CONFIGURATION, platformInfoFinder, reconnectionPolicyInfoFinder, new ExecutionProfilesInfoFinder(), configAntiPatternsFinder, dataCentersFinder, EMPTY_STACK_TRACE);
    // when
    String startupMessage = insightsClient.createStartupMessage();
    Insight<InsightsStartupData> insight = new ObjectMapper().readValue(startupMessage, new TypeReference<Insight<InsightsStartupData>>() {
    });
    // then
    assertThat(insight.getMetadata()).isEqualTo(new InsightMetadata("driver.startup", 1L, ImmutableMap.of("language", "java"), InsightType.EVENT, "v1"));
    InsightsStartupData insightData = insight.getInsightData();
    assertThat(insightData.getClientId()).isEqualTo("client-id");
    assertThat(insightData.getSessionId()).isNotNull();
    assertThat(insightData.getDriverName()).isEqualTo("DataStax Enterprise Java Driver");
    assertThat(insightData.getDriverVersion()).isNotEmpty();
    assertThat(insightData.getApplicationName()).isEqualTo("app-name");
    assertThat(insightData.getApplicationVersion()).isEqualTo("1.0.0");
    assertThat(insightData.isApplicationNameWasGenerated()).isEqualTo(false);
    assertThat(insightData.getContactPoints()).isEqualTo(ImmutableMap.of("localhost", Collections.singletonList("127.0.0.1:9999")));
    assertThat(insightData.getInitialControlConnection()).isEqualTo("127.0.0.1:10");
    assertThat(insightData.getLocalAddress()).isEqualTo("127.0.0.1");
    assertThat(insightData.getHostName()).isNotEmpty();
    assertThat(insightData.getProtocolVersion()).isEqualTo(DSE_V2.getCode());
    assertThat(insightData.getExecutionProfiles()).isEqualTo(ImmutableMap.of("default", new SpecificExecutionProfile(100, new LoadBalancingInfo("LoadBalancingPolicyImpl", ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), DEFAULT_LOAD_BALANCING_PACKAGE), new SpeculativeExecutionInfo("SpeculativeExecutionImpl", ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), "LOCAL_ONE", "SERIAL", ImmutableMap.of("source", "src-graph")), "non-default", new SpecificExecutionProfile(50, null, null, null, null, null)));
    assertThat(insightData.getPoolSizeByHostDistance()).isEqualTo(new PoolSizeByHostDistance(2, 1, 0));
    assertThat(insightData.getHeartbeatInterval()).isEqualTo(100);
    assertThat(insightData.getCompression()).isEqualTo("none");
    assertThat(insightData.getReconnectionPolicy()).isEqualTo(new ReconnectionPolicyInfo("reconnection-policy-a", ImmutableMap.of("opt-a", 1), "com.datastax.dse"));
    assertThat(insightData.getSsl()).isEqualTo(new SSL(true, false));
    assertThat(insightData.getAuthProvider()).isEqualTo(new AuthProviderType("AuthProviderImpl", DEFAULT_AUTH_PROVIDER_PACKAGE));
    assertThat(insightData.getOtherOptions()).isEqualTo(EMPTY_OBJECT_MAP);
    assertThat(insightData.getPlatformInfo()).isEqualTo(insightsPlatformInfo);
    assertThat(insightData.getConfigAntiPatterns()).isEqualTo(ImmutableMap.of("contactPointsMultipleDCs", "Contact points contain hosts from multiple data centers"));
    assertThat(insightData.getPeriodicStatusInterval()).isEqualTo(300);
    assertThat(insightData.getDataCenters()).isEqualTo(Sets.newHashSet("dc1", "dc2"));
}
Also used : LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) PoolSizeByHostDistance(com.datastax.dse.driver.internal.core.insights.schema.PoolSizeByHostDistance) CPUS(com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.CPUS) InsightsPlatformInfo(com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo) InsightsStartupData(com.datastax.dse.driver.internal.core.insights.schema.InsightsStartupData) ReconnectionPolicyInfo(com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo) Insight(com.datastax.dse.driver.internal.core.insights.schema.Insight) RuntimeAndCompileTimeVersions(com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.RuntimeAndCompileTimeVersions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) OS(com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.OS) AuthProviderType(com.datastax.dse.driver.internal.core.insights.schema.AuthProviderType) SSL(com.datastax.dse.driver.internal.core.insights.schema.SSL) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) Map(java.util.Map) HashMap(java.util.HashMap) ImmutableMap(com.datastax.oss.driver.shaded.guava.common.collect.ImmutableMap) InsightMetadata(com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata) Test(org.junit.Test)

Example 3 with SpeculativeExecutionInfo

use of com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo in project java-driver by datastax.

the class ExecutionProfilesInfoFinder method retainOnlyDifferentFieldsFromSpecificProfile.

private SpecificExecutionProfile retainOnlyDifferentFieldsFromSpecificProfile(SpecificExecutionProfile defaultProfile, SpecificExecutionProfile specificExecutionProfile) {
    Integer readTimeout = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getReadTimeout);
    LoadBalancingInfo loadBalancingInfo = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getLoadBalancing);
    SpeculativeExecutionInfo speculativeExecutionInfo = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getSpeculativeExecution);
    String consistency = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getConsistency);
    String serialConsistency = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getSerialConsistency);
    Map<String, Object> graphOptions = getIfDifferentOrReturnNull(defaultProfile, specificExecutionProfile, SpecificExecutionProfile::getGraphOptions);
    return new SpecificExecutionProfile(readTimeout, loadBalancingInfo, speculativeExecutionInfo, consistency, serialConsistency, graphOptions);
}
Also used : LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo)

Example 4 with SpeculativeExecutionInfo

use of com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo in project java-driver by datastax.

the class ExecutionProfilesInfoFinder method getSpeculativeExecutionInfo.

private SpeculativeExecutionInfo getSpeculativeExecutionInfo(DriverExecutionProfile driverExecutionProfile) {
    Map<String, Object> options = new LinkedHashMap<>();
    putIfExists(options, "maxSpeculativeExecutions", DefaultDriverOption.SPECULATIVE_EXECUTION_MAX, driverExecutionProfile);
    putIfExists(options, "delay", DefaultDriverOption.SPECULATIVE_EXECUTION_DELAY, driverExecutionProfile);
    ClassSettingDetails speculativeExecutionDetails = PackageUtil.getSpeculativeExecutionDetails(driverExecutionProfile.getString(DefaultDriverOption.SPECULATIVE_EXECUTION_POLICY_CLASS));
    return new SpeculativeExecutionInfo(speculativeExecutionDetails.getClassName(), options, speculativeExecutionDetails.getFullPackage());
}
Also used : ClassSettingDetails(com.datastax.dse.driver.internal.core.insights.PackageUtil.ClassSettingDetails) LinkedHashMap(java.util.LinkedHashMap) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo)

Example 5 with SpeculativeExecutionInfo

use of com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo in project java-driver by datastax.

the class ExecutionProfilesInfoFinderTest method should_include_info_about_default_profile_and_only_difference_for_specific_profile.

@Test
@UseDataProvider("executionProfileProvider")
public void should_include_info_about_default_profile_and_only_difference_for_specific_profile(DriverExecutionProfile nonDefaultExecutionProfile, SpecificExecutionProfile expected) {
    // given
    DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
    Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile);
    InternalDriverContext context = mockDriverContextWithProfiles(defaultExecutionProfile, profiles);
    // when
    Map<String, SpecificExecutionProfile> executionProfilesInfo = new ExecutionProfilesInfoFinder().getExecutionProfilesInfo(context);
    // then
    assertThat(executionProfilesInfo).isEqualTo(ImmutableMap.of("default", new SpecificExecutionProfile(100, new LoadBalancingInfo("LoadBalancingPolicyImpl", ImmutableMap.of("localDataCenter", "local-dc", "filterFunction", true), DEFAULT_LOAD_BALANCING_PACKAGE), new SpeculativeExecutionInfo("SpeculativeExecutionImpl", ImmutableMap.of("maxSpeculativeExecutions", 100, "delay", 20), DEFAULT_SPECULATIVE_EXECUTION_PACKAGE), "LOCAL_ONE", "SERIAL", ImmutableMap.of("source", "src-graph")), "non-default", expected));
}
Also used : DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) LoadBalancingInfo(com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo) SpecificExecutionProfile(com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) SpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo) ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo(com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

SpeculativeExecutionInfo (com.datastax.dse.driver.internal.core.insights.schema.SpeculativeExecutionInfo)5 LoadBalancingInfo (com.datastax.dse.driver.internal.core.insights.schema.LoadBalancingInfo)4 SpecificExecutionProfile (com.datastax.dse.driver.internal.core.insights.schema.SpecificExecutionProfile)4 Test (org.junit.Test)3 ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo (com.datastax.dse.driver.internal.core.insights.ExecutionProfileMockUtil.mockNonDefaultSpeculativeExecutionInfo)2 DriverExecutionProfile (com.datastax.oss.driver.api.core.config.DriverExecutionProfile)2 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)2 ClassSettingDetails (com.datastax.dse.driver.internal.core.insights.PackageUtil.ClassSettingDetails)1 AuthProviderType (com.datastax.dse.driver.internal.core.insights.schema.AuthProviderType)1 Insight (com.datastax.dse.driver.internal.core.insights.schema.Insight)1 InsightMetadata (com.datastax.dse.driver.internal.core.insights.schema.InsightMetadata)1 InsightsPlatformInfo (com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo)1 CPUS (com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.CPUS)1 OS (com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.OS)1 RuntimeAndCompileTimeVersions (com.datastax.dse.driver.internal.core.insights.schema.InsightsPlatformInfo.RuntimeAndCompileTimeVersions)1 InsightsStartupData (com.datastax.dse.driver.internal.core.insights.schema.InsightsStartupData)1 PoolSizeByHostDistance (com.datastax.dse.driver.internal.core.insights.schema.PoolSizeByHostDistance)1 ReconnectionPolicyInfo (com.datastax.dse.driver.internal.core.insights.schema.ReconnectionPolicyInfo)1 SSL (com.datastax.dse.driver.internal.core.insights.schema.SSL)1 DefaultDriverContext (com.datastax.oss.driver.internal.core.context.DefaultDriverContext)1