Search in sources :

Example 1 with SyntaxError

use of com.datastax.oss.driver.api.core.servererrors.SyntaxError in project dsbulk by datastax.

the class SchemaSettingsTest method should_reject_constant_in_mapping_when_literal_selector_unsupported.

@Test
void should_reject_constant_in_mapping_when_literal_selector_unsupported() {
    when(session.execute("SELECT (int)1 FROM system.local")).thenThrow(new SyntaxError(mock(Node.class), "Line 1:9 no viable alternative at input '(' (SELECT [(]...)"));
    Config config = TestConfigUtils.createTestConfig("dsbulk.schema", "mapping", "\"f1=c1,f2=(text)'abc'\"", "keyspace", "ks", "table", "t1");
    SchemaSettings settings = new SchemaSettings(config, READ_AND_MAP);
    assertThatThrownBy(() -> settings.init(session, codecFactory, true, true)).isInstanceOf(IllegalStateException.class).hasMessageContaining("At least one constant expression appears on the right side of a mapping entry, " + "but the cluster does not support CQL literals in the SELECT clause");
}
Also used : SyntaxError(com.datastax.oss.driver.api.core.servererrors.SyntaxError) Config(com.typesafe.config.Config) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Test(org.junit.jupiter.api.Test)

Example 2 with SyntaxError

use of com.datastax.oss.driver.api.core.servererrors.SyntaxError in project dsbulk by datastax.

the class NonContinuousBulkExecutorTestBase method setUpSession.

@BeforeEach
void setUpSession() {
    when(session.executeAsync(any(SimpleStatement.class))).thenAnswer(invocation -> {
        SimpleStatement stmt = (SimpleStatement) invocation.getArguments()[0];
        switch(stmt.getQuery()) {
            case "read should succeed 1":
                return futureReadSuccess1a;
            case "read should succeed 2":
                return futureReadSuccess2a;
            case "write should succeed 1":
                return futureWriteSuccess1;
            case "write should succeed 2":
                return futureWriteSuccess2;
            case "should fail":
            default:
                return failedFuture;
        }
    });
    // read request 1a
    futureReadSuccess1a.complete(successfulReadResultSet1a);
    when(successfulReadResultSet1a.currentPage()).thenReturn(page1a);
    when(successfulReadResultSet1a.hasMorePages()).thenReturn(true);
    ExecutionInfo executionInfo1a = mock(ExecutionInfo.class);
    when(successfulReadResultSet1a.getExecutionInfo()).thenReturn(executionInfo1a);
    when(executionInfo1a.getPagingState()).thenReturn(pagingState);
    when(successfulReadResultSet1a.fetchNextPage()).thenReturn(futureReadSuccess1b);
    // read request 1b
    futureReadSuccess1b.complete(successfulReadResultSet1b);
    when(successfulReadResultSet1b.currentPage()).thenReturn(page1b);
    when(successfulReadResultSet1b.hasMorePages()).thenReturn(false);
    ExecutionInfo executionInfo1b = mock(ExecutionInfo.class);
    when(successfulReadResultSet1b.getExecutionInfo()).thenReturn(executionInfo1b);
    when(executionInfo1b.getPagingState()).thenReturn(null);
    // read request 2a
    futureReadSuccess2a.complete(successfulReadResultSet2a);
    when(successfulReadResultSet2a.currentPage()).thenReturn(page2a);
    when(successfulReadResultSet2a.hasMorePages()).thenReturn(false);
    ExecutionInfo executionInfo2a = mock(ExecutionInfo.class);
    when(successfulReadResultSet2a.getExecutionInfo()).thenReturn(executionInfo2a);
    when(executionInfo2a.getPagingState()).thenReturn(null);
    // write request 1
    futureWriteSuccess1.complete(successfulWriteResultSet1);
    when(successfulWriteResultSet1.currentPage()).thenReturn(Collections.emptyList());
    when(successfulWriteResultSet1.hasMorePages()).thenReturn(false);
    when(successfulWriteResultSet1.getExecutionInfo()).thenReturn(executionInfo1a);
    when(executionInfo1a.getPagingState()).thenReturn(null);
    // write request 2
    futureWriteSuccess2.complete(successfulWriteResultSet2);
    when(successfulWriteResultSet2.currentPage()).thenReturn(Collections.emptyList());
    when(successfulWriteResultSet2.hasMorePages()).thenReturn(false);
    when(successfulWriteResultSet2.getExecutionInfo()).thenReturn(executionInfo2a);
    when(executionInfo2a.getPagingState()).thenReturn(null);
    // failed request
    failedFuture.completeExceptionally(new SyntaxError(mock(Node.class), "line 1:0 no viable alternative at input 'should' ([should]...)"));
}
Also used : SyntaxError(com.datastax.oss.driver.api.core.servererrors.SyntaxError) SimpleStatement(com.datastax.oss.driver.api.core.cql.SimpleStatement) ExecutionInfo(com.datastax.oss.driver.api.core.cql.ExecutionInfo) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

SyntaxError (com.datastax.oss.driver.api.core.servererrors.SyntaxError)2 ExecutionInfo (com.datastax.oss.driver.api.core.cql.ExecutionInfo)1 SimpleStatement (com.datastax.oss.driver.api.core.cql.SimpleStatement)1 Config (com.typesafe.config.Config)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1