use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method should_complete_single_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(false);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (GraphRequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
DefaultDriverContext context = harness.getContext();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
GraphBinaryModule graphBinaryModule = createGraphBinaryModule(context);
when(asyncProcessor.getGraphBinaryModule()).thenReturn(graphBinaryModule);
ReactiveGraphResultSet publisher = new ReactiveGraphRequestProcessor(asyncProcessor).process(graphStatement, session, context, "test");
Flowable<ReactiveGraphNode> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
// emulate single page
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, true)));
List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(10);
checkResultSet(rows);
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).hasSize(1).containsExactly(rows.get(0).getExecutionInfo());
}
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class ReactiveGraphRequestProcessorTest method should_complete_multi_page_result.
@Test
@UseDataProvider(value = "allDseProtocolVersionsAndSupportedGraphProtocols", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version, GraphProtocol graphProtocol) throws IOException {
when(graphSupportChecker.isPagingEnabled(any(), any())).thenReturn(true);
when(graphSupportChecker.inferGraphProtocol(any(), any(), any())).thenReturn(graphProtocol);
GraphRequestHandlerTestHarness.Builder builder = GraphRequestHandlerTestHarness.builder().withProtocolVersion(version);
PoolBehavior node1Behavior = builder.customBehavior(node1);
try (GraphRequestHandlerTestHarness harness = builder.build()) {
DefaultSession session = harness.getSession();
DefaultDriverContext context = harness.getContext();
GraphStatement<?> graphStatement = ScriptGraphStatement.newInstance("g.V()");
GraphBinaryModule graphBinaryModule = createGraphBinaryModule(context);
when(asyncProcessor.getGraphBinaryModule()).thenReturn(graphBinaryModule);
ReactiveGraphResultSet publisher = new ReactiveGraphRequestProcessor(asyncProcessor).process(graphStatement, session, context, "test");
Flowable<ReactiveGraphNode> rowsPublisher = Flowable.fromPublisher(publisher).cache();
rowsPublisher.subscribe();
// emulate page 1
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 1, false)));
// emulate page 2
node1Behavior.setResponseSuccess(defaultDseFrameOf(tenGraphRows(graphProtocol, graphBinaryModule, 2, true)));
List<ReactiveGraphNode> rows = rowsPublisher.toList().blockingGet();
assertThat(rows).hasSize(20);
checkResultSet(rows);
Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
assertThat(execInfosFlowable.toList().blockingGet()).hasSize(2).containsExactly(rows.get(0).getExecutionInfo(), rows.get(10).getExecutionInfo());
}
}
use of com.datastax.oss.driver.internal.core.context.DefaultDriverContext in project java-driver by datastax.
the class InsightsClientTest method mockDefaultDriverContext.
private DefaultDriverContext mockDefaultDriverContext() throws UnknownHostException {
DefaultDriverContext context = mock(DefaultDriverContext.class);
mockConnectionPools(context);
MetadataManager manager = mock(MetadataManager.class);
when(context.getMetadataManager()).thenReturn(manager);
Metadata metadata = mock(Metadata.class);
when(manager.getMetadata()).thenReturn(metadata);
Node node = mock(Node.class);
when(node.getExtras()).thenReturn(ImmutableMap.of(DseNodeProperties.DSE_VERSION, Objects.requireNonNull(Version.parse("6.0.5"))));
when(metadata.getNodes()).thenReturn(ImmutableMap.of(UUID.randomUUID(), node));
DriverExecutionProfile defaultExecutionProfile = mockDefaultExecutionProfile();
DriverExecutionProfile nonDefaultExecutionProfile = mockNonDefaultRequestTimeoutExecutionProfile();
Map<String, String> startupOptions = new HashMap<>();
startupOptions.put(StartupOptionsBuilder.CLIENT_ID_KEY, "client-id");
startupOptions.put(StartupOptionsBuilder.APPLICATION_VERSION_KEY, "1.0.0");
startupOptions.put(StartupOptionsBuilder.APPLICATION_NAME_KEY, "app-name");
startupOptions.put(StartupOptionsBuilder.DRIVER_VERSION_KEY, "2.x");
startupOptions.put(StartupOptionsBuilder.DRIVER_NAME_KEY, "DataStax Enterprise Java Driver");
when(context.getStartupOptions()).thenReturn(startupOptions);
when(context.getProtocolVersion()).thenReturn(DSE_V2);
DefaultNode contactPoint = mock(DefaultNode.class);
EndPoint contactEndPoint = mock(EndPoint.class);
when(contactEndPoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 9999));
when(contactPoint.getEndPoint()).thenReturn(contactEndPoint);
when(manager.getContactPoints()).thenReturn(ImmutableSet.of(contactPoint));
DriverConfig driverConfig = mock(DriverConfig.class);
when(context.getConfig()).thenReturn(driverConfig);
Map<String, DriverExecutionProfile> profiles = ImmutableMap.of("default", defaultExecutionProfile, "non-default", nonDefaultExecutionProfile);
Mockito.<Map<String, ? extends DriverExecutionProfile>>when(driverConfig.getProfiles()).thenReturn(profiles);
when(driverConfig.getDefaultProfile()).thenReturn(defaultExecutionProfile);
ControlConnection controlConnection = mock(ControlConnection.class);
DriverChannel channel = mock(DriverChannel.class);
EndPoint controlConnectionEndpoint = mock(EndPoint.class);
when(controlConnectionEndpoint.resolve()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
when(channel.getEndPoint()).thenReturn(controlConnectionEndpoint);
when(channel.localAddress()).thenReturn(new InetSocketAddress("127.0.0.1", 10));
when(controlConnection.channel()).thenReturn(channel);
when(context.getControlConnection()).thenReturn(controlConnection);
return context;
}
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.
@Test
@UseDataProvider("dseVersionsAndGraphProtocols")
public void should_determine_default_graph_protocol_from_dse_version(Version[] dseVersions, GraphProtocol expectedProtocol) {
// mock up the metadata for the context
// using 'true' here will treat null test Versions as no DSE_VERSION info in the metadata
DefaultDriverContext context = mockNodesInMetadataWithVersions(mock(DefaultDriverContext.class), true, 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 GraphNodeTest method setup.
@Before
public void setup() {
DefaultDriverContext dseDriverContext = mock(DefaultDriverContext.class);
when(dseDriverContext.getCodecRegistry()).thenReturn(CodecRegistry.DEFAULT);
when(dseDriverContext.getProtocolVersion()).thenReturn(DseProtocolVersion.DSE_V2);
TypeSerializerRegistry registry = GraphBinaryModule.createDseTypeSerializerRegistry(dseDriverContext);
graphBinaryModule = new GraphBinaryModule(new GraphBinaryReader(registry), new GraphBinaryWriter(registry));
}
Aggregations