Skip to content

Commit

Permalink
Checkstyle (#122)
Browse files Browse the repository at this point in the history
* Add checkstyle plugin to maven.

* Apply checkstyle coding standards

* Apply checkstyle fixes on walker exception handling, catching of Exception is not allowed.
  • Loading branch information
Tiihott authored Nov 22, 2024
1 parent 2b251b1 commit 4429cbc
Show file tree
Hide file tree
Showing 45 changed files with 501 additions and 133 deletions.
212 changes: 212 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,218 @@
<useUnlimitedThreads>true</useUnlimitedThreads>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>3.5.0</version>
<executions>
<!-- These are all errors that will fail the build if triggered -->
<execution>
<id>scan-errors</id>
<goals>
<goal>check</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<violationSeverity>error</violationSeverity>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>true</failOnViolation>
<failsOnError>false</failsOnError>
<checkstyleRules>
<module name="Checker">
<module name="TreeWalker">
<module name="ClassMemberImpliedModifier"></module>
<module name="CovariantEquals"></module>
<module name="DefaultComesLast"></module>
<module name="EmptyBlock"></module>
<module name="EmptyCatchBlock"></module>
<module name="EmptyStatement"></module>
<module name="EqualsAvoidNull"></module>
<module name="EqualsHashCode"></module>
<module name="FallThrough"></module>
<module name="FinalClass"></module>
<module name="HiddenField">
<property name="ignoreConstructorParameter" value="true"></property>
<property name="ignoreSetter" value="true"></property>
</module>
<module name="IllegalCatch"></module>
<module name="IllegalImport"></module>
<module name="IllegalThrows"></module>
<module name="IllegalToken"></module>
<module name="IllegalType"></module>
<module name="InnerAssignment"></module>
<module name="InterfaceMemberImpliedModifier"></module>
<module name="MissingOverride"></module>
<module name="MissingSwitchDefault"></module>
<module name="ModifiedControlVariable">
<property name="skipEnhancedForLoopVariable" value="true"></property>
</module>
<module name="ModifierOrder"></module>
<module name="MutableException"></module>
<module name="NeedBraces"></module>
<module name="NestedForDepth">
<property name="max" value="2"></property>
</module>
<module name="NestedTryDepth"></module>
<module name="NoClone"></module>
<module name="NoFinalizer"></module>
<module name="OneTopLevelClass"></module>
<module name="PackageDeclaration"></module>
<module name="PackageName">
<property name="format" value="^com\.teragrep\.[a-z]{3}_\d{2}(?:.[a-zA-Z]\w*)*$"></property>
</module>
<module name="ReturnCount">
<property name="max" value="5"></property>
</module>
<module name="StringLiteralEquality"></module>
<module name="SuperClone"></module>
<module name="SuperFinalize"></module>
<module name="TypeName"></module>
<module name="UpperEll"></module>
<module name="VisibilityModifier">
<property name="allowPublicFinalFields" value="true"></property>
</module>
</module>
<module name="Translation"></module>
<module name="UniqueProperties"></module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value=".*[\\/]src[\\/]main[\\/]java[\\/]com[\\/]teragrep[\\/]pth_06[\\/]jooq[\\/]generated[\\/].*$"></property>
</module>
</module>
</checkstyleRules>
</configuration>
</execution>
<!-- These are warnings but will not fail the build -->
<execution>
<id>scan-warnings</id>
<goals>
<goal>check</goal>
</goals>
<phase>process-classes</phase>
<configuration>
<violationSeverity>warning</violationSeverity>
<logViolationsToConsole>true</logViolationsToConsole>
<failOnViolation>false</failOnViolation>
<failsOnError>false</failsOnError>
<checkstyleRules>
<module name="Checker">
<module name="TreeWalker">
<module name="ArrayTypeStyle">
<property name="severity" value="warning"></property>
</module>
<module name="AvoidNestedBlocks">
<property name="allowInSwitchCase" value="true"></property>
<property name="severity" value="warning"></property>
</module>
<module name="AvoidNoArgumentSuperConstructorCall">
<property name="severity" value="warning"></property>
</module>
<module name="AvoidStarImport">
<property name="severity" value="warning"></property>
</module>
<module name="AvoidStaticImport">
<property name="severity" value="warning"></property>
</module>
<module name="DeclarationOrder">
<property name="severity" value="warning"></property>
</module>
<module name="FinalLocalVariable">
<property name="severity" value="warning"></property>
</module>
<module name="FinalParameters">
<property name="severity" value="warning"></property>
</module>
<module name="MagicNumber">
<property name="severity" value="warning"></property>
</module>
<module name="MissingDeprecated">
<property name="severity" value="warning"></property>
</module>
<module name="MultipleVariableDeclarations">
<property name="severity" value="warning"></property>
</module>
<module name="NestedForDepth">
<property name="max" value="1"></property>
<property name="severity" value="warning"></property>
</module>
<module name="NestedIfDepth">
<property name="severity" value="warning"></property>
</module>
<module name="NoArrayTrailingComma">
<property name="severity" value="warning"></property>
</module>
<module name="NoCodeInFile">
<property name="severity" value="warning"></property>
</module>
<module name="NoEnumTrailingComma">
<property name="severity" value="warning"></property>
</module>
<module name="OneStatementPerLine">
<property name="severity" value="warning"></property>
</module>
<module name="OuterTypeFilename">
<property name="severity" value="warning"></property>
</module>
<module name="ParameterAssignment">
<property name="severity" value="warning"></property>
</module>
<module name="RedundantImport">
<property name="severity" value="warning"></property>
</module>
<module name="RequireThis">
<property name="checkFields" value="false"></property>
<property name="checkMethods" value="false"></property>
<property name="validateOnlyOverlapping" value="true"></property>
<property name="severity" value="warning"></property>
</module>
<module name="ReturnCount">
<property name="max" value="1"></property>
<property name="severity" value="warning"></property>
</module>
<module name="SimplifyBooleanExpression">
<property name="severity" value="warning"></property>
</module>
<module name="SimplifyBooleanReturn">
<property name="severity" value="warning"></property>
</module>
<module name="UnnecessarySemicolonAfterOuterTypeDeclaration">
<property name="severity" value="warning"></property>
</module>
<module name="UnnecessarySemicolonAfterTypeMemberDeclaration">
<property name="severity" value="warning"></property>
</module>
<module name="UnnecessarySemicolonInEnumeration">
<property name="severity" value="warning"></property>
</module>
<module name="UnnecessarySemicolonInTryWithResources">
<property name="severity" value="warning"></property>
</module>
<module name="UnusedLocalVariable">
<property name="severity" value="warning"></property>
</module>
<module name="VariableDeclarationUsageDistance">
<property name="severity" value="warning"></property>
</module>
<module name="VisibilityModifier">
<property name="allowPublicFinalFields" value="false"></property>
<property name="severity" value="warning"></property>
</module>
</module>
<module name="NewlineAtEndOfFile">
<property name="severity" value="warning"></property>
</module>
<module name="OrderedProperties">
<property name="severity" value="warning"></property>
</module>
<module name="BeforeExecutionExclusionFileFilter">
<property name="fileNamePattern" value=".*[\\/]src[\\/]main[\\/]java[\\/]com[\\/]teragrep[\\/]pth_06[\\/]jooq[\\/]generated[\\/].*$"></property>
</module>
</module>
</checkstyleRules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/teragrep/pth_06/TeragrepDatasource.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public final class TeragrepDatasource implements DataSourceRegister, TableProvid
});

