Skip to content

Commit

Permalink
Fix checkstyle plugin run on jet samples
Browse files Browse the repository at this point in the history
Also, resolved the checkstyle issues that came up afterwards.
  • Loading branch information
Ufuk Yılmaz committed Jun 30, 2021
1 parent 84bd250 commit 337f510
Show file tree
Hide file tree
Showing 70 changed files with 386 additions and 159 deletions.
11 changes: 11 additions & 0 deletions checkstyle/suppressions.xml
Expand Up @@ -17,6 +17,17 @@
<suppress checks="NPathComplexity" files="com/hazelcast/examples/iterator/CacheIteratorUsage"/>
<suppress checks="VisibilityModifierCheck" files="member/*" />
<suppress checks="VisibilityModifierCheck" files="client/*" />
<suppress checks="VisibilityModifierCheck" files="jet/cdc/Customer" />
<suppress checks="VisibilityModifierCheck" files="jet/files/SalesJsonAnalyzer" />
<suppress checks="EmptyBlock" files="member/LockSample" />
<suppress checks="EmptyBlock" files="client/LockSample" />
<suppress checks="InnerAssignment" files="jet/jobmanagement/JobSuspendResume" />
<suppress checks="InnerAssignment" files="jet/sessionwindow/GenerateEventsP" />
<suppress checks="InnerAssignment" files="jet/sockets/StreamTextSocket" />
<suppress checks="GenericWhitespace" files="jet/returnresults" />
<suppress checks="GenericWhitespace" files="jet/wordcount" />
<suppress checks="GenericWhitespace" files="jet/slidingwindow" />

<suppress checks="[a-zA-Z0-9]*" files="jet/files/unifiedapi/generated/AvroTrade" />
<suppress checks="[a-zA-Z0-9]*" files="jet/hadoop/generated/User" />
</suppressions>
6 changes: 6 additions & 0 deletions jet/cdc/pom.xml
Expand Up @@ -41,4 +41,10 @@
<version>${hazelcast.version}</version>
</dependency>
</dependencies>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
5 changes: 5 additions & 0 deletions jet/co-group/pom.xml
Expand Up @@ -29,4 +29,9 @@
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Expand Up @@ -51,7 +51,8 @@
* joins two or more streams on a common key and performs a user-specified
* aggregate operation on the co-grouped items.
*/
@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
// https://bugs.openjdk.java.net/browse/JDK-8154236
@SuppressWarnings("Convert2MethodRef")
public final class BatchCoGroup {
private static final String PAGE_VISIT = "pageVisit";
private static final String ADD_TO_CART = "addToCart";
Expand Down
Expand Up @@ -44,7 +44,8 @@
import static com.hazelcast.jet.pipeline.WindowDefinition.sliding;
import static java.util.concurrent.TimeUnit.MILLISECONDS;

@SuppressWarnings("Convert2MethodRef") // https://bugs.openjdk.java.net/browse/JDK-8154236
// https://bugs.openjdk.java.net/browse/JDK-8154236
@SuppressWarnings("Convert2MethodRef")
public final class WindowedCoGroup {
private static final String TOPIC = "topic";
private static final String PAGE_VISIT = "pageVisit";
Expand Down Expand Up @@ -80,22 +81,22 @@ private static Pipeline aggregate() {
Pipeline p = Pipeline.create();
p.readFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
START_FROM_OLDEST, mapEventNewValue(), mapPutEvents()))
.withTimestamps(pv -> pv.timestamp(), 100)
.window(sliding(10, 1))
.aggregate(counting())
.writeTo(Sinks.logger());
.withTimestamps(pv -> pv.timestamp(), 100)
.window(sliding(10, 1))
.aggregate(counting())
.writeTo(Sinks.logger());
return p;
}

private static Pipeline groupAndAggregate() {
Pipeline p = Pipeline.create();
p.readFrom(Sources.<PageVisit, Integer, PageVisit>mapJournal(PAGE_VISIT,
START_FROM_OLDEST, mapEventNewValue(), mapPutEvents()))
.withTimestamps(pv -> pv.timestamp(), 100)
.window(sliding(10, 1))
.groupingKey(pv -> pv.userId())
.aggregate(toList())
.writeTo(Sinks.logger());
.withTimestamps(pv -> pv.timestamp(), 100)
.window(sliding(10, 1))
.groupingKey(pv -> pv.userId())
.aggregate(toList())
.writeTo(Sinks.logger());
return p;
}

