Search in sources :

Example 11 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method getSchema_avro_schemaId_nonExistingSchemaId.

@Test
public void getSchema_avro_schemaId_nonExistingSchemaId() {
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> schemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.of(1000), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Error serializing message. Error when fetching schema by id. schemaId = 1000", rcve.getMessage());
    assertEquals(42207, rcve.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 12 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method schemaRegistryDisabledReturnsError.

@Test
public void schemaRegistryDisabledReturnsError() {
    SchemaManager mySchemaManager = new SchemaManagerThrowing();
    RestConstraintViolationException e = assertThrows(RestConstraintViolationException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.empty(), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Payload error. Schema Registry must be configured when using schemas.", e.getMessage());
    assertEquals(42206, e.getErrorCode());
}
Also used : RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) Test(org.junit.jupiter.api.Test)

Example 13 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class SchemaManagerImplTest method errorFetchingLatestSchemaBySchemaVersionInvalidSchema.

@Test
public void errorFetchingLatestSchemaBySchemaVersionInvalidSchema() throws RestClientException, IOException {
    SchemaRegistryClient schemaRegistryClientMock = mock(SchemaRegistryClient.class);
    SchemaMetadata schemaMetadataMock = mock(SchemaMetadata.class);
    expect(schemaRegistryClientMock.getLatestSchemaMetadata("subject1")).andReturn(schemaMetadataMock);
    expect(schemaMetadataMock.getSchemaType()).andReturn(EmbeddedFormat.AVRO.name());
    expect(schemaMetadataMock.getSchema()).andReturn(TextNode.valueOf("schema").toString());
    expect(schemaMetadataMock.getReferences()).andReturn(emptyList());
    replay(schemaRegistryClientMock, schemaMetadataMock);
    SchemaManager mySchemaManager = new SchemaManagerImpl(schemaRegistryClientMock, new TopicNameStrategy());
    RestConstraintViolationException rcve = assertThrows(RestConstraintViolationException.class, () -> mySchemaManager.getSchema(TOPIC_NAME, /* format= */
    Optional.empty(), /* subject= */
    Optional.of("subject1"), /* subjectNameStrategy= */
    Optional.empty(), /* schemaId= */
    Optional.empty(), /* schemaVersion= */
    Optional.empty(), /* rawSchema= */
    Optional.empty(), /* isKey= */
    true));
    assertEquals("Invalid schema: Error when fetching latest schema version. subject = subject1", rcve.getMessage());
    assertEquals(42205, rcve.getErrorCode());
}
Also used : SchemaMetadata(io.confluent.kafka.schemaregistry.client.SchemaMetadata) RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) TopicNameStrategy(io.confluent.kafka.serializers.subject.TopicNameStrategy) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) MockSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient) Test(org.junit.jupiter.api.Test)

Example 14 with RestConstraintViolationException

use of io.confluent.rest.exceptions.RestConstraintViolationException in project kafka-rest by confluentinc.

the class ProduceActionTest method testHasNextOnNullData.

@Test
public void testHasNextOnNullData() throws Exception {
    Properties properties = new Properties();
    properties.put(PRODUCE_MAX_REQUESTS_PER_SECOND, "100");
    properties.put(PRODUCE_MAX_BYTES_PER_SECOND, // first record is 25 bytes long
    Integer.toString(30));
    properties.put(PRODUCE_RATE_LIMIT_CACHE_EXPIRY_MS, "3600000");
    properties.put(PRODUCE_RATE_LIMIT_ENABLED, "true");
    // setup
    ChunkedOutputFactory chunkedOutputFactory = mock(ChunkedOutputFactory.class);
    Provider<RequestRateLimiter> countLimitProvider = mock(Provider.class);
    Provider<RequestRateLimiter> bytesLimitProvider = mock(Provider.class);
    RequestRateLimiter rateLimiterForCount = mock(RequestRateLimiter.class);
    RequestRateLimiter rateLimiterForBytes = mock(RequestRateLimiter.class);
    expect(countLimitProvider.get()).andReturn(rateLimiterForCount);
    expect(bytesLimitProvider.get()).andReturn(rateLimiterForBytes);
    rateLimiterForCount.rateLimit(anyInt());
    rateLimiterForBytes.rateLimit(anyInt());
    ProduceAction produceAction = getProduceAction(properties, chunkedOutputFactory, 1, countLimitProvider, bytesLimitProvider);
    MappingIterator<ProduceRequest> requests = null;
    FakeAsyncResponse fakeAsyncResponse = new FakeAsyncResponse();
    RestConstraintViolationException e = assertThrows(RestConstraintViolationException.class, () -> produceAction.produce(fakeAsyncResponse, "clusterId", "topicName", requests));
    assertEquals("Payload error. Null input provided. Data is required.", e.getMessage());
    assertEquals(42206, e.getErrorCode());
}
Also used : ChunkedOutputFactory(io.confluent.kafkarest.response.ChunkedOutputFactory) RequestRateLimiter(io.confluent.kafkarest.ratelimit.RequestRateLimiter) ProduceRequest(io.confluent.kafkarest.entities.v3.ProduceRequest) RestConstraintViolationException(io.confluent.rest.exceptions.RestConstraintViolationException) FakeAsyncResponse(io.confluent.kafkarest.response.FakeAsyncResponse) Properties(java.util.Properties) Test(org.junit.jupiter.api.Test)

Aggregations

RestConstraintViolationException (io.confluent.rest.exceptions.RestConstraintViolationException)14 Test (org.junit.jupiter.api.Test)14 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)4 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)4 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)4 TopicNameStrategy (io.confluent.kafka.serializers.subject.TopicNameStrategy)4 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)3 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)2 RegisteredSchema (io.confluent.kafkarest.entities.RegisteredSchema)2 SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)1 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)1 SchemaMetadata (io.confluent.kafka.schemaregistry.client.SchemaMetadata)1 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)1 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)1 EmbeddedFormat (io.confluent.kafkarest.entities.EmbeddedFormat)1 ProduceRequest (io.confluent.kafkarest.entities.v3.ProduceRequest)1 RequestRateLimiter (io.confluent.kafkarest.ratelimit.RequestRateLimiter)1 ChunkedOutputFactory (io.confluent.kafkarest.response.ChunkedOutputFactory)1 FakeAsyncResponse (io.confluent.kafkarest.response.FakeAsyncResponse)1 IOException (java.io.IOException)1