use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnTopicAuthorizationException.
@Test
public void shouldThrowOnTopicAuthorizationException() {
// Given:
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
doThrow(new TopicAuthorizationException(Collections.singleton("t1"))).when(producer).send(any());
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getCause(), (hasMessage(containsString("Authorization denied to Write on topic(s): [t1]"))));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowWhenInsertingValuesOnSourceTable.
@Test
public void shouldThrowWhenInsertingValuesOnSourceTable() {
// Given:
givenDataSourceWithSchema("source_table_1", SCHEMA, SerdeFeatures.of(), SerdeFeatures.of(), true, true);
final KsqlConfig ksqlConfig = new KsqlConfig(ImmutableMap.of());
final ConfiguredStatement<InsertValues> statement = ConfiguredStatement.of(PreparedStatement.of("", new InsertValues(SourceName.of("TOPIC"), allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)))), SessionConfig.of(ksqlConfig, ImmutableMap.of()));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("Cannot insert values into read-only table: TOPIC"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldBuildCorrectSerde.
@Test
public void shouldBuildCorrectSerde() {
// Given:
final ConfiguredStatement<InsertValues> statement = givenInsertValues(valueColumnNames(SCHEMA), ImmutableList.of(new StringLiteral("str"), new LongLiteral(2L)));
// When:
executor.execute(statement, mock(SessionProperties.class), engine, serviceContext);
// Then:
verify(keySerdeFactory).create(FormatInfo.of(FormatFactory.KAFKA.name()), PersistenceSchema.from(SCHEMA.key(), SerdeFeatures.of()), new KsqlConfig(ImmutableMap.of()), srClientFactory, "", NoopProcessingLogContext.INSTANCE, Optional.empty());
verify(valueSerdeFactory).create(FormatInfo.of(FormatFactory.JSON.name()), PersistenceSchema.from(SCHEMA.value(), SerdeFeatures.of()), new KsqlConfig(ImmutableMap.of()), srClientFactory, "", NoopProcessingLogContext.INSTANCE, Optional.empty());
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnTablesWithNoKeyFieldAndNoRowKeyProvided.
@Test
public void shouldThrowOnTablesWithNoKeyFieldAndNoRowKeyProvided() {
// Given:
givenSourceTableWithSchema(SerdeFeatures.of(), SerdeFeatures.of());
final ConfiguredStatement<InsertValues> statement = givenInsertValues(ImmutableList.of(COL0, COL1), ImmutableList.of(new StringLiteral("str"), new LongLiteral(2L)));
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("Failed to insert values into 'TOPIC'. Value for primary key column(s) k0 is required for tables"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral in project ksql by confluentinc.
the class InsertValuesExecutorTest method shouldThrowOnProducerSendError.
@Test
public void shouldThrowOnProducerSendError() throws ExecutionException, InterruptedException {
// Given:
final ConfiguredStatement<InsertValues> statement = givenInsertValues(allAndPseudoColumnNames(SCHEMA), ImmutableList.of(new LongLiteral(1L), new StringLiteral("str"), new StringLiteral("str"), new LongLiteral(2L)));
final Future<?> failure = mock(Future.class);
when(failure.get()).thenThrow(ExecutionException.class);
doReturn(failure).when(producer).send(any());
// When:
final Exception e = assertThrows(KsqlException.class, () -> executor.execute(statement, mock(SessionProperties.class), engine, serviceContext));
// Then:
assertThat(e.getMessage(), containsString("Failed to insert values into "));
}
Aggregations