Expand Down Expand Up @@ -155,10 +156,10 @@ START_FROM_OLDEST, mapEventNewValue(), mapPutEvents()))
.writeTo(Sinks.logger(r -> {
ItemsByTag items = r.result();
return String.format(
"window(%s..%s): id %d%n" +
"pageVisits %s%n" +
"addToCarts %s%n" +
"payments %s",
"window(%s..%s): id %d%n"
+ "pageVisits %s%n"
+ "addToCarts %s%n"
+ "payments %s",
Util.toLocalTime(r.start()),
Util.toLocalTime(r.end()),
r.getKey(),
Expand Down
Expand Up @@ -33,11 +33,14 @@ public int quantity() {

@Override
public boolean equals(Object obj) {
final AddToCart that;
return obj instanceof AddToCart
&& this.timestamp() == (that = (AddToCart) obj).timestamp()
&& this.userId() == that.userId()
&& this.quantity == that.quantity;
if (obj instanceof AddToCart) {
AddToCart that = (AddToCart) obj;
return this.timestamp() == that.timestamp()
&& this.userId() == that.userId()
&& this.quantity == that.quantity;
} else {
return false;
}
}

@Override
Expand All @@ -51,10 +54,10 @@ public int hashCode() {

@Override
public String toString() {
return "AddToCart{" +
"quantity=" + quantity +
", userId=" + userId() +
", timestamp=" + Util.toLocalTime(timestamp()) +
'}';
return "AddToCart{"
+ "quantity=" + quantity
+ ", userId=" + userId()
+ ", timestamp=" + Util.toLocalTime(timestamp())
+ '}';
}
}
Expand Up @@ -33,11 +33,14 @@ public int loadTime() {

@Override
public boolean equals(Object obj) {
final PageVisit that;
return obj instanceof PageVisit
&& this.timestamp() == (that = (PageVisit) obj).timestamp()
&& this.userId() == that.userId()
&& this.loadTime == that.loadTime;
if (obj instanceof PageVisit) {
PageVisit that = (PageVisit) obj;
return this.timestamp() == that.timestamp()
&& this.userId() == that.userId()
&& this.loadTime == that.loadTime;
} else {
return false;
}
}

@Override
Expand All @@ -51,10 +54,10 @@ public int hashCode() {

@Override
public String toString() {
return "PageVisit{" +
"loadTime=" + loadTime +
", userId=" + userId() +
", timestamp=" + Util.toLocalTime(timestamp()) +
'}';
return "PageVisit{"
+ "loadTime=" + loadTime
+ ", userId=" + userId()
+ ", timestamp=" + Util.toLocalTime(timestamp())
+ '}';
}
}
Expand Up @@ -33,11 +33,14 @@ public int amount() {

@Override
public boolean equals(Object obj) {
final Payment that;
return obj instanceof Payment
&& this.timestamp() == (that = (Payment) obj).timestamp()
&& this.userId() == that.userId()
&& this.amount == that.amount;
if (obj instanceof Payment) {
Payment that = (Payment) obj;
return this.timestamp() == that.timestamp()
&& this.userId() == that.userId()
&& this.amount == that.amount;
} else {
return false;
}
}

@Override
Expand All @@ -51,10 +54,10 @@ public int hashCode() {

@Override
public String toString() {
return "Payment{" +
"amount=" + amount +
", userId=" + userId() +
", timestamp=" + Util.toLocalTime(timestamp()) +
'}';
return "Payment{"
+ "amount=" + amount
+ ", userId=" + userId()
+ ", timestamp=" + Util.toLocalTime(timestamp())
+ '}';
}
}
6 changes: 6 additions & 0 deletions jet/early-window-results/pom.xml
Expand Up @@ -40,4 +40,10 @@
<version>1.5.0</version>
</dependency>
</dependencies>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
6 changes: 6 additions & 0 deletions jet/elastic/pom.xml
Expand Up @@ -36,4 +36,10 @@
<version>${hazelcast.version}</version>
</dependency>
</dependencies>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
5 changes: 5 additions & 0 deletions jet/enrichment/pom.xml
Expand Up @@ -29,4 +29,9 @@
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
Expand Up @@ -45,6 +45,7 @@
import java.util.stream.Stream;

import static com.hazelcast.function.Functions.entryValue;
import static com.hazelcast.internal.util.EmptyStatement.ignore;
import static com.hazelcast.jet.Util.entry;
import static com.hazelcast.jet.datamodel.Tuple2.tuple2;
import static com.hazelcast.jet.datamodel.Tuple3.tuple3;
Expand Down Expand Up @@ -119,9 +120,12 @@ private Pipeline enrichUsingIMap() {
// first enrich the trade by looking up the product from the IMap
trades
.mapUsingIMap(
productMap, // target map to lookup
trade -> trade.productId(), // key to lookup in the map
(t, product) -> tuple2(t, product.name()) // merge the value in the map with the trade
// target map to lookup
productMap,
// key to lookup in the map
trade -> trade.productId(),
// merge the value in the map with the trade
(t, product) -> tuple2(t, product.name())
)
// (trade, productName)
.mapUsingIMap(
Expand Down Expand Up @@ -170,9 +174,12 @@ private Pipeline enrichUsingReplicatedMap() {
// first enrich the trade by looking up the product from the replicated map
trades
.mapUsingReplicatedMap(
productMap, // target map to lookup
Trade::productId, // key to lookup in the map
(t, product) -> tuple2(t, product.name()) // merge the value in the map with the trade
// target map to lookup
productMap,
// key to lookup in the map
Trade::productId,
// merge the value in the map with the trade
(t, product) -> tuple2(t, product.name())
)
// (trade, productName)
.mapUsingReplicatedMap(
Expand Down Expand Up @@ -264,6 +271,7 @@ private void go() throws Exception {
try {
job.join();
} catch (CancellationException ignored) {
ignore(ignored);
}
} finally {
eventGenerator.shutdown();
Expand Down
Expand Up @@ -39,9 +39,9 @@ public String name() {

@Override
public String toString() {
return "Broker{" +
"id=" + id +
", name='" + name + '\'' +
'}';
return "Broker{"
+ "id=" + id
+ ", name='" + name + '\''
+ '}';
}
}
Expand Up @@ -38,9 +38,9 @@ public String name() {

@Override
public String toString() {
return "Product{" +
"id=" + id +
", name='" + name + '\'' +
'}';
return "Product{"
+ "id=" + id
+ ", name='" + name + '\''
+ '}';
}
}
Expand Up @@ -44,11 +44,14 @@ public int brokerId() {

@Override
public boolean equals(Object obj) {
Trade that;
return obj instanceof Trade
&& this.id == (that = (Trade) obj).id
&& this.productId == that.productId
&& this.brokerId == (that = (Trade) obj).brokerId;
if (obj instanceof Trade) {
Trade that = (Trade) obj;
return this.id == that.id
&& this.productId == that.productId
&& this.brokerId == that.brokerId;
} else {
return false;
}
}

@Override
Expand Down
5 changes: 5 additions & 0 deletions jet/event-journal/pom.xml
Expand Up @@ -36,4 +36,9 @@
</dependency>
</dependencies>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
5 changes: 5 additions & 0 deletions jet/fault-tolerance/pom.xml
Expand Up @@ -27,4 +27,9 @@
<relativePath>../pom.xml</relativePath>
</parent>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
6 changes: 6 additions & 0 deletions jet/files-cloud/pom.xml
Expand Up @@ -49,4 +49,10 @@
<version>${hazelcast.version}</version>
</dependency>
</dependencies>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
6 changes: 6 additions & 0 deletions jet/files/pom.xml
Expand Up @@ -86,4 +86,10 @@
</plugins>

</build>

<properties>
<!-- needed for checkstyle/findbugs -->
<main.basedir>${project.parent.parent.basedir}</main.basedir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>

0 comments on commit 337f510

Please sign in to comment.