Search in sources :

Example 1 with TopicDeleteInjector

use of io.confluent.ksql.topic.TopicDeleteInjector in project ksql by confluentinc.

the class KsqlResourceTest method shouldThrowOnHandleTerminateIfNotConfigured.

@Test
public void shouldThrowOnHandleTerminateIfNotConfigured() {
    // Given:
    ksqlResource = new KsqlResource(ksqlEngine, commandRunner, DISTRIBUTED_COMMAND_RESPONSE_TIMEOUT, activenessRegistrar, (ec, sc) -> InjectorChain.of(schemaInjectorFactory.apply(sc), topicInjectorFactory.apply(ec), new TopicDeleteInjector(ec, sc)), Optional.of(authorizationValidator), errorsHandler, connectErrorHandler, denyListPropertyValidator, commandRunnerWarning);
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> ksqlResource.terminateCluster(securityContext, new ClusterTerminateRequest(ImmutableList.of(""))));
    // Then:
    assertThat(e, exceptionStatusCode(CoreMatchers.is(SERVICE_UNAVAILABLE.code())));
    assertThat(e, exceptionErrorMessage(errorMessage(Matchers.is("Server initializing"))));
}
Also used : ClusterTerminateRequest(io.confluent.ksql.rest.entity.ClusterTerminateRequest) DROP(io.confluent.ksql.rest.entity.CommandId.Action.DROP) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlRestExceptionMatchers.exceptionStatementErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatementErrorMessage) Mockito.doThrow(org.mockito.Mockito.doThrow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) EXECUTE(io.confluent.ksql.rest.entity.CommandId.Action.EXECUTE) ActivenessRegistrar(io.confluent.ksql.version.metrics.ActivenessRegistrar) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Metrics(org.apache.kafka.common.metrics.Metrics) SERVICE_UNAVAILABLE(io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE) KsqlException(io.confluent.ksql.util.KsqlException) FunctionCategory(io.confluent.ksql.function.FunctionCategory) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TOPIC(io.confluent.ksql.rest.entity.CommandId.Type.TOPIC) RunWith(org.junit.runner.RunWith) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) Supplier(java.util.function.Supplier) SessionConfig(io.confluent.ksql.config.SessionConfig) Answer(org.mockito.stubbing.Answer) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) Injector(io.confluent.ksql.statement.Injector) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) Producer(org.apache.kafka.clients.producer.Producer) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) ValueFormat(io.confluent.ksql.serde.ValueFormat) ConnectServerErrors(io.confluent.ksql.rest.server.execution.ConnectServerErrors) CommandStore(io.confluent.ksql.rest.server.computation.CommandStore) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Matcher(org.hamcrest.Matcher) DefaultErrorMessages(io.confluent.ksql.rest.DefaultErrorMessages) Mockito.reset(org.mockito.Mockito.reset) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) ParserMatchers.configured(io.confluent.ksql.parser.ParserMatchers.configured) KsqlEngineTestUtil(io.confluent.ksql.engine.KsqlEngineTestUtil) ParserMatchers.preparedStatementText(io.confluent.ksql.parser.ParserMatchers.preparedStatementText) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlAuthorizationValidator(io.confluent.ksql.security.KsqlAuthorizationValidator) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) ImmutableSet(com.google.common.collect.ImmutableSet) Command(io.confluent.ksql.rest.server.computation.Command) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Statement(io.confluent.ksql.parser.tree.Statement) KsqlConstants(io.confluent.ksql.util.KsqlConstants) Assert.assertThrows(org.junit.Assert.assertThrows) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Function(java.util.function.Function) CommandStatusFuture(io.confluent.ksql.rest.server.computation.CommandStatusFuture) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) Sandbox(io.confluent.ksql.util.Sandbox) ImmutableList(com.google.common.collect.ImmutableList) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) TerminateCluster(io.confluent.ksql.rest.util.TerminateCluster) Queries(io.confluent.ksql.rest.entity.Queries) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Mockito.when(org.mockito.Mockito.when) TABLE(io.confluent.ksql.rest.entity.CommandId.Type.TABLE) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Matchers.not(org.hamcrest.Matchers.not) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) QueuedCommandStatus(io.confluent.ksql.rest.server.computation.QueuedCommandStatus) InjectorChain(io.confluent.ksql.statement.InjectorChain) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Mockito.doReturn(org.mockito.Mockito.doReturn) CREATE(io.confluent.ksql.rest.entity.CommandId.Action.CREATE) QueryMetadata(io.confluent.ksql.util.QueryMetadata) FakeKafkaConsumerGroupClient(io.confluent.ksql.services.FakeKafkaConsumerGroupClient) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MockedStatic(org.mockito.MockedStatic) Matchers.contains(org.hamcrest.Matchers.contains) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Matchers.is(org.hamcrest.Matchers.is) OK(io.netty.handler.codec.http.HttpResponseStatus.OK) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) FormatFactory(io.confluent.ksql.serde.FormatFactory) Mock(org.mockito.Mock) KsqlRestExceptionMatchers.exceptionErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionErrorMessage) CreateStream(io.confluent.ksql.parser.tree.CreateStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) Properties(java.util.Properties) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) AclOperation(org.apache.kafka.common.acl.AclOperation) File(java.io.File) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) TableElements(io.confluent.ksql.parser.tree.TableElements) ERROR_CODE_FORBIDDEN_KAFKA_ACCESS(io.confluent.ksql.rest.Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlStatementErrorMessageMatchers.statement(io.confluent.ksql.rest.entity.KsqlStatementErrorMessageMatchers.statement) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) ServiceContext(io.confluent.ksql.services.ServiceContext) TimeoutException(java.util.concurrent.TimeoutException) CommandId(io.confluent.ksql.rest.entity.CommandId) TableElement(io.confluent.ksql.parser.tree.TableElement) DenyListPropertyValidator(io.confluent.ksql.properties.DenyListPropertyValidator) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) After(org.junit.After) CommandRunner(io.confluent.ksql.rest.server.computation.CommandRunner) QueryLogger(io.confluent.ksql.logging.query.QueryLogger) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) KsqlConfig(io.confluent.ksql.util.KsqlConfig) QueryDescriptionFactory(io.confluent.ksql.rest.entity.QueryDescriptionFactory) TestServiceContext(io.confluent.ksql.services.TestServiceContext) List(java.util.List) KsqlErrorMessageMatchers.errorCode(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorCode) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) FORBIDDEN(io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) KeyFormat(io.confluent.ksql.serde.KeyFormat) STREAM(io.confluent.ksql.rest.entity.CommandId.Type.STREAM) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlErrorMessageMatchers.errorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorMessage) TablesList(io.confluent.ksql.rest.entity.TablesList) DELETE_TOPIC_LIST_PROP(io.confluent.ksql.rest.entity.ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP) Description(org.hamcrest.Description) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Matchers(org.hamcrest.Matchers) KsqlRestExceptionMatchers.exceptionStatusCode(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatusCode) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collections(java.util.Collections) ClusterTerminateRequest(io.confluent.ksql.rest.entity.ClusterTerminateRequest) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) Test(org.junit.Test)

