Skip to content

Commit

Permalink
Merge branch '__rultor'
Browse files Browse the repository at this point in the history
  • Loading branch information
rultor committed Jun 12, 2023
2 parents cbbfd43 + 6e13073 commit 3de3945
Show file tree
Hide file tree
Showing 10 changed files with 500 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/Action.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.kafka.act;

/**
* Kafka Action.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@FunctionalInterface
public interface Action {

/**
* Apply action.
*/
void apply();
}
79 changes: 79 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/AssignPartitions.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.kafka.act;

import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.TopicPartition;
import org.cactoos.list.ListOf;

import java.util.Collection;

/**
* Assign Partitions for Kafka Consumer.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
public final class AssignPartitions implements Action {

/**
* Consumer.
*/
private final KafkaConsumer<?, ?> consumer;
/**
* Partitions to assign.
*/
private final Collection<TopicPartition> partitions;

/**
* Ctor.
*
* @param cnsmr Kafka Consumer
* @param prts Partitions to assign
*/
public AssignPartitions(
final KafkaConsumer<?, ?> cnsmr,
final Collection<TopicPartition> prts
) {
this.consumer = cnsmr;
this.partitions = prts;
}

/**
* Ctor.
*
* @param cnsmr Kafka Consumer
* @param prts Partitions to assign.
*/
public AssignPartitions(
final KafkaConsumer<?, ?> cnsmr,
final TopicPartition... prts
) {
this(cnsmr, new ListOf<>(prts));
}

@Override
public void apply() {
this.consumer.assign(this.partitions);
}
}
46 changes: 46 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/CommitAsync.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.kafka.act;

import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.consumer.KafkaConsumer;

/**
* Async Offset Commit.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@RequiredArgsConstructor
public final class CommitAsync implements Action {

/**
* Consumer.
*/
private final KafkaConsumer<?, ?> consumer;

@Override
public void apply() {
this.consumer.commitAsync();
}
}
46 changes: 46 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/CommitSync.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.kafka.act;

import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.consumer.KafkaConsumer;

/**
* Sync Offset Commit.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@RequiredArgsConstructor
public final class CommitSync implements Action {

/**
* Consumer.
*/
private final KafkaConsumer<?, ?> consumer;

@Override
public void apply() {
this.consumer.commitSync();
}
}
46 changes: 46 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/Wakeup.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package io.github.eocqrs.kafka.act;

import lombok.RequiredArgsConstructor;
import org.apache.kafka.clients.consumer.KafkaConsumer;

/**
* Wakeup of Kafka Consumer.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@RequiredArgsConstructor
public final class Wakeup implements Action {

/**
* Consumer.
*/
private final KafkaConsumer<?, ?> consumer;

@Override
public void apply() {
this.consumer.wakeup();
}
}
29 changes: 29 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

/**
* Kafka Actions.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
package io.github.eocqrs.kafka.act;
56 changes: 56 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/act/AssignPartitionsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2023 Aliaksei Bialiauski, EO-CQRS
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/


package io.github.eocqrs.kafka.act;

import org.apache.kafka.clients.consumer.KafkaConsumer;
import org.apache.kafka.common.TopicPartition;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

/**
* Test case for {@link AssignPartitions}.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@ExtendWith(MockitoExtension.class)
final class AssignPartitionsTest {

/*
* @todo #326:45/DEV Introduce Integration Tests for Partition Assigning
*/
@Test
void assignsPartitions(
@Mock final KafkaConsumer<String, String> mck
) {
final Action assign =
new AssignPartitions(mck, new TopicPartition("test", 1));
Assertions.assertDoesNotThrow(assign::apply);
}
}
Loading

4 comments on commit 3de3945

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3de3945 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 326-af48ff49 discovered in src/test/java/io/github/eocqrs/kafka/act/AssignPartitionsTest.java) and submitted as #358. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3de3945 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 351-a36aee37 discovered in src/test/java/io/github/eocqrs/kafka/act/WakeupTest.java) and submitted as #359. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3de3945 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 327-8fa687f2 discovered in src/test/java/io/github/eocqrs/kafka/act/CommitAsyncTest.java) and submitted as #360. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

@0pdd
Copy link
Collaborator

@0pdd 0pdd commented on 3de3945 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Puzzle 325-61fbc47c discovered in src/test/java/io/github/eocqrs/kafka/act/CommitSyncTest.java) and submitted as #361. Please, remember that the puzzle was not necessarily added in this particular commit. Maybe it was added earlier, but we discovered it only now.

Please sign in to comment.