Search in sources :

Example 1 with DefaultSession

use of com.datastax.oss.driver.internal.core.session.DefaultSession in project java-driver by datastax.

the class ChannelSocketOptionsIT method should_report_socket_options.

@Test
public void should_report_socket_options() {
    Session session = SESSION_RULE.session();
    DriverExecutionProfile config = session.getContext().getConfig().getDefaultProfile();
    assertThat(config.getBoolean(SOCKET_TCP_NODELAY)).isTrue();
    assertThat(config.getBoolean(SOCKET_KEEP_ALIVE)).isFalse();
    assertThat(config.getBoolean(SOCKET_REUSE_ADDRESS)).isFalse();
    assertThat(config.getInt(SOCKET_LINGER_INTERVAL)).isEqualTo(10);
    assertThat(config.getInt(SOCKET_RECEIVE_BUFFER_SIZE)).isEqualTo(123456);
    assertThat(config.getInt(SOCKET_SEND_BUFFER_SIZE)).isEqualTo(123456);
    Node node = session.getMetadata().getNodes().values().iterator().next();
    if (session instanceof SessionWrapper) {
        session = ((SessionWrapper) session).getDelegate();
    }
    DriverChannel channel = ((DefaultSession) session).getChannel(node, "test");
    assertThat(channel).isNotNull();
    assertThat(channel.config()).isInstanceOf(SocketChannelConfig.class);
    SocketChannelConfig socketConfig = (SocketChannelConfig) channel.config();
    assertThat(socketConfig.isTcpNoDelay()).isTrue();
    assertThat(socketConfig.isKeepAlive()).isFalse();
    assertThat(socketConfig.isReuseAddress()).isFalse();
    assertThat(socketConfig.getSoLinger()).isEqualTo(10);
    RecvByteBufAllocator allocator = socketConfig.getRecvByteBufAllocator();
    assertThat(allocator).isInstanceOf(FixedRecvByteBufAllocator.class);
    assertThat(allocator.newHandle().guess()).isEqualTo(123456);
// cannot assert around SO_RCVBUF and SO_SNDBUF, such values are just hints
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) FixedRecvByteBufAllocator(io.netty.channel.FixedRecvByteBufAllocator) RecvByteBufAllocator(io.netty.channel.RecvByteBufAllocator) DriverExecutionProfile(com.datastax.oss.driver.api.core.config.DriverExecutionProfile) SocketChannelConfig(io.netty.channel.socket.SocketChannelConfig) Node(com.datastax.oss.driver.api.core.metadata.Node) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Session(com.datastax.oss.driver.api.core.session.Session) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) SessionWrapper(com.datastax.oss.driver.internal.core.session.SessionWrapper) Test(org.junit.Test)

Example 2 with DefaultSession

use of com.datastax.oss.driver.internal.core.session.DefaultSession in project java-driver by datastax.

the class RemovedNodeIT method should_signal_and_destroy_pool_when_node_gets_removed.

@Test
public void should_signal_and_destroy_pool_when_node_gets_removed() {
    RemovalListener removalListener = new RemovalListener();
    try (CqlSession session = SessionUtils.newSession(CCM_RULE, null, removalListener, null, null)) {
        assertThat(session.getMetadata().getTokenMap()).isPresent();
        Set<TokenRange> tokenRanges = session.getMetadata().getTokenMap().get().getTokenRanges();
        assertThat(tokenRanges).hasSize(4);
        CCM_RULE.getCcmBridge().decommission(2);
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> removalListener.removedNode != null);
        Map<Node, ChannelPool> pools = ((DefaultSession) session).getPools();
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> !pools.containsKey(removalListener.removedNode));
        await().pollInterval(500, TimeUnit.MILLISECONDS).atMost(60, TimeUnit.SECONDS).until(() -> session.getMetadata().getTokenMap().get().getTokenRanges().size() == 3);
    }
}
Also used : ChannelPool(com.datastax.oss.driver.internal.core.pool.ChannelPool) Node(com.datastax.oss.driver.api.core.metadata.Node) TokenRange(com.datastax.oss.driver.api.core.metadata.token.TokenRange) CqlSession(com.datastax.oss.driver.api.core.CqlSession) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test)