Example 2 with TopicDeleteInjector

use of io.confluent.ksql.topic.TopicDeleteInjector in project ksql by confluentinc.

the class KsqlResourceTest method shouldThrowOnDenyListValidatorWhenHandleKsqlStatement.

@Test
public void shouldThrowOnDenyListValidatorWhenHandleKsqlStatement() {
    // Given:
    ksqlResource = new KsqlResource(ksqlEngine, commandRunner, DISTRIBUTED_COMMAND_RESPONSE_TIMEOUT, activenessRegistrar, (ec, sc) -> InjectorChain.of(schemaInjectorFactory.apply(sc), topicInjectorFactory.apply(ec), new TopicDeleteInjector(ec, sc)), Optional.of(authorizationValidator), errorsHandler, connectErrorHandler, denyListPropertyValidator, commandRunnerWarning);
    final Map<String, Object> props = new HashMap<>(ksqlRestConfig.getKsqlConfigProperties());
    props.put(KsqlConfig.KSQL_PROPERTIES_OVERRIDES_DENYLIST, StreamsConfig.NUM_STREAM_THREADS_CONFIG);
    ksqlResource.configure(new KsqlConfig(props));
    final Map<String, Object> overrides = ImmutableMap.of(StreamsConfig.NUM_STREAM_THREADS_CONFIG, 1);
    doThrow(new KsqlException("deny override")).when(denyListPropertyValidator).validateAll(overrides);
    // When:
    final EndpointResponse response = ksqlResource.handleKsqlStatements(securityContext, new KsqlRequest("query", // stream properties
    overrides, emptyMap(), null));
    // Then:
    verify(denyListPropertyValidator).validateAll(overrides);
    assertThat(response.getStatus(), CoreMatchers.is(BAD_REQUEST.code()));
    assertThat(((KsqlErrorMessage) response.getEntity()).getMessage(), is("deny override"));
}
Also used : ClusterTerminateRequest(io.confluent.ksql.rest.entity.ClusterTerminateRequest) DROP(io.confluent.ksql.rest.entity.CommandId.Action.DROP) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlRestExceptionMatchers.exceptionStatementErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatementErrorMessage) Mockito.doThrow(org.mockito.Mockito.doThrow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) EXECUTE(io.confluent.ksql.rest.entity.CommandId.Action.EXECUTE) ActivenessRegistrar(io.confluent.ksql.version.metrics.ActivenessRegistrar) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Metrics(org.apache.kafka.common.metrics.Metrics) SERVICE_UNAVAILABLE(io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE) KsqlException(io.confluent.ksql.util.KsqlException) FunctionCategory(io.confluent.ksql.function.FunctionCategory) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TOPIC(io.confluent.ksql.rest.entity.CommandId.Type.TOPIC) RunWith(org.junit.runner.RunWith) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) Supplier(java.util.function.Supplier) SessionConfig(io.confluent.ksql.config.SessionConfig) Answer(org.mockito.stubbing.Answer) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) Injector(io.confluent.ksql.statement.Injector) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) Producer(org.apache.kafka.clients.producer.Producer) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) ValueFormat(io.confluent.ksql.serde.ValueFormat) ConnectServerErrors(io.confluent.ksql.rest.server.execution.ConnectServerErrors) CommandStore(io.confluent.ksql.rest.server.computation.CommandStore) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Matcher(org.hamcrest.Matcher) DefaultErrorMessages(io.confluent.ksql.rest.DefaultErrorMessages) Mockito.reset(org.mockito.Mockito.reset) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) ParserMatchers.configured(io.confluent.ksql.parser.ParserMatchers.configured) KsqlEngineTestUtil(io.confluent.ksql.engine.KsqlEngineTestUtil) ParserMatchers.preparedStatementText(io.confluent.ksql.parser.ParserMatchers.preparedStatementText) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlAuthorizationValidator(io.confluent.ksql.security.KsqlAuthorizationValidator) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) ImmutableSet(com.google.common.collect.ImmutableSet) Command(io.confluent.ksql.rest.server.computation.Command) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Statement(io.confluent.ksql.parser.tree.Statement) KsqlConstants(io.confluent.ksql.util.KsqlConstants) Assert.assertThrows(org.junit.Assert.assertThrows) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Function(java.util.function.Function) CommandStatusFuture(io.confluent.ksql.rest.server.computation.CommandStatusFuture) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) Sandbox(io.confluent.ksql.util.Sandbox) ImmutableList(com.google.common.collect.ImmutableList) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) TerminateCluster(io.confluent.ksql.rest.util.TerminateCluster) Queries(io.confluent.ksql.rest.entity.Queries) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Mockito.when(org.mockito.Mockito.when) TABLE(io.confluent.ksql.rest.entity.CommandId.Type.TABLE) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Matchers.not(org.hamcrest.Matchers.not) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) QueuedCommandStatus(io.confluent.ksql.rest.server.computation.QueuedCommandStatus) InjectorChain(io.confluent.ksql.statement.InjectorChain) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Mockito.doReturn(org.mockito.Mockito.doReturn) CREATE(io.confluent.ksql.rest.entity.CommandId.Action.CREATE) QueryMetadata(io.confluent.ksql.util.QueryMetadata) FakeKafkaConsumerGroupClient(io.confluent.ksql.services.FakeKafkaConsumerGroupClient) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MockedStatic(org.mockito.MockedStatic) Matchers.contains(org.hamcrest.Matchers.contains) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Matchers.is(org.hamcrest.Matchers.is) OK(io.netty.handler.codec.http.HttpResponseStatus.OK) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) FormatFactory(io.confluent.ksql.serde.FormatFactory) Mock(org.mockito.Mock) KsqlRestExceptionMatchers.exceptionErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionErrorMessage) CreateStream(io.confluent.ksql.parser.tree.CreateStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) Properties(java.util.Properties) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) AclOperation(org.apache.kafka.common.acl.AclOperation) File(java.io.File) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) TableElements(io.confluent.ksql.parser.tree.TableElements) ERROR_CODE_FORBIDDEN_KAFKA_ACCESS(io.confluent.ksql.rest.Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlStatementErrorMessageMatchers.statement(io.confluent.ksql.rest.entity.KsqlStatementErrorMessageMatchers.statement) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) ServiceContext(io.confluent.ksql.services.ServiceContext) TimeoutException(java.util.concurrent.TimeoutException) CommandId(io.confluent.ksql.rest.entity.CommandId) TableElement(io.confluent.ksql.parser.tree.TableElement) DenyListPropertyValidator(io.confluent.ksql.properties.DenyListPropertyValidator) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) After(org.junit.After) CommandRunner(io.confluent.ksql.rest.server.computation.CommandRunner) QueryLogger(io.confluent.ksql.logging.query.QueryLogger) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) KsqlConfig(io.confluent.ksql.util.KsqlConfig) QueryDescriptionFactory(io.confluent.ksql.rest.entity.QueryDescriptionFactory) TestServiceContext(io.confluent.ksql.services.TestServiceContext) List(java.util.List) KsqlErrorMessageMatchers.errorCode(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorCode) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) FORBIDDEN(io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) KeyFormat(io.confluent.ksql.serde.KeyFormat) STREAM(io.confluent.ksql.rest.entity.CommandId.Type.STREAM) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlErrorMessageMatchers.errorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorMessage) TablesList(io.confluent.ksql.rest.entity.TablesList) DELETE_TOPIC_LIST_PROP(io.confluent.ksql.rest.entity.ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP) Description(org.hamcrest.Description) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Matchers(org.hamcrest.Matchers) KsqlRestExceptionMatchers.exceptionStatusCode(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatusCode) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collections(java.util.Collections) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) HashMap(java.util.HashMap) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) KsqlConfig(io.confluent.ksql.util.KsqlConfig) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlException(io.confluent.ksql.util.KsqlException) Test(org.junit.Test)

