use of io.jans.scim.model.scim2.ErrorResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceBinaryWithRawSchema_returnsBadRequest.
@Test
public void produceBinaryWithRawSchema_returnsBadRequest() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
String request = "{ \"key\": { \"type\": \"BINARY\", \"schema\": \"{ \\\"type\\\": \\\"string\\\" }\" } }";
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ErrorResponse actual = response.readEntity(ErrorResponse.class);
assertEquals(400, actual.getErrorCode());
}
use of io.jans.scim.model.scim2.ErrorResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceAvroWithRawSchemaAndInvalidData.
@Test
public void produceAvroWithRawSchemaAndInvalidData() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
ProduceRequest request = ProduceRequest.builder().setKey(ProduceRequestData.builder().setFormat(EmbeddedFormat.AVRO).setRawSchema("{\"type\": \"string\"}").setData(IntNode.valueOf(1)).build()).setValue(ProduceRequestData.builder().setFormat(EmbeddedFormat.AVRO).setRawSchema("{\"type\": \"string\"}").setData(IntNode.valueOf(2)).build()).setOriginalSize(0L).build();
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ErrorResponse actual = response.readEntity(ErrorResponse.class);
assertEquals(400, actual.getErrorCode());
}
use of io.jans.scim.model.scim2.ErrorResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceBinaryWithSchemaSubject_returnsBadRequest.
@Test
public void produceBinaryWithSchemaSubject_returnsBadRequest() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
String request = "{ \"key\": { \"type\": \"BINARY\", \"subject\": \"foobar\" } }";
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ErrorResponse actual = response.readEntity(ErrorResponse.class);
assertEquals(400, actual.getErrorCode());
}
use of io.jans.scim.model.scim2.ErrorResponse in project kafka-rest by confluentinc.
the class ProduceActionTest method produceNoSchemaRegistryDefined.
@Test
public void produceNoSchemaRegistryDefined() throws Exception {
// config
final int TOTAL_NUMBER_OF_PRODUCE_CALLS = 1;
Properties properties = new Properties();
properties.put(PRODUCE_MAX_REQUESTS_PER_SECOND, "100");
properties.put(PRODUCE_MAX_BYTES_PER_SECOND, Integer.toString(999999999));
properties.put(PRODUCE_RATE_LIMIT_ENABLED, "true");
properties.put(PRODUCE_RATE_LIMIT_CACHE_EXPIRY_MS, "3600000");
properties.put(SCHEMA_REGISTRY_URL_CONFIG, "");
// setup
ChunkedOutputFactory chunkedOutputFactory = mock(ChunkedOutputFactory.class);
ChunkedOutput<ResultOrError> mockedChunkedOutput = getChunkedOutput(chunkedOutputFactory, TOTAL_NUMBER_OF_PRODUCE_CALLS);
Provider<RequestRateLimiter> countLimitProvider = mock(Provider.class);
Provider<RequestRateLimiter> bytesLimitProvider = mock(Provider.class);
Provider<RequestRateLimiter> countLimiterGlobalProvider = mock(Provider.class);
Provider<RequestRateLimiter> bytesLimiterGlobalProvider = mock(Provider.class);
RequestRateLimiter rateLimiterForCount = mock(RequestRateLimiter.class);
RequestRateLimiter rateLimiterForBytes = mock(RequestRateLimiter.class);
RequestRateLimiter countLimiterGlobal = mock(RequestRateLimiter.class);
RequestRateLimiter bytesLimiterGlobal = mock(RequestRateLimiter.class);
expect(countLimitProvider.get()).andReturn(rateLimiterForCount);
expect(bytesLimitProvider.get()).andReturn(rateLimiterForBytes);
expect(countLimiterGlobalProvider.get()).andReturn(countLimiterGlobal);
expect(bytesLimiterGlobalProvider.get()).andReturn(bytesLimiterGlobal);
rateLimiterForCount.rateLimit(anyInt());
rateLimiterForBytes.rateLimit(anyInt());
bytesLimiterGlobal.rateLimit(anyInt());
countLimiterGlobal.rateLimit(anyInt());
replay(countLimitProvider, bytesLimitProvider, rateLimiterForCount, rateLimiterForBytes, countLimiterGlobal, bytesLimiterGlobal, countLimiterGlobalProvider, bytesLimiterGlobalProvider);
ProduceAction produceAction = getProduceAction(properties, chunkedOutputFactory, 1, countLimitProvider, bytesLimitProvider, countLimiterGlobalProvider, bytesLimiterGlobalProvider, true);
MappingIterator<ProduceRequest> requests = getProduceRequestsMappingIteratorWithSchemaNeeded();
// expected results
ErrorResponse err = ErrorResponse.create(422, "Error: 42206 : Payload error. Schema Registry must be configured when using schemas.");
ResultOrError resultOrErrorFail = ResultOrError.error(err);
expect(mockedChunkedOutput.isClosed()).andReturn(false);
mockedChunkedOutput.write(resultOrErrorFail);
mockedChunkedOutput.close();
replay(mockedChunkedOutput, chunkedOutputFactory);
// run test
FakeAsyncResponse fakeAsyncResponse = new FakeAsyncResponse();
produceAction.produce(fakeAsyncResponse, "clusterId", "topicName", new JsonStream<>(() -> requests));
// check results
EasyMock.verify(requests);
EasyMock.verify(mockedChunkedOutput);
}
use of io.jans.scim.model.scim2.ErrorResponse in project kafka-rest by confluentinc.
the class ProduceActionTest method produceWithByteLimit.
@Test
public void produceWithByteLimit() throws Exception {
// config
final int TOTAL_NUMBER_OF_PRODUCE_CALLS = 2;
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);
ChunkedOutput<ResultOrError> mockedChunkedOutput = getChunkedOutput(chunkedOutputFactory, TOTAL_NUMBER_OF_PRODUCE_CALLS);
Provider<RequestRateLimiter> countLimitProvider = mock(Provider.class);
Provider<RequestRateLimiter> bytesLimitProvider = mock(Provider.class);
Provider<RequestRateLimiter> countLimiterGlobalProvider = mock(Provider.class);
Provider<RequestRateLimiter> bytesLimiterGlobalProvider = mock(Provider.class);
RequestRateLimiter countLimiterGlobal = mock(RequestRateLimiter.class);
RequestRateLimiter bytesLimiterGlobal = mock(RequestRateLimiter.class);
RequestRateLimiter rateLimiterForCount = mock(RequestRateLimiter.class);
RequestRateLimiter rateLimiterForBytes = mock(RequestRateLimiter.class);
expect(countLimitProvider.get()).andReturn(rateLimiterForCount);
expect(bytesLimitProvider.get()).andReturn(rateLimiterForBytes);
expect(countLimiterGlobalProvider.get()).andReturn(countLimiterGlobal);
expect(bytesLimiterGlobalProvider.get()).andReturn(bytesLimiterGlobal);
rateLimiterForCount.rateLimit(anyInt());
rateLimiterForBytes.rateLimit(anyInt());
bytesLimiterGlobal.rateLimit(anyInt());
countLimiterGlobal.rateLimit(anyInt());
expect(countLimiterGlobalProvider.get()).andReturn(countLimiterGlobal);
expect(bytesLimiterGlobalProvider.get()).andReturn(bytesLimiterGlobal);
bytesLimiterGlobal.rateLimit(anyInt());
countLimiterGlobal.rateLimit(anyInt());
rateLimiterForCount.rateLimit(anyInt());
rateLimiterForBytes.rateLimit(anyInt());
EasyMock.expectLastCall().andThrow(new RateLimitExceededException());
replay(countLimitProvider, bytesLimitProvider, rateLimiterForCount, rateLimiterForBytes, countLimiterGlobal, bytesLimiterGlobal, countLimiterGlobalProvider, bytesLimiterGlobalProvider);
ProduceAction produceAction = getProduceAction(properties, chunkedOutputFactory, 1, countLimitProvider, bytesLimitProvider, countLimiterGlobalProvider, bytesLimiterGlobalProvider);
MappingIterator<ProduceRequest> requests = getProduceRequestsMappingIterator(TOTAL_NUMBER_OF_PRODUCE_CALLS);
// expected results
ProduceResponse produceResponse = getProduceResponse(0);
ResultOrError resultOrErrorOK = ResultOrError.result(produceResponse);
expect(mockedChunkedOutput.isClosed()).andReturn(false);
// successful first produce
mockedChunkedOutput.write(resultOrErrorOK);
mockedChunkedOutput.close();
ErrorResponse err = ErrorResponse.create(429, "Request rate limit exceeded: The rate limit of requests per second has been exceeded.");
ResultOrError resultOrErrorFail = ResultOrError.error(err);
expect(mockedChunkedOutput.isClosed()).andReturn(false);
// failing second produce
mockedChunkedOutput.write(resultOrErrorFail);
// error close
mockedChunkedOutput.close();
replay(mockedChunkedOutput, chunkedOutputFactory);
// run test
FakeAsyncResponse fakeAsyncResponse = new FakeAsyncResponse();
produceAction.produce(fakeAsyncResponse, "clusterId", "topicName", new JsonStream<>(() -> requests));
FakeAsyncResponse fakeAsyncResponse2 = new FakeAsyncResponse();
produceAction.produce(fakeAsyncResponse2, "clusterId", "topicName", new JsonStream<>(() -> requests));
// check results
// check results
verify(requests, mockedChunkedOutput, countLimitProvider, bytesLimitProvider, rateLimiterForCount, rateLimiterForBytes, countLimiterGlobal, bytesLimiterGlobal);
}
Aggregations