Example 3 with DefaultSession

use of com.datastax.oss.driver.internal.core.session.DefaultSession 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());
    }
}
Also used : GraphRequestHandlerTestHarness(com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) GraphTestUtils.createGraphBinaryModule(com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule) GraphBinaryModule(com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule) ReactiveGraphNode(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode) DefaultDriverContext(com.datastax.oss.driver.internal.core.context.DefaultDriverContext) ReactiveGraphResultSet(com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 4 with DefaultSession

use of com.datastax.oss.driver.internal.core.session.DefaultSession in project java-driver by datastax.

the class ContinuousCqlRequestReactiveProcessorTest method should_complete_single_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_single_page_result(DseProtocolVersion version) {
    try (RequestHandlerTestHarness harness = continuousHarnessBuilder().withProtocolVersion(version).withResponse(node1, defaultFrameOf(DseTestFixtures.singleDseRow())).build()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
        List<ReactiveRow> rows = Flowable.fromPublisher(publisher).toList().blockingGet();
        assertThat(rows).hasSize(1);
        ReactiveRow row = rows.get(0);
        assertThat(row.getString("message")).isEqualTo("hello, world");
        ExecutionInfo executionInfo = row.getExecutionInfo();
        assertThat(executionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(executionInfo.getErrors()).isEmpty();
        assertThat(executionInfo.getIncomingPayload()).isEmpty();
        assertThat(executionInfo.getPagingState()).isNull();
        assertThat(executionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(executionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(executionInfo.getWarnings()).isEmpty();
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(executionInfo);
        Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
        assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(row.getColumnDefinitions());
        Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
        assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(row.wasApplied());
    }
}
Also used : ContinuousCqlRequestAsyncProcessor(com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) ContinuousReactiveResultSet(com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 5 with DefaultSession

use of com.datastax.oss.driver.internal.core.session.DefaultSession in project java-driver by datastax.

the class ContinuousCqlRequestReactiveProcessorTest method should_complete_multi_page_result.

@Test
@UseDataProvider(value = "allDseProtocolVersions", location = DseTestDataProviders.class)
public void should_complete_multi_page_result(DseProtocolVersion version) {
    RequestHandlerTestHarness.Builder builder = continuousHarnessBuilder().withProtocolVersion(version);
    PoolBehavior node1Behavior = builder.customBehavior(node1);
    try (RequestHandlerTestHarness harness = builder.build()) {
        DefaultSession session = harness.getSession();
        InternalDriverContext context = harness.getContext();
        ContinuousReactiveResultSet publisher = new ContinuousCqlRequestReactiveProcessor(new ContinuousCqlRequestAsyncProcessor()).process(UNDEFINED_IDEMPOTENCE_STATEMENT, session, context, "test");
        Flowable<ReactiveRow> rowsPublisher = Flowable.fromPublisher(publisher).cache();
        rowsPublisher.subscribe();
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(1, false)));
        node1Behavior.setResponseSuccess(defaultFrameOf(DseTestFixtures.tenDseRows(2, true)));
        List<ReactiveRow> rows = rowsPublisher.toList().blockingGet();
        assertThat(rows).hasSize(20);
        ReactiveRow first = rows.get(0);
        ExecutionInfo firstExecutionInfo = first.getExecutionInfo();
        assertThat(firstExecutionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(firstExecutionInfo.getErrors()).isEmpty();
        assertThat(firstExecutionInfo.getIncomingPayload()).isEmpty();
        assertThat(firstExecutionInfo.getPagingState()).isNotNull();
        assertThat(firstExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(firstExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(firstExecutionInfo.getWarnings()).isEmpty();
        ReactiveRow inSecondPage = rows.get(10);
        ExecutionInfo secondExecutionInfo = inSecondPage.getExecutionInfo();
        assertThat(secondExecutionInfo.getCoordinator()).isEqualTo(node1);
        assertThat(secondExecutionInfo.getErrors()).isEmpty();
        assertThat(secondExecutionInfo.getIncomingPayload()).isEmpty();
        assertThat(secondExecutionInfo.getPagingState()).isNull();
        assertThat(secondExecutionInfo.getSpeculativeExecutionCount()).isEqualTo(0);
        assertThat(secondExecutionInfo.getSuccessfulExecutionIndex()).isEqualTo(0);
        assertThat(secondExecutionInfo.getWarnings()).isEmpty();
        Flowable<ExecutionInfo> execInfosFlowable = Flowable.fromPublisher(publisher.getExecutionInfos());
        assertThat(execInfosFlowable.toList().blockingGet()).containsExactly(firstExecutionInfo, secondExecutionInfo);
        Flowable<ColumnDefinitions> colDefsFlowable = Flowable.fromPublisher(publisher.getColumnDefinitions());
        assertThat(colDefsFlowable.toList().blockingGet()).containsExactly(first.getColumnDefinitions());
        Flowable<Boolean> wasAppliedFlowable = Flowable.fromPublisher(publisher.wasApplied());
        assertThat(wasAppliedFlowable.toList().blockingGet()).containsExactly(first.wasApplied());
    }
}
Also used : ContinuousCqlRequestAsyncProcessor(com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor) ColumnDefinitions(com.datastax.oss.driver.api.core.cql.ColumnDefinitions) PoolBehavior(com.datastax.oss.driver.internal.core.cql.PoolBehavior) RequestHandlerTestHarness(com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) ReactiveRow(com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow) ContinuousReactiveResultSet(com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet) InternalDriverContext(com.datastax.oss.driver.internal.core.context.InternalDriverContext) DefaultSession(com.datastax.oss.driver.internal.core.session.DefaultSession) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Aggregations

DefaultSession (com.datastax.oss.driver.internal.core.session.DefaultSession)9 Test (org.junit.Test)9 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)6 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)6 ReactiveRow (com.datastax.dse.driver.api.core.cql.reactive.ReactiveRow)4 ColumnDefinitions (com.datastax.oss.driver.api.core.cql.ColumnDefinitions)4 InternalDriverContext (com.datastax.oss.driver.internal.core.context.InternalDriverContext)4 PoolBehavior (com.datastax.oss.driver.internal.core.cql.PoolBehavior)4 RequestHandlerTestHarness (com.datastax.oss.driver.internal.core.cql.RequestHandlerTestHarness)4 CqlSession (com.datastax.oss.driver.api.core.CqlSession)3 Node (com.datastax.oss.driver.api.core.metadata.Node)3 ContinuousReactiveResultSet (com.datastax.dse.driver.api.core.cql.continuous.reactive.ContinuousReactiveResultSet)2 ReactiveResultSet (com.datastax.dse.driver.api.core.cql.reactive.ReactiveResultSet)2 ReactiveGraphNode (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphNode)2 ReactiveGraphResultSet (com.datastax.dse.driver.api.core.graph.reactive.ReactiveGraphResultSet)2 ContinuousCqlRequestAsyncProcessor (com.datastax.dse.driver.internal.core.cql.continuous.ContinuousCqlRequestAsyncProcessor)2 GraphRequestHandlerTestHarness (com.datastax.dse.driver.internal.core.graph.GraphRequestHandlerTestHarness)2 GraphTestUtils.createGraphBinaryModule (com.datastax.dse.driver.internal.core.graph.GraphTestUtils.createGraphBinaryModule)2 GraphBinaryModule (com.datastax.dse.driver.internal.core.graph.binary.GraphBinaryModule)2 TokenRange (com.datastax.oss.driver.api.core.metadata.token.TokenRange)2