Example 3 with TopicDeleteInjector

use of io.confluent.ksql.topic.TopicDeleteInjector in project ksql by confluentinc.

the class KsqlResourceTest method shouldThrowOnHandleStatementIfNotConfigured.

@Test
public void shouldThrowOnHandleStatementIfNotConfigured() {
    // Given:
    ksqlResource = new KsqlResource(ksqlEngine, commandRunner, DISTRIBUTED_COMMAND_RESPONSE_TIMEOUT, activenessRegistrar, (ec, sc) -> InjectorChain.of(schemaInjectorFactory.apply(sc), topicInjectorFactory.apply(ec), new TopicDeleteInjector(ec, sc)), Optional.of(authorizationValidator), errorsHandler, connectErrorHandler, denyListPropertyValidator, commandRunnerWarning);
    // When:
    final KsqlRestException e = assertThrows(KsqlRestException.class, () -> ksqlResource.handleKsqlStatements(securityContext, new KsqlRequest("query", emptyMap(), emptyMap(), null)));
    // Then:
    assertThat(e, exceptionStatusCode(CoreMatchers.is(SERVICE_UNAVAILABLE.code())));
    assertThat(e, exceptionErrorMessage(errorMessage(Matchers.is("Server initializing"))));
}
Also used : ClusterTerminateRequest(io.confluent.ksql.rest.entity.ClusterTerminateRequest) DROP(io.confluent.ksql.rest.entity.CommandId.Action.DROP) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlRestExceptionMatchers.exceptionStatementErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatementErrorMessage) Mockito.doThrow(org.mockito.Mockito.doThrow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) EXECUTE(io.confluent.ksql.rest.entity.CommandId.Action.EXECUTE) ActivenessRegistrar(io.confluent.ksql.version.metrics.ActivenessRegistrar) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Metrics(org.apache.kafka.common.metrics.Metrics) SERVICE_UNAVAILABLE(io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE) KsqlException(io.confluent.ksql.util.KsqlException) FunctionCategory(io.confluent.ksql.function.FunctionCategory) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TOPIC(io.confluent.ksql.rest.entity.CommandId.Type.TOPIC) RunWith(org.junit.runner.RunWith) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) Supplier(java.util.function.Supplier) SessionConfig(io.confluent.ksql.config.SessionConfig) Answer(org.mockito.stubbing.Answer) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) Injector(io.confluent.ksql.statement.Injector) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) Producer(org.apache.kafka.clients.producer.Producer) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) ValueFormat(io.confluent.ksql.serde.ValueFormat) ConnectServerErrors(io.confluent.ksql.rest.server.execution.ConnectServerErrors) CommandStore(io.confluent.ksql.rest.server.computation.CommandStore) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Matcher(org.hamcrest.Matcher) DefaultErrorMessages(io.confluent.ksql.rest.DefaultErrorMessages) Mockito.reset(org.mockito.Mockito.reset) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) ParserMatchers.configured(io.confluent.ksql.parser.ParserMatchers.configured) KsqlEngineTestUtil(io.confluent.ksql.engine.KsqlEngineTestUtil) ParserMatchers.preparedStatementText(io.confluent.ksql.parser.ParserMatchers.preparedStatementText) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlAuthorizationValidator(io.confluent.ksql.security.KsqlAuthorizationValidator) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) ImmutableSet(com.google.common.collect.ImmutableSet) Command(io.confluent.ksql.rest.server.computation.Command) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Statement(io.confluent.ksql.parser.tree.Statement) KsqlConstants(io.confluent.ksql.util.KsqlConstants) Assert.assertThrows(org.junit.Assert.assertThrows) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Function(java.util.function.Function) CommandStatusFuture(io.confluent.ksql.rest.server.computation.CommandStatusFuture) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) Sandbox(io.confluent.ksql.util.Sandbox) ImmutableList(com.google.common.collect.ImmutableList) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) TerminateCluster(io.confluent.ksql.rest.util.TerminateCluster) Queries(io.confluent.ksql.rest.entity.Queries) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Mockito.when(org.mockito.Mockito.when) TABLE(io.confluent.ksql.rest.entity.CommandId.Type.TABLE) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Matchers.not(org.hamcrest.Matchers.not) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) QueuedCommandStatus(io.confluent.ksql.rest.server.computation.QueuedCommandStatus) InjectorChain(io.confluent.ksql.statement.InjectorChain) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Mockito.doReturn(org.mockito.Mockito.doReturn) CREATE(io.confluent.ksql.rest.entity.CommandId.Action.CREATE) QueryMetadata(io.confluent.ksql.util.QueryMetadata) FakeKafkaConsumerGroupClient(io.confluent.ksql.services.FakeKafkaConsumerGroupClient) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MockedStatic(org.mockito.MockedStatic) Matchers.contains(org.hamcrest.Matchers.contains) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Matchers.is(org.hamcrest.Matchers.is) OK(io.netty.handler.codec.http.HttpResponseStatus.OK) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) FormatFactory(io.confluent.ksql.serde.FormatFactory) Mock(org.mockito.Mock) KsqlRestExceptionMatchers.exceptionErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionErrorMessage) CreateStream(io.confluent.ksql.parser.tree.CreateStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) Properties(java.util.Properties) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) AclOperation(org.apache.kafka.common.acl.AclOperation) File(java.io.File) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) TableElements(io.confluent.ksql.parser.tree.TableElements) ERROR_CODE_FORBIDDEN_KAFKA_ACCESS(io.confluent.ksql.rest.Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlStatementErrorMessageMatchers.statement(io.confluent.ksql.rest.entity.KsqlStatementErrorMessageMatchers.statement) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) ServiceContext(io.confluent.ksql.services.ServiceContext) TimeoutException(java.util.concurrent.TimeoutException) CommandId(io.confluent.ksql.rest.entity.CommandId) TableElement(io.confluent.ksql.parser.tree.TableElement) DenyListPropertyValidator(io.confluent.ksql.properties.DenyListPropertyValidator) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) After(org.junit.After) CommandRunner(io.confluent.ksql.rest.server.computation.CommandRunner) QueryLogger(io.confluent.ksql.logging.query.QueryLogger) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) KsqlConfig(io.confluent.ksql.util.KsqlConfig) QueryDescriptionFactory(io.confluent.ksql.rest.entity.QueryDescriptionFactory) TestServiceContext(io.confluent.ksql.services.TestServiceContext) List(java.util.List) KsqlErrorMessageMatchers.errorCode(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorCode) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) FORBIDDEN(io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) KeyFormat(io.confluent.ksql.serde.KeyFormat) STREAM(io.confluent.ksql.rest.entity.CommandId.Type.STREAM) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlErrorMessageMatchers.errorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorMessage) TablesList(io.confluent.ksql.rest.entity.TablesList) DELETE_TOPIC_LIST_PROP(io.confluent.ksql.rest.entity.ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP) Description(org.hamcrest.Description) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Matchers(org.hamcrest.Matchers) KsqlRestExceptionMatchers.exceptionStatusCode(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatusCode) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collections(java.util.Collections) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) Test(org.junit.Test)

