Skip to content

Commit

Permalink
act tests
Browse files Browse the repository at this point in the history
  • Loading branch information
h1alexbel committed Jun 7, 2023
1 parent e41f649 commit 162a354
Show file tree
Hide file tree
Showing 6 changed files with 284 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public final class ShutdownHook implements Action {
* Main thread.
*/
private final Thread main;
/**
* After.
*/
private final Action after;

@Override
public void apply() {
Expand All @@ -51,6 +55,8 @@ public void apply() {
this.main.join();
} catch (final InterruptedException ex) {
ex.printStackTrace();

Check warning on line 57 in src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java#L55-L57

Added lines #L55 - L57 were not covered by tests
} finally {
this.after.apply();

Check warning on line 59 in src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java#L59

Added line #L59 was not covered by tests
}
})

Check warning on line 61 in src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java

View check run for this annotation

Codecov / codecov/patch

src/main/java/io/github/eocqrs/kafka/act/ShutdownHook.java#L61

Added line #L61 was not covered by tests
);
Expand Down
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);
}
}
54 changes: 54 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/act/CommitAsyncTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.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 CommitAsync}.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@ExtendWith(MockitoExtension.class)
final class CommitAsyncTest {

/*
* @todo #327:45/DEV Introduce Integration Tests for Async Commit
*/
@Test
void commitsAsync(
@Mock final KafkaConsumer<String, String> mck
) {
final Action async = new CommitAsync(mck);
Assertions.assertDoesNotThrow(async::apply);
}
}
54 changes: 54 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/act/CommitSyncTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.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 CommitSync}.
*
* @author Aliaksei Bialiauski (abiliauski.dev@gmail.com)
* @since 0.2.5
*/
@ExtendWith(MockitoExtension.class)
final class CommitSyncTest {

/*
* @todo #325:45/DEV Introduce Integration Tests for Sync Commit
*/
@Test
void commitsSync(
@Mock final KafkaConsumer<String, String> mck
) {
final Action sync = new CommitSync(mck);
Assertions.assertDoesNotThrow(sync::apply);
}
}
62 changes: 62 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/act/ShutdownHookTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* 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.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 ShutdownHook}.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@ExtendWith(MockitoExtension.class)
final class ShutdownHookTest {

/*
* @todo #356:45/DEV Introduce Integration Tests for ShutdownHook
*/
@Test
void shutdownsWithWakeUp(
@Mock final KafkaConsumer<String, String> mck
) {
final Action hook =
new ShutdownHook(
new Wakeup(mck),
Thread.currentThread(),
new Action() {
@Override
public void apply() {
Thread.currentThread().interrupt();
}
}
);
}
}
52 changes: 52 additions & 0 deletions src/test/java/io/github/eocqrs/kafka/act/WakeupTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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.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 Wakeup}.
*
* @author Aliaksei Bialiauski (abialiauski.dev@gmail.com)
* @since 0.2.5
*/
@ExtendWith(MockitoExtension.class)
final class WakeupTest {

/*
* @todo #351:45/DEV Introduce Integration Tests for Consumer Wakeup
*/
@Test
void wakeups(@Mock final KafkaConsumer<String, String> mck) {
final Action wakeup = new Wakeup(mck);
Assertions.assertDoesNotThrow(wakeup::apply);
}
}

0 comments on commit 162a354

Please sign in to comment.