-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
211 additions
and
6 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
src/main/java/pl/amazingcode/threadscollider/multi/MandatoryActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package pl.amazingcode.threadscollider.multi; | ||
|
||
/** Builder for mandatory action. */ | ||
public interface MandatoryActionBuilder { | ||
|
||
/** | ||
* Set action to be executed. | ||
* | ||
* @param action action to be executed | ||
* @return builder | ||
*/ | ||
TimesBuilder withAction(Runnable action); | ||
} |
35 changes: 35 additions & 0 deletions
35
src/main/java/pl/amazingcode/threadscollider/multi/MultiOptionalBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package pl.amazingcode.threadscollider.multi; | ||
|
||
import java.util.function.Consumer; | ||
import pl.amazingcode.threadscollider.single.OptionalBuilder; | ||
import pl.amazingcode.threadscollider.single.ThreadsCollider; | ||
import pl.amazingcode.threadscollider.single.TimeUnitBuilder; | ||
|
||
/** Intermediary builder for {@link ThreadsCollider}. */ | ||
public interface MultiOptionalBuilder { | ||
|
||
/** | ||
* Sets exception consumer for threads. This consumer will be called for each exception thrown by | ||
* threads. Consumer will be called in thread safe manner. | ||
* | ||
* @param threadsExceptionsConsumer - exception consumer for threads. | ||
* @return {@link OptionalBuilder} | ||
*/ | ||
MultiOptionalBuilder withThreadsExceptionsConsumer(Consumer<Exception> threadsExceptionsConsumer); | ||
|
||
/** | ||
* Sets await termination timeout for executor service used by {@link ThreadsCollider}. | ||
* | ||
* @param timeout - await termination timeout for executor service used by {@link | ||
* ThreadsCollider}. | ||
* @return {@link TimeUnitBuilder} | ||
*/ | ||
MultiTimeUnitBuilder withAwaitTerminationTimeout(long timeout); | ||
|
||
/** | ||
* Builds {@link ThreadsCollider}. | ||
* | ||
* @return {@link ThreadsCollider} | ||
*/ | ||
MultiThreadsCollider build(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
src/main/java/pl/amazingcode/threadscollider/multi/MultiTimeUnitBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package pl.amazingcode.threadscollider.multi; | ||
|
||
import pl.amazingcode.threadscollider.single.Builder; | ||
import pl.amazingcode.threadscollider.single.ThreadsCollider; | ||
|
||
/** Intermediary builder for {@link ThreadsCollider}. */ | ||
public interface MultiTimeUnitBuilder { | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as nanoseconds. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asNanoseconds(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as microseconds. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asMicroseconds(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as milliseconds. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asMilliseconds(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as seconds. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asSeconds(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as minutes. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asMinutes(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as hours. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asHours(); | ||
|
||
/** | ||
* Sets await termination timeout time unit for executor service used by {@link ThreadsCollider} | ||
* as days. | ||
* | ||
* @return {@link Builder} | ||
*/ | ||
MultiOptionalBuilder asDays(); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/pl/amazingcode/threadscollider/multi/OptionalActionBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package pl.amazingcode.threadscollider.multi; | ||
|
||
import java.util.function.Consumer; | ||
|
||
public interface OptionalActionBuilder { | ||
|
||
TimesBuilder withAction(Runnable action); | ||
|
||
MultiTimeUnitBuilder withAwaitTerminationTimeout(long timeout); | ||
|
||
MultiOptionalBuilder withThreadsExceptionsConsumer(Consumer<Exception> threadsExceptionsConsumer); | ||
|
||
MultiThreadsCollider build(); | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/pl/amazingcode/threadscollider/multi/TimesBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package pl.amazingcode.threadscollider.multi; | ||
|
||
public interface TimesBuilder { | ||
|
||
OptionalActionBuilder times(int times); | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/pl/amazingcode/threadscollider/architecture/Architecture_Scenarios.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package pl.amazingcode.threadscollider.architecture; | ||
|
||
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.noClasses; | ||
|
||
import com.tngtech.archunit.core.domain.JavaClasses; | ||
import com.tngtech.archunit.core.importer.ClassFileImporter; | ||
import com.tngtech.archunit.core.importer.ImportOption; | ||
import org.junit.jupiter.api.DisplayNameGeneration; | ||
import org.junit.jupiter.api.DisplayNameGenerator; | ||
import org.junit.jupiter.api.Test; | ||
|
||
@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) | ||
final class Architecture_Scenarios { | ||
|
||
private static final String ROOT_PACKAGE = "pl.amazingcode.threadscollider"; | ||
private static final String SINGLE_PACKAGE = "pl.amazingcode.threadscollider.single"; | ||
private static final String MULTI_PACKAGE = "pl.amazingcode.threadscollider.multi"; | ||
|
||
private final JavaClasses classes = | ||
new ClassFileImporter() | ||
.withImportOption(new ImportOption.DoNotIncludeTests()) | ||
.importPackages(ROOT_PACKAGE); | ||
|
||
@Test | ||
void Independent_single_package() { | ||
|
||
noClasses() | ||
.that() | ||
.resideInAPackage(SINGLE_PACKAGE) | ||
.should() | ||
.dependOnClassesThat() | ||
.resideInAnyPackage(MULTI_PACKAGE) | ||
.check(classes); | ||
} | ||
|
||
@Test | ||
void Independent_multi_package() { | ||
|
||
noClasses() | ||
.that() | ||
.resideInAPackage(MULTI_PACKAGE) | ||
.should() | ||
.dependOnClassesThat() | ||
.resideInAnyPackage(SINGLE_PACKAGE) | ||
.check(classes); | ||
} | ||
} |