use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext 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"));
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class GraphSupportCheckerTest method should_pickup_graph_protocol_and_parse_from_string_config.
@Test
@UseDataProvider("graphProtocolStringsAndDseVersions")
public void should_pickup_graph_protocol_and_parse_from_string_config(String stringConfig, Version dseVersion) {
GraphStatement graphStatement = mock(GraphStatement.class);
DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
when(executionProfile.isDefined(DseDriverOption.GRAPH_SUB_PROTOCOL)).thenReturn(Boolean.TRUE);
when(executionProfile.getString(eq(DseDriverOption.GRAPH_SUB_PROTOCOL))).thenReturn(stringConfig);
DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, dseVersion);
GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, context);
assertThat(inferredProtocol.toInternalCode()).isEqualTo(stringConfig);
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class GraphSupportCheckerTest method should_use_correct_default_protocol_when_parsing.
@Test
@UseDataProvider("dseVersions6")
public void should_use_correct_default_protocol_when_parsing(Version dseVersion) {
GraphStatement graphStatement = mock(GraphStatement.class);
DriverExecutionProfile executionProfile = mock(DriverExecutionProfile.class);
DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, dseVersion);
GraphProtocol inferredProtocol = new GraphSupportChecker().inferGraphProtocol(graphStatement, executionProfile, context);
// For DSE 6.8 and newer, the default should be GraphSON binary
// for DSE older than 6.8, the default should be GraphSON2
assertThat(inferredProtocol).isEqualTo((dseVersion.compareTo(Version.parse("6.8.0")) < 0) ? GraphProtocol.GRAPHSON_2_0 : GraphProtocol.GRAPH_BINARY_1_0);
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class GraphSupportCheckerTest method should_determine_default_graph_protocol_from_dse_version_with_null_versions.
@Test
@UseDataProvider("dseVersionsAndGraphProtocols")
public void should_determine_default_graph_protocol_from_dse_version_with_null_versions(Version[] dseVersions, GraphProtocol expectedProtocol) {
// mock up the metadata for the context
// using 'false' here will treat null test Versions as explicit NULL info for DSE_VERSION
DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), false, dseVersions);
GraphProtocol graphProtocol = new GraphSupportChecker().getDefaultGraphProtocol(context);
assertThat(graphProtocol).isEqualTo(expectedProtocol);
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method setUp.
@Before
public void setUp() {
DefaultDriverContext context = mock(DefaultDriverContext.class);
graphSupportChecker = mock(GraphSupportChecker.class);
asyncProcessor = Mockito.spy(new GraphRequestAsyncProcessor(context, graphSupportChecker));
}
Aggregations