From c45998009c9e58344f60dd6bd928fa8abbaff40a Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Jul 2020 17:52:57 +0300 Subject: [PATCH 1/3] #15 - using whitebox subscriber --- .github/workflows/maven.yml | 2 +- pom.xml | 17 +++ .../g4s8/rio/file/WriteSubscriberTest.java | 118 +++++++++++++++--- .../{resources => resources-binary}/file.bin | Bin .../log4j.properties | 0 5 files changed, 122 insertions(+), 15 deletions(-) rename src/test/{resources => resources-binary}/file.bin (100%) rename src/test/{resources => resources-binary}/log4j.properties (100%) 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/pom.xml b/pom.xml index c862a53..1d6e590 100644 --- a/pom.xml +++ b/pom.xml @@ -109,6 +109,10 @@ OTHER DEALINGS IN THE SOFTWARE. ${basedir}/src/test/resources false + + ${basedir}/src/test/resources-binary + false + @@ -206,5 +210,18 @@ OTHER DEALINGS IN THE SOFTWARE. + + + + com.qulice + qulice-maven-plugin + + + checkstyle:/src/test/resources-binary/.* + + + + + diff --git a/src/test/java/wtf/g4s8/rio/file/WriteSubscriberTest.java b/src/test/java/wtf/g4s8/rio/file/WriteSubscriberTest.java index d6c3934..985577f 100644 --- a/src/test/java/wtf/g4s8/rio/file/WriteSubscriberTest.java +++ b/src/test/java/wtf/g4s8/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 From a789fa3a209d06da20b401665bff0b9b16d14ef4 Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Jul 2020 18:01:33 +0300 Subject: [PATCH 2/3] #15 - gitattributes --- .gitattributes | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 .gitattributes 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 From f3c59c11c755e58635776f5af6455176336cff85 Mon Sep 17 00:00:00 2001 From: Kirill Date: Tue, 28 Jul 2020 18:07:04 +0300 Subject: [PATCH 3/3] #15 - pdd rules exlude bin resources --- .pdd | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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