diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..63cfca8 --- /dev/null +++ b/.gitattributes @@ -0,0 +1,4 @@ +* text=auto eol=lf +*.java ident +*.xml ident +*.png binary diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 5ea8d3b..a9e5ef4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -27,4 +27,4 @@ jobs: restore-keys: | ${{ runner.os }}-jdk-${{ matrix.java }}-maven- - name: Build it with Maven - run: mvn -B verify + run: mvn -B verify -Pqulice diff --git a/.pdd b/.pdd index 06e33de..e395f75 100644 --- a/.pdd +++ b/.pdd @@ -1,7 +1,7 @@ --source=. --verbose --exclude target/**/* ---exclude src/test/resources/**/* +--exclude src/test/resources-binary/**/* --exclude .idea/**/* --rule min-words:15 --rule min-estimate:15 diff --git a/pom.xml b/pom.xml index f92f23f..be80762 100644 --- a/pom.xml +++ b/pom.xml @@ -133,6 +133,10 @@ OTHER DEALINGS IN THE SOFTWARE. ${basedir}/src/test/resources false + + ${basedir}/src/test/resources-binary + false + @@ -230,6 +234,19 @@ OTHER DEALINGS IN THE SOFTWARE. + + + + com.qulice + qulice-maven-plugin + + + checkstyle:/src/test/resources-binary/.* + + + + + diff --git a/src/test/java/org/cqfn/rio/file/WriteSubscriberTest.java b/src/test/java/org/cqfn/rio/file/WriteSubscriberTest.java index 6cbd219..2b4b18b 100644 --- a/src/test/java/org/cqfn/rio/file/WriteSubscriberTest.java +++ b/src/test/java/org/cqfn/rio/file/WriteSubscriberTest.java @@ -36,7 +36,8 @@ import java.util.Locale; import java.util.concurrent.Executors; import org.reactivestreams.Subscriber; -import org.reactivestreams.tck.SubscriberBlackboxVerification; +import org.reactivestreams.Subscription; +import org.reactivestreams.tck.SubscriberWhiteboxVerification; import org.reactivestreams.tck.TestEnvironment; import org.testng.SkipException; import org.testng.annotations.BeforeClass; @@ -46,6 +47,7 @@ * * @since 1.0 * @checkstyle MagicNumberCheck (500 lines) + * @checkstyle AnonInnerLengthCheck (500 lines) */ @SuppressWarnings( { @@ -53,7 +55,7 @@ "PMD.JUnit4TestShouldUseBeforeAnnotation" } ) -public final class WriteSubscriberTest extends SubscriberBlackboxVerification { +public final class WriteSubscriberTest extends SubscriberWhiteboxVerification { /** * Ctor. @@ -62,33 +64,121 @@ public WriteSubscriberTest() { super(new TestEnvironment()); } - @BeforeClass - public void setUp() { - if (System.getProperty("os.name").toLowerCase(Locale.US).contains("win")) { - throw new SkipException("Disabled for windows"); - } - } - @Override - public Subscriber createSubscriber() { + public Subscriber createSubscriber( + final WhiteboxSubscriberProbe probe + ) { final Path tmp; try { tmp = Files.createTempFile(this.getClass().getSimpleName(), ".tmp"); tmp.toFile().deleteOnExit(); - return new WriteSubscriber( - FileChannel.open(tmp, Collections.singleton(StandardOpenOption.WRITE)), - WriteGreed.SINGLE, - Executors.newCachedThreadPool() + return new SubscriberWithProbe<>( + new WriteSubscriber( + FileChannel.open(tmp, Collections.singleton(StandardOpenOption.WRITE)), + WriteGreed.SINGLE, + Executors.newCachedThreadPool() + ), + probe ); } catch (final IOException err) { throw new UncheckedIOException(err); } } + @BeforeClass + public void setUp() { + if (System.getProperty("os.name").toLowerCase(Locale.US).contains("win")) { + throw new SkipException("Disabled for windows"); + } + } + @Override public ByteBuffer createElement(final int element) { final byte[] arr = new byte[1024]; Arrays.fill(arr, (byte) element); return ByteBuffer.wrap(arr); } + + /** + * Subscriber with probe. + * @param Subscriber type + * @since 0.2 + */ + private static class SubscriberWithProbe implements Subscriber { + + /** + * Target subscriber. + */ + private final Subscriber target; + + /** + * Test probe. + */ + private final WhiteboxSubscriberProbe probe; + + /** + * Ctor. + * @param target Subscriber + * @param probe For test + */ + SubscriberWithProbe(final Subscriber target, + final WhiteboxSubscriberProbe probe) { + this.target = target; + this.probe = probe; + } + + @Override + public void onSubscribe(final Subscription subscription) { + this.target.onSubscribe(subscription); + this.probe.registerOnSubscribe(new ProbePuppet(subscription)); + } + + @Override + public void onNext(final T next) { + this.target.onNext(next); + this.probe.registerOnNext(next); + } + + @Override + public void onError(final Throwable err) { + this.target.onError(err); + this.probe.registerOnError(err); + } + + @Override + public void onComplete() { + this.target.onComplete(); + this.probe.registerOnComplete(); + } + } + + /** + * Puppet for subscriber probe. + * @since 0.2 + */ + private static class ProbePuppet implements SubscriberPuppet { + + /** + * Actual subscription. + */ + private final Subscription subscription; + + /** + * New puppet. + * @param subscription Of subscriber + */ + ProbePuppet(final Subscription subscription) { + this.subscription = subscription; + } + + @Override + public void triggerRequest(final long elements) { + this.subscription.request(elements); + } + + @Override + public void signalCancel() { + this.subscription.cancel(); + } + } } diff --git a/src/test/resources/file.bin b/src/test/resources-binary/file.bin similarity index 100% rename from src/test/resources/file.bin rename to src/test/resources-binary/file.bin diff --git a/src/test/resources/log4j.properties b/src/test/resources-binary/log4j.properties similarity index 100% rename from src/test/resources/log4j.properties rename to src/test/resources-binary/log4j.properties