Skip to content

Commit

Permalink
Adding parameters validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ehud-Lev-Forter committed Jun 11, 2023
1 parent 152f96d commit 4b17c0d
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,23 @@ public void validate() {
Objects.requireNonNull(consumer, "A consumer must be supplied");

transactionsValidation();
validateMinBatchParameters();
}

private void validateMinBatchParameters() {
if (isEnforceMinBatch()){
if (minBatchSize > batchSize)
throw new IllegalArgumentException(
msg("minBatchSize can not by bigger than batchSize: {} > {}",
minBatchSize,
batchSize));
}
if (minBatchTimeoutInMillis < 0){
throw new IllegalArgumentException(
msg("minBatchTimeoutInMillis should be non negative: {}",
minBatchTimeoutInMillis
));
}
}

private void transactionsValidation() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.confluent.parallelconsumer.state;

/*-
* Copyright (C) 2020-2023 Confluent, Inc.
*/

import io.confluent.parallelconsumer.ParallelConsumerOptions;
import lombok.extern.slf4j.Slf4j;
import org.apache.kafka.clients.consumer.Consumer;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import static org.junit.jupiter.api.Assertions.assertThrows;


@Slf4j
public class ParallelConsumerOptionsTest {

private final Consumer<Object,Object> mockConsumer = Mockito.mock(Consumer.class);


@Test
void validateMinBatchParameters(){
assertThrows(
IllegalArgumentException.class,
() -> ParallelConsumerOptions.builder()
.minBatchSize(10)
.minBatchTimeoutInMillis(100)
.consumer(mockConsumer)
.batchSize(5)
.build()
.validate()
);

assertThrows(
IllegalArgumentException.class,
() -> ParallelConsumerOptions.builder()
.minBatchSize(3)
.minBatchTimeoutInMillis(-1)
.consumer(mockConsumer)
.batchSize(5)
.build()
.validate()
);
}
}

0 comments on commit 4b17c0d

Please sign in to comment.