@Override
public Table getTable(StructType schema, Transform[] partitioning, Map<String, String> properties) {
public Table getTable(StructType schemaArg, Transform[] partitioning, Map<String, String> properties) {
return this;
}

Expand Down
16 changes: 13 additions & 3 deletions src/main/java/com/teragrep/pth_06/config/ConditionConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@

import org.jooq.DSLContext;

import java.util.Objects;

public final class ConditionConfig {

private final DSLContext ctx;
Expand Down Expand Up @@ -107,14 +109,22 @@ public boolean streamQuery() {

@Override
public boolean equals(Object object) {
if (this == object)
if (this == object) {
return true;
if (object == null)
}
if (object == null) {
return false;
if (object.getClass() != this.getClass())
}
if (object.getClass() != this.getClass()) {
return false;
}
final ConditionConfig cast = (ConditionConfig) object;
return this.bloomEnabled == cast.bloomEnabled && this.streamQuery == cast.streamQuery
&& this.withoutFilters == cast.withoutFilters && this.ctx == cast.ctx;
}

@Override
public int hashCode() {
return Objects.hash(ctx, streamQuery, bloomEnabled, withoutFilters);
}
}
8 changes: 4 additions & 4 deletions src/main/java/com/teragrep/pth_06/planner/ArchiveQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@
*/
public interface ArchiveQuery {

Result<Record11<ULong, String, String, String, String, Date, String, String, Long, ULong, ULong>> processBetweenUnixEpochHours(
public abstract Result<Record11<ULong, String, String, String, String, Date, String, String, Long, ULong, ULong>> processBetweenUnixEpochHours(
long startHour,
long endHour
);

void commit(long offset);
public abstract void commit(long offset);

Long getInitialOffset();
public abstract Long getInitialOffset();

Long incrementAndGetLatestOffset();
public abstract Long incrementAndGetLatestOffset();
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
import org.jooq.types.ULong;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.sql.Date;
import java.sql.SQLException;
import java.time.Instant;
Expand Down Expand Up @@ -102,7 +105,7 @@ public ArchiveQueryProcessor(Config config) {
rollingDay = Instant.ofEpochSecond(this.earliestEpoch).atZone(ZoneId.systemDefault()).toLocalDate();

}
catch (Exception ex) {
catch (ParserConfigurationException | IOException | SAXException ex) {
throw new RuntimeException(
"ArchiveQueryProcessor problems when construction Query conditions query:" + config.query
+ " exception:" + ex
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/teragrep/pth_06/planner/BatchSizeLimit.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,10 @@ final class BatchSizeLimit {
final long maxObjectCount;

/** accumulated sum of weights */
float accumulatedWeight;
private float accumulatedWeight;

/** accumulated sum of object count */
long accumulatedObjectCount;
private long accumulatedObjectCount;

/**
* Initialize the BatchSizeLimit with the given maximum size and maximum object count.
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/com/teragrep/pth_06/planner/KafkaQuery.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@
*/
public interface KafkaQuery {

Map<TopicPartition, Long> getInitialEndOffsets();
public abstract Map<TopicPartition, Long> getInitialEndOffsets();

Map<TopicPartition, Long> getEndOffsets(KafkaOffset startOffset);
public abstract Map<TopicPartition, Long> getEndOffsets(KafkaOffset startOffset);

Map<TopicPartition, Long> getBeginningOffsets(KafkaOffset endOffset);
public abstract Map<TopicPartition, Long> getBeginningOffsets(KafkaOffset endOffset);

void commit(KafkaOffset offset);
public abstract void commit(KafkaOffset offset);
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@
import org.apache.kafka.common.errors.TopicAuthorizationException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import javax.xml.parsers.ParserConfigurationException;
import java.io.IOException;
import java.time.Duration;
import java.util.*;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -91,7 +94,7 @@ public KafkaQueryProcessor(Config config) {
KafkaWalker parser = new KafkaWalker();
topicsRegexString = parser.fromString(config.query);
}
catch (Exception ex) {
catch (ParserConfigurationException | IOException | SAXException ex) {
ex.printStackTrace();
throw new RuntimeException(
"KafkaQueryProcessor problems when construction Query conditions query:" + config.query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
* <h1>Mock Kafka Consumer Factory</h1> Mocked Kafka Consumer factory used for testing.
Expand All @@ -65,9 +66,9 @@
* @author Mikko Kortelainen
*/
@VisibleForTesting
public class MockKafkaConsumerFactory {
public final class MockKafkaConsumerFactory {

final static private Logger LOGGER = LoggerFactory.getLogger(MockKafkaConsumerFactory.class);
private static final Logger LOGGER = LoggerFactory.getLogger(MockKafkaConsumerFactory.class);

private MockKafkaConsumerFactory() {

Expand Down Expand Up @@ -251,13 +252,13 @@ public static Consumer<byte[], byte[]> getConsumer() {
consumer = new MockConsumer(OffsetResetStrategy.EARLIEST);
consumer.assign(Collections.singletonList(new TopicPartition("testConsumerTopic", 0)));

HashMap<TopicPartition, Long> beginningOffsets = new HashMap<>();
Map<TopicPartition, Long> beginningOffsets = new HashMap<>();
beginningOffsets.put(new TopicPartition("testConsumerTopic", 0), 0L); // start is inclusive
consumer.updateBeginningOffsets(beginningOffsets);

generateEvents(consumer);

HashMap<TopicPartition, Long> endOffsets = new HashMap<>();
Map<TopicPartition, Long> endOffsets = new HashMap<>();
endOffsets.put(new TopicPartition("testConsumerTopic", 0), 14L); // end is exclusive
consumer.updateEndOffsets(endOffsets);
LOGGER.debug(endOffsets.toString());
Expand Down
Loading

0 comments on commit 4429cbc

Please sign in to comment.