Skip to content

Commit ab8f388

Browse files
authored
Enabling github checks (#57)
Enabling checks for unit test, checkstyle and spot bugs. Signed-off-by: Amit-Singh40 <[email protected]>
1 parent aa40c7f commit ab8f388

File tree

17 files changed

+143
-56
lines changed

17 files changed

+143
-56
lines changed

.github/workflows/build.yaml

+74-21
Original file line numberDiff line numberDiff line change
@@ -10,37 +10,90 @@
1010
name: build
1111

1212
on: [push, pull_request, workflow_dispatch]
13-
# workflow_dispatch should make manually triggered ci/cd possible
14-
# workflow file (like this) with `workflow_dispatch` after on should exist on the **master** or default branch,
15-
# or there will be no ui for a manual trigger. https://github.community/t/workflow-dispatch-event-not-working/128856/2
13+
# workflow_dispatch should make manually triggered ci/cd possible
14+
# workflow file (like this) with `workflow_dispatch` after on should exist on the **master** or default branch,
15+
# or there will be no ui for a manual trigger. https://github.community/t/workflow-dispatch-event-not-working/128856/2
16+
17+
env:
18+
REPORTS_LOCATIONS: |
19+
pravega-sensor-collector/build/reports
20+
1621
1722
jobs:
1823
build:
1924
name: Build
2025
runs-on: ubuntu-20.04
2126
steps:
27+
- name: Build Information
28+
run: echo Building a '${{ github.event_name }}' for target '${{ github.ref }}'.
2229
- name: Checkout
2330
uses: actions/checkout@v2
24-
25-
- name: Set up JDK
26-
uses: actions/setup-java@v2
31+
- uses: actions/setup-java@v2
2732
with:
28-
distribution: 'zulu'
29-
java-version: '11' # major or semver Java version will be acceptable, see https://github.com/marketplace/actions/setup-java-jdk#basic
30-
31-
- name: Build
33+
distribution: 'temurin'
34+
java-version: '11'
35+
- name: Test build-installer.sh
3236
run: ./scripts/build-installer.sh
37+
- name: Clean
38+
if: ${{ startsWith(github.ref, 'refs/heads/') }}
39+
run: ./gradlew clean ${{env.GRADLE_OPTS}}
40+
- name: Compile & Checkstyle
41+
run: ./gradlew jar compileTest checkstyleMain checkstyleTest --parallel ${{env.GRADLE_OPTS}}
42+
- name: Spotbugs
43+
run: ./gradlew spotbugsMain spotbugsTest
44+
- name: Tar Reports
45+
run: tar --use-compress-program zstd -cf reports-${{github.job}}.tzst `echo ${{env.REPORTS_LOCATIONS}}`
46+
- name: Upload Reports
47+
uses: actions/upload-artifact@v2
48+
with:
49+
name: ${{github.job}}-reports
50+
retention-days: 4
51+
path: reports-${{github.job}}.tzst
52+
# Uncomment these two lines if you need ssh access to debug a build.
53+
# - name: Setup upterm session
54+
# uses: lhotari/action-upterm@v1
55+
56+
57+
unit_test:
58+
name: PSC Unit Tests
59+
needs: build
60+
runs-on: ubuntu-20.04
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@v2
64+
- uses: actions/setup-java@v2
65+
with:
66+
distribution: 'temurin'
67+
java-version: '11'
68+
- name: Unit tests
69+
run: ./gradlew pravega-sensor-collector:test --parallel ${{env.GRADLE_OPTS}}
70+
- name: Tar Reports
71+
run: tar --use-compress-program zstd -cf reports-${{github.job}}.tzst `echo ${{env.REPORTS_LOCATIONS}}`
72+
- name: Upload Reports
73+
if: always()
74+
uses: actions/upload-artifact@v2
75+
with:
76+
name: ${{github.job}}-reports
77+
retention-days: 4
78+
path: reports-${{github.job}}.tzst
3379

34-
- name: Set env
35-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
36-
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
3780

38-
- name: Release
39-
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
40-
uses: softprops/action-gh-release@v1
41-
env:
42-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
81+
# DO NOT RENAME THIS JOB. Mergers to master branch are gated on this completing successfully.
82+
build_and_test_complete:
83+
name: CI Complete
84+
needs: [build, unit_test]
85+
runs-on: ubuntu-20.04
86+
steps:
87+
- name: Check Build Status
88+
run: echo Build, static analysis, unit and integration tests successful.
89+
- name: Checkout
90+
uses: actions/checkout@v2
4391
with:
44-
files: ./pravega-sensor-collector/build/distributions/pravega-sensor-collector-*.tgz
45-
draft: true
46-
name: pravega-sensor-collector ${{ env.RELEASE_VERSION }}
92+
fetch-depth: 2
93+
- name: Download code coverage reports
94+
uses: actions/download-artifact@v2
95+
- name: Untar reports
96+
run: ( ls */reports-*.tzst | xargs -n1 tar --use-compress-program zstd --keep-newer-files -xf )
97+
- name: Upload to Codecov
98+
uses: codecov/codecov-action@v1
99+

config/checkstyle.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<!-- header -->
1111
<module name="RegexpHeader">
12-
<property name="header" value="/\*\*\n * Copyright Pravega Authors\."/>
12+
<property name="header" value="/\*\*\n * Copyright \(c\) Dell Inc., or its subsidiaries. All Rights Reserved."/>
1313
</module>
1414
<module name="SuppressionFilter">
1515
<property name="file" value="${suppressionsFile}"/>
@@ -54,7 +54,7 @@
5454
<module name="LeftCurly"/>
5555
<module name="RightCurly"/>
5656
<module name="ConstantName">
57-
<property name="format" value="(^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$)|(^log$)"/>
57+
<property name="format" value="(^[A-Za-z][A-Za-z0-9]*(_[A-Z0-9]+)*$)|(^log$)"/>
5858
</module>
5959
<module name="LocalVariableName"/>
6060
<module name="LocalFinalVariableName"/>

config/spotbugs-exclude.xml

+43
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,52 @@
2929
<Match> <!-- does not work from JDK11 onwards https://github.com/spotbugs/spotbugs/issues/756 -->
3030
<Bug pattern="RCN_REDUNDANT_NULLCHECK_OF_NONNULL_VALUE" />
3131
</Match>
32+
<Match> <!-- does not work from JDK11 onwards https://github.com/spotbugs/spotbugs/issues/756 -->
33+
<Bug pattern="NP_NULL_ON_SOME_PATH_FROM_RETURN_VALUE" />
34+
</Match>
35+
3236
<Match> <!-- Returning a java.lang.Boolean is common with Streams/Lambdas -->
3337
<Bug pattern="NP_BOOLEAN_RETURN_NULL" />
3438
</Match>
39+
<Match>
40+
<Bug pattern="ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD" />
41+
</Match>
42+
43+
<Match>
44+
<Class name="io.pravega.sensor.collector.util.TransactionCoordinator" />
45+
<Bug pattern="CT_CONSTRUCTOR_THROW" />
46+
</Match>
47+
48+
<Match>
49+
<Class name="io.pravega.sensor.collector.file.csvfile.CsvFileSequenceProcessor" />
50+
<Bug pattern="UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR" />
51+
</Match>
52+
53+
<Match>
54+
<Class name="io.pravega.sensor.collector.file.parquet.ParquetFileProcessor" />
55+
<Bug pattern="UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR" />
56+
</Match>
57+
58+
<Match>
59+
<Class name="io.pravega.sensor.collector.file.rawfile.RawFileProcessor" />
60+
<Bug pattern="UR_UNINIT_READ_CALLED_FROM_SUPER_CONSTRUCTOR" />
61+
</Match>
62+
63+
<Match>
64+
<Class name="io.pravega.sensor.collector.util.TransactionCoordinatorTests" />
65+
<Bug pattern="ODR_OPEN_DATABASE_RESOURCE" />
66+
</Match>
67+
68+
<Match>
69+
<Class name="io.pravega.sensor.collector.accelerometer.AccelerometerSamples" />
70+
<Bug pattern="PA_PUBLIC_PRIMITIVE_ATTRIBUTE" />
71+
</Match>
72+
73+
<Match>
74+
<Class name="io.pravega.sensor.collector.network.NetworkSamples" />
75+
<Bug pattern="PA_PUBLIC_PRIMITIVE_ATTRIBUTE" />
76+
</Match>
77+
3578
<Match> <!-- This is intended in these and only these classes -->
3679
<Or>
3780
<Bug pattern="EI_EXPOSE_REP" />

config/spotbugs-include.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88

99
<!-- A use of untrusted input in a way that could create a remotely exploitable
1010
security vulnerability. -->
11-
<Match>
11+
<!-- <Match>
1212
<Bug category="SECURITY" />
13-
</Match>
13+
</Match> -->
1414

1515
<!-- Violations of recommended and essential coding practice. Examples include
1616
hash code and equals problems, cloneable idiom, dropped exceptions, Serializable
@@ -39,9 +39,9 @@
3939
</Match>
4040

4141
<!-- code flaws having to do with threads, locks, and volatiles -->
42-
<Match>
42+
<!-- <Match>
4343
<Bug category="MT_CORRECTNESS" />
44-
</Match>
44+
</Match> -->
4545

4646
<!-- Experimental and not fully vetted bug patterns -->
4747
<Match>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello World.

pravega-sensor-collector/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ tasks.withType(com.github.spotbugs.snom.SpotBugsTask) {
133133

134134
spotbugs {
135135
toolVersion = spotbugsVersion
136-
ignoreFailures = true
136+
ignoreFailures = false
137137
showProgress = true
138138
effort = 'max'
139139
reportLevel = 'default'

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/accelerometer/AccelerometerDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
import java.util.List;
2727
import java.util.stream.Collectors;
2828

29-
public class AccelerometerDriver extends SimpleDeviceDriver<AccelerometerRawData, AccelerometerSamples> {
29+
public final class AccelerometerDriver extends SimpleDeviceDriver<AccelerometerRawData, AccelerometerSamples> {
3030
private static final Logger LOGGER = LoggerFactory.getLogger(AccelerometerDriver.class);
3131

3232
private static final String CONFIG_DEVICE_FILE_KEY = "CONFIG_DEVICE_FILE";

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/file/FileProcessor.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ void processFile(FileNameWithOffset fileNameWithBeginOffset, long firstSequenceN
203203

204204
try (final InputStream inputStream = new FileInputStream(fileNameWithBeginOffset.fileName)) {
205205
final CountingInputStream countingInputStream = new CountingInputStream(inputStream);
206-
countingInputStream.skip(fileNameWithBeginOffset.offset);
206+
log.info("Offset skipped {}", countingInputStream.skip(fileNameWithBeginOffset.offset));
207207
final Pair<Long, Long> result = eventGenerator.generateEventsFromInputStream(countingInputStream, firstSequenceNumber,
208208
e -> {
209209
log.trace("processFile: event={}", e);
@@ -287,12 +287,4 @@ void deleteCompletedFiles() throws Exception {
287287
});
288288
}
289289

290-
/**
291-
* Inject a failure before commit for testing.
292-
*/
293-
protected void injectCommitFailure() {
294-
if (Math.random() < 0.3) {
295-
throw new RuntimeException("injectCommitFailure: Commit failure test exception");
296-
}
297-
}
298290
}

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/network/NetworkDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
import java.util.stream.Collectors;
3232
import java.util.stream.IntStream;
3333

34-
public class NetworkDriver extends SimpleDeviceDriver<NetworkRawData, NetworkSamples> {
34+
public final class NetworkDriver extends SimpleDeviceDriver<NetworkRawData, NetworkSamples> {
3535
private static final Logger LOGGER = LoggerFactory.getLogger(NetworkDriver.class);
3636

3737
private static final String NETWORK_INTERFACE_KEY = "NETWORK_INTERFACE";

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/opcua/OpcUaClientDriver.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
import static org.eclipse.milo.opcua.stack.core.types.builtin.unsigned.Unsigned.uint;
5454
import static org.eclipse.milo.opcua.stack.core.util.ConversionUtil.toList;
5555

56-
public class OpcUaClientDriver extends SimpleMemorylessDriver<OpcUaRawData> {
56+
public final class OpcUaClientDriver extends SimpleMemorylessDriver<OpcUaRawData> {
5757

5858
private static final Logger LOGGER = LoggerFactory.getLogger(OpcUaClientDriver.class);
5959
private static final Gson JSON_PARSER = new Gson();

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/simple/PersistentQueue.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/**
3434
* A persistent queue that uses a SQLite database on disk.
3535
*/
36-
public class PersistentQueue implements AutoCloseable {
36+
public final class PersistentQueue implements AutoCloseable {
3737
private static final Logger LOGGER = LoggerFactory.getLogger(PersistentQueue.class);
3838

3939
/**

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/simple/PersistentQueueToPravegaService.java

-8
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,4 @@ protected void run() throws Exception {
8888
}
8989
}
9090

91-
/**
92-
* Inject a failure before commit for testing.
93-
*/
94-
protected void injectCommitFailure() {
95-
if (Math.random() < 0.1) {
96-
throw new RuntimeException("injectCommitFailure: Commit failure test exception");
97-
}
98-
}
9991
}

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/stateful/ReadingState.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
/**
2323
* Stores and updates last-read timestamp in the persistent state (SQLite database) *
2424
*/
25-
public class ReadingState {
25+
public final class ReadingState {
2626
private static final Logger LOGGER = LoggerFactory.getLogger(ReadingState.class);
2727
public final Connection connection;
2828
public ReadingState(Connection connection) {

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/util/FileUtils.java

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ public class FileUtils {
3434
public static final String COMPLETED_FILES = "Completed_Files";
3535

3636
/**
37+
* Gets directory listings.
38+
*
39+
* @param fileSpec
40+
* @param fileExtension
41+
* @param movedFilesDirectory
42+
* @param minTimeInMillisToUpdateFile
3743
* @return list of file name and file size in bytes
3844
* Handle the below cases
3945
* 1. If given file path does not exist then log the message and continue

pravega-sensor-collector/src/main/java/io/pravega/sensor/collector/util/PersistentId.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
import java.sql.Statement;
2020
import java.util.UUID;
2121

22-
public class PersistentId {
22+
public final class PersistentId {
2323
private static final Logger LOGGER = LoggerFactory.getLogger(PersistentId.class);
2424

2525
private final UUID persistentId;

pravega-sensor-collector/src/test/java/io/pravega/sensor/collector/file/csvfile/CSVFileEventGeneratorTests.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void test3by2() throws IOException {
4848
}
4949

5050
@Test
51-
public void Test3by3() throws IOException {
51+
public void test3by3() throws IOException {
5252
final EventGenerator eventGenerator = CsvFileEventGenerator.create("routingKey1", 3);
5353
final String csvStr =
5454
"\"Time\",\"X\",\"Y\",\"Z\",\"IN_PROGRESS\"\n"
@@ -64,7 +64,7 @@ public void Test3by3() throws IOException {
6464
}
6565

6666
@Test
67-
public void Test1by3() throws IOException {
67+
public void test1by3() throws IOException {
6868
final EventGenerator eventGenerator = CsvFileEventGenerator.create("routingKey1", 3);
6969
final String csvStr =
7070
"\"Time\",\"X\",\"Y\",\"Z\",\"IN_PROGRESS\"\n"
@@ -78,7 +78,7 @@ public void Test1by3() throws IOException {
7878
}
7979

8080
@Test
81-
public void Test0by3() throws IOException {
81+
public void test0by3() throws IOException {
8282
final EventGenerator eventGenerator = CsvFileEventGenerator.create("routingKey1", 3);
8383
final String csvStr =
8484
"\"Time\",\"X\",\"Y\",\"Z\",\"IN_PROGRESS\"\n";
@@ -91,7 +91,7 @@ public void Test0by3() throws IOException {
9191
}
9292

9393
@Test
94-
public void TestEmptyFile() throws IOException {
94+
public void testEmptyFile() throws IOException {
9595
final EventGenerator eventGenerator = CsvFileEventGenerator.create("routingKey1", 3);
9696
final String csvStr = "";
9797
final CountingInputStream inputStream = new CountingInputStream(new ByteArrayInputStream(csvStr.getBytes(StandardCharsets.UTF_8)));

pravega-sensor-collector/src/test/java/io/pravega/sensor/collector/file/parquet/ParquetEventGeneratorTests.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public class ParquetEventGeneratorTests {
3434
private static final Logger LOG = LoggerFactory.getLogger(ParquetEventGeneratorTests.class);
3535

3636
@Test
37-
public void TestFile() throws IOException {
37+
public void testFile() throws IOException {
3838
final EventGenerator eventGenerator = ParquetEventGenerator.create("routingKey1",100);
3939
final List<FileNameWithOffset> files = FileUtils.getDirectoryListing("../parquet-file-sample-data","parquet", Paths.get("."), 5000);
4040
File parquetData= new File(files.get(0).fileName);

0 commit comments

Comments
 (0)