Example 4 with TopicDeleteInjector

use of io.confluent.ksql.topic.TopicDeleteInjector in project ksql by confluentinc.

the class KsqlResourceTest method setUpKsqlResource.

private void setUpKsqlResource() {
    ksqlResource = new KsqlResource(ksqlEngine, commandRunner, DISTRIBUTED_COMMAND_RESPONSE_TIMEOUT, activenessRegistrar, (ec, sc) -> InjectorChain.of(schemaInjectorFactory.apply(sc), topicInjectorFactory.apply(ec), new TopicDeleteInjector(ec, sc)), Optional.of(authorizationValidator), errorsHandler, connectErrorHandler, denyListPropertyValidator, commandRunnerWarning);
    ksqlResource.configure(ksqlConfig);
}
Also used : ClusterTerminateRequest(io.confluent.ksql.rest.entity.ClusterTerminateRequest) DROP(io.confluent.ksql.rest.entity.CommandId.Action.DROP) InternalFunctionRegistry(io.confluent.ksql.function.InternalFunctionRegistry) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) ColumnName(io.confluent.ksql.name.ColumnName) ArgumentMatchers.eq(org.mockito.ArgumentMatchers.eq) KsqlErrorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessage) KsqlRestExceptionMatchers.exceptionStatementErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatementErrorMessage) Mockito.doThrow(org.mockito.Mockito.doThrow) TransientQueryMetadata(io.confluent.ksql.util.TransientQueryMetadata) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Duration(java.time.Duration) Map(java.util.Map) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) CommandStatus(io.confluent.ksql.rest.entity.CommandStatus) SystemColumns(io.confluent.ksql.schema.ksql.SystemColumns) ConfiguredStatement(io.confluent.ksql.statement.ConfiguredStatement) EXECUTE(io.confluent.ksql.rest.entity.CommandId.Action.EXECUTE) ActivenessRegistrar(io.confluent.ksql.version.metrics.ActivenessRegistrar) KsqlRestConfig(io.confluent.ksql.rest.server.KsqlRestConfig) QueryDescription(io.confluent.ksql.rest.entity.QueryDescription) Metrics(org.apache.kafka.common.metrics.Metrics) SERVICE_UNAVAILABLE(io.netty.handler.codec.http.HttpResponseStatus.SERVICE_UNAVAILABLE) KsqlException(io.confluent.ksql.util.KsqlException) FunctionCategory(io.confluent.ksql.function.FunctionCategory) KsqlRequest(io.confluent.ksql.rest.entity.KsqlRequest) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.mock(org.mockito.Mockito.mock) CoreMatchers.equalTo(org.hamcrest.CoreMatchers.equalTo) TOPIC(io.confluent.ksql.rest.entity.CommandId.Type.TOPIC) RunWith(org.junit.runner.RunWith) KsqlIdentifierTestUtil(io.confluent.ksql.test.util.KsqlIdentifierTestUtil) KsqlSecurityContext(io.confluent.ksql.security.KsqlSecurityContext) Supplier(java.util.function.Supplier) SessionConfig(io.confluent.ksql.config.SessionConfig) Answer(org.mockito.stubbing.Answer) QueryStatusCount(io.confluent.ksql.rest.entity.QueryStatusCount) Injector(io.confluent.ksql.statement.Injector) Matchers.hasSize(org.hamcrest.Matchers.hasSize) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) UserFunctionLoader(io.confluent.ksql.function.UserFunctionLoader) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Before(org.junit.Before) Producer(org.apache.kafka.clients.producer.Producer) SourceDescriptionFactory(io.confluent.ksql.rest.entity.SourceDescriptionFactory) SandboxedServiceContext(io.confluent.ksql.services.SandboxedServiceContext) Mockito.times(org.mockito.Mockito.times) IOException(java.io.IOException) Test(org.junit.Test) KsqlStream(io.confluent.ksql.metastore.model.KsqlStream) ValueFormat(io.confluent.ksql.serde.ValueFormat) ConnectServerErrors(io.confluent.ksql.rest.server.execution.ConnectServerErrors) CommandStore(io.confluent.ksql.rest.server.computation.CommandStore) KsqlStatementException(io.confluent.ksql.util.KsqlStatementException) Mockito.never(org.mockito.Mockito.never) CreateSourceProperties(io.confluent.ksql.parser.properties.with.CreateSourceProperties) KsqlTopic(io.confluent.ksql.execution.ddl.commands.KsqlTopic) Matcher(org.hamcrest.Matcher) DefaultErrorMessages(io.confluent.ksql.rest.DefaultErrorMessages) Mockito.reset(org.mockito.Mockito.reset) SequentialQueryIdGenerator(io.confluent.ksql.query.id.SequentialQueryIdGenerator) ParserMatchers.configured(io.confluent.ksql.parser.ParserMatchers.configured) KsqlEngineTestUtil(io.confluent.ksql.engine.KsqlEngineTestUtil) ParserMatchers.preparedStatementText(io.confluent.ksql.parser.ParserMatchers.preparedStatementText) SimpleFunctionInfo(io.confluent.ksql.rest.entity.SimpleFunctionInfo) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) KsqlAuthorizationValidator(io.confluent.ksql.security.KsqlAuthorizationValidator) MockitoHamcrest.argThat(org.mockito.hamcrest.MockitoHamcrest.argThat) FakeKafkaTopicClient(io.confluent.ksql.services.FakeKafkaTopicClient) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) QueryDescriptionList(io.confluent.ksql.rest.entity.QueryDescriptionList) ImmutableSet(com.google.common.collect.ImmutableSet) Command(io.confluent.ksql.rest.server.computation.Command) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) Collectors(java.util.stream.Collectors) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) Statement(io.confluent.ksql.parser.tree.Statement) KsqlConstants(io.confluent.ksql.util.KsqlConstants) Assert.assertThrows(org.junit.Assert.assertThrows) KsqlEntityList(io.confluent.ksql.rest.entity.KsqlEntityList) DataSourceType(io.confluent.ksql.metastore.model.DataSource.DataSourceType) MetricCollectors(io.confluent.ksql.metrics.MetricCollectors) Function(java.util.function.Function) CommandStatusFuture(io.confluent.ksql.rest.server.computation.CommandStatusFuture) BAD_REQUEST(io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST) Sandbox(io.confluent.ksql.util.Sandbox) ImmutableList(com.google.common.collect.ImmutableList) ConfiguredKsqlPlan(io.confluent.ksql.planner.plan.ConfiguredKsqlPlan) TerminateCluster(io.confluent.ksql.rest.util.TerminateCluster) Queries(io.confluent.ksql.rest.entity.Queries) SerdeFeatures(io.confluent.ksql.serde.SerdeFeatures) ProducerConfig(org.apache.kafka.clients.producer.ProducerConfig) Collections.emptyMap(java.util.Collections.emptyMap) Matchers.empty(org.hamcrest.Matchers.empty) CoreMatchers.hasItems(org.hamcrest.CoreMatchers.hasItems) MutableFunctionRegistry(io.confluent.ksql.function.MutableFunctionRegistry) EndpointResponse(io.confluent.ksql.rest.EndpointResponse) Mockito.when(org.mockito.Mockito.when) TABLE(io.confluent.ksql.rest.entity.CommandId.Type.TABLE) SourceInfo(io.confluent.ksql.rest.entity.SourceInfo) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector) KsqlStatementErrorMessage(io.confluent.ksql.rest.entity.KsqlStatementErrorMessage) DataSource(io.confluent.ksql.metastore.model.DataSource) StreamsList(io.confluent.ksql.rest.entity.StreamsList) SourceName(io.confluent.ksql.name.SourceName) RunningQuery(io.confluent.ksql.rest.entity.RunningQuery) Matchers.not(org.hamcrest.Matchers.not) KsqlTopicAuthorizationException(io.confluent.ksql.exception.KsqlTopicAuthorizationException) SourceDescription(io.confluent.ksql.rest.entity.SourceDescription) QueuedCommandStatus(io.confluent.ksql.rest.server.computation.QueuedCommandStatus) InjectorChain(io.confluent.ksql.statement.InjectorChain) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Mockito.doReturn(org.mockito.Mockito.doReturn) CREATE(io.confluent.ksql.rest.entity.CommandId.Action.CREATE) QueryMetadata(io.confluent.ksql.util.QueryMetadata) FakeKafkaConsumerGroupClient(io.confluent.ksql.services.FakeKafkaConsumerGroupClient) Set(java.util.Set) ConsumerConfig(org.apache.kafka.clients.consumer.ConsumerConfig) MetaStoreImpl(io.confluent.ksql.metastore.MetaStoreImpl) MockedStatic(org.mockito.MockedStatic) Matchers.contains(org.hamcrest.Matchers.contains) KsqlExecutionContext(io.confluent.ksql.KsqlExecutionContext) Matchers.is(org.hamcrest.Matchers.is) OK(io.netty.handler.codec.http.HttpResponseStatus.OK) FormatOptions(io.confluent.ksql.schema.utils.FormatOptions) FormatFactory(io.confluent.ksql.serde.FormatFactory) Mock(org.mockito.Mock) KsqlRestExceptionMatchers.exceptionErrorMessage(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionErrorMessage) CreateStream(io.confluent.ksql.parser.tree.CreateStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) DropSourceCommand(io.confluent.ksql.execution.ddl.commands.DropSourceCommand) Properties(java.util.Properties) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) AclOperation(org.apache.kafka.common.acl.AclOperation) File(java.io.File) KsqlConfigTestUtil(io.confluent.ksql.KsqlConfigTestUtil) TableElements(io.confluent.ksql.parser.tree.TableElements) ERROR_CODE_FORBIDDEN_KAFKA_ACCESS(io.confluent.ksql.rest.Errors.ERROR_CODE_FORBIDDEN_KAFKA_ACCESS) SqlTypes(io.confluent.ksql.schema.ksql.types.SqlTypes) PreparedStatement(io.confluent.ksql.parser.KsqlParser.PreparedStatement) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) KsqlStatementErrorMessageMatchers.statement(io.confluent.ksql.rest.entity.KsqlStatementErrorMessageMatchers.statement) CoreMatchers(org.hamcrest.CoreMatchers) CoreMatchers.hasItem(org.hamcrest.CoreMatchers.hasItem) KsqlPlan(io.confluent.ksql.engine.KsqlPlan) FunctionNameList(io.confluent.ksql.rest.entity.FunctionNameList) ServiceContext(io.confluent.ksql.services.ServiceContext) TimeoutException(java.util.concurrent.TimeoutException) CommandId(io.confluent.ksql.rest.entity.CommandId) TableElement(io.confluent.ksql.parser.tree.TableElement) DenyListPropertyValidator(io.confluent.ksql.properties.DenyListPropertyValidator) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) After(org.junit.After) CommandRunner(io.confluent.ksql.rest.server.computation.CommandRunner) QueryLogger(io.confluent.ksql.logging.query.QueryLogger) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) EntityUtil(io.confluent.ksql.rest.util.EntityUtil) SourceDescriptionList(io.confluent.ksql.rest.entity.SourceDescriptionList) KsqlTable(io.confluent.ksql.metastore.model.KsqlTable) PropertiesList(io.confluent.ksql.rest.entity.PropertiesList) ImmutableMap(com.google.common.collect.ImmutableMap) Errors(io.confluent.ksql.rest.Errors) KsqlConfig(io.confluent.ksql.util.KsqlConfig) QueryDescriptionFactory(io.confluent.ksql.rest.entity.QueryDescriptionFactory) TestServiceContext(io.confluent.ksql.services.TestServiceContext) List(java.util.List) KsqlErrorMessageMatchers.errorCode(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorCode) KsqlEngineMetrics(io.confluent.ksql.internal.KsqlEngineMetrics) Optional(java.util.Optional) FormatInfo(io.confluent.ksql.serde.FormatInfo) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) StreamsConfig(org.apache.kafka.streams.StreamsConfig) ArgumentMatchers.anyLong(org.mockito.ArgumentMatchers.anyLong) FORBIDDEN(io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN) INTERNAL_SERVER_ERROR(io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR) KeyFormat(io.confluent.ksql.serde.KeyFormat) STREAM(io.confluent.ksql.rest.entity.CommandId.Type.STREAM) QueryDescriptionEntity(io.confluent.ksql.rest.entity.QueryDescriptionEntity) HashMap(java.util.HashMap) AvroSchema(io.confluent.kafka.schemaregistry.avro.AvroSchema) KsqlEntity(io.confluent.ksql.rest.entity.KsqlEntity) FunctionType(io.confluent.ksql.rest.entity.FunctionType) SourceDescriptionEntity(io.confluent.ksql.rest.entity.SourceDescriptionEntity) KsqlErrorMessageMatchers.errorMessage(io.confluent.ksql.rest.entity.KsqlErrorMessageMatchers.errorMessage) TablesList(io.confluent.ksql.rest.entity.TablesList) DELETE_TOPIC_LIST_PROP(io.confluent.ksql.rest.entity.ClusterTerminateRequest.DELETE_TOPIC_LIST_PROP) Description(org.hamcrest.Description) CommandStatusEntity(io.confluent.ksql.rest.entity.CommandStatusEntity) Matchers(org.hamcrest.Matchers) KsqlRestExceptionMatchers.exceptionStatusCode(io.confluent.ksql.rest.server.resources.KsqlRestExceptionMatchers.exceptionStatusCode) Property(io.confluent.ksql.rest.entity.PropertiesList.Property) Mockito.verify(org.mockito.Mockito.verify) Mockito(org.mockito.Mockito) Collections(java.util.Collections) TopicDeleteInjector(io.confluent.ksql.topic.TopicDeleteInjector)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 ImmutableSet (com.google.common.collect.ImmutableSet)4 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)4 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)4 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)4 KsqlConfigTestUtil (io.confluent.ksql.KsqlConfigTestUtil)4 KsqlExecutionContext (io.confluent.ksql.KsqlExecutionContext)4 SessionConfig (io.confluent.ksql.config.SessionConfig)4 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)4 KsqlEngineTestUtil (io.confluent.ksql.engine.KsqlEngineTestUtil)4 KsqlPlan (io.confluent.ksql.engine.KsqlPlan)4 KsqlTopicAuthorizationException (io.confluent.ksql.exception.KsqlTopicAuthorizationException)4 DropSourceCommand (io.confluent.ksql.execution.ddl.commands.DropSourceCommand)4 KsqlTopic (io.confluent.ksql.execution.ddl.commands.KsqlTopic)4 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)4 FunctionCategory (io.confluent.ksql.function.FunctionCategory)4 InternalFunctionRegistry (io.confluent.ksql.function.InternalFunctionRegistry)4 MutableFunctionRegistry (io.confluent.ksql.function.MutableFunctionRegistry)4 UserFunctionLoader (io.confluent.ksql.function.UserFunctionLoader)4