Skip to content

Commit 118d637

Browse files
authored
Bugfix/47 fix action retrier (#48)
* Fix action retrier * Update pom * Update pipeline * Fix sonar issue
1 parent 9e066cb commit 118d637

File tree

5 files changed

+169
-162
lines changed

5 files changed

+169
-162
lines changed

azure-pipelines.yml

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,51 @@
1-
# Maven
2-
31
trigger:
42
- master
53

64
pool:
75
vmImage: 'windows-latest'
86

9-
steps:
7+
jobs:
8+
- job: sonar
9+
displayName: Analyse code with SonarQube
10+
11+
steps:
1012
- task: SonarCloudPrepare@1
13+
displayName: 'Prepare SonarCloud analysis'
1114
inputs:
1215
SonarCloud: 'SonarCloud'
1316
organization: 'aqualityautomation'
1417
scannerMode: 'CLI'
1518
configMode: 'file'
1619
extraProperties: |
1720
sonar.coverage.exclusions=**/**
21+
22+
- task: Maven@3
23+
displayName: 'Build project'
24+
inputs:
25+
mavenPomFile: 'pom.xml'
26+
mavenOptions: '-Xmx3072m'
27+
javaHomeOption: 'JDKVersion'
28+
jdkVersionOption: '1.8'
29+
jdkArchitectureOption: 'x64'
30+
publishJUnitResults: true
31+
testResultsFiles: '**/surefire-reports/TEST-*.xml'
32+
goals: 'clean'
33+
34+
- task: SonarCloudAnalyze@1
35+
displayName: 'Run SonarCloud code analysis'
36+
continueOnError: true
37+
38+
- task: SonarCloudPublish@1
39+
displayName: 'Publish SonarCloud quality gate results'
40+
inputs:
41+
pollingTimeoutSec: '300'
42+
43+
- job: tests
44+
displayName: Run tests
45+
46+
steps:
1847
- task: ScreenResolutionUtility@1
48+
displayName: 'Set optimal screen resolution'
1949
inputs:
2050
displaySettings: 'optimal'
2151

@@ -25,6 +55,7 @@ steps:
2555
OperationType: 'Start'
2656

2757
- task: Maven@3
58+
displayName: 'Run tests'
2859
inputs:
2960
mavenPomFile: 'pom.xml'
3061
mavenOptions: '-Xmx3072m'
@@ -35,13 +66,7 @@ steps:
3566
testResultsFiles: '**/surefire-reports/TEST-*.xml'
3667
goals: 'clean test -Dprofile=local'
3768

38-
- task: SonarCloudAnalyze@1
39-
40-
- task: SonarCloudPublish@1
41-
inputs:
42-
pollingTimeoutSec: '300'
43-
4469
- task: Windows Application Driver@0
45-
displayName: stop WinAppDriver
70+
displayName: 'Stop WinAppDriver'
4671
inputs:
4772
OperationType: 'Stop'

pom.xml

Lines changed: 118 additions & 146 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6+
67
<groupId>com.github.aquality-automation</groupId>
78
<artifactId>aquality-selenium-core</artifactId>
8-
<version>1.0.0</version>
9+
<version>1.0.1</version>
10+
911
<packaging>jar</packaging>
1012
<name>Aquality Selenium Core</name>
1113
<description>Library with core functions simplifying work with Selenium-controlled applications.</description>
1214
<url>https://github.com/aquality-automation/aquality-selenium-core-java</url>
15+
1316
<properties>
1417
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
1518
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -113,155 +116,124 @@
113116
<scope>test</scope>
114117
</dependency>
115118
</dependencies>
116-
<profiles>
117-
<profile>
118-
<id>default</id>
119-
<activation>
120-
<activeByDefault>true</activeByDefault>
121-
</activation>
122-
<build>
123-
<plugins>
124-
<plugin>
125-
<groupId>org.apache.maven.plugins</groupId>
126-
<artifactId>maven-compiler-plugin</artifactId>
127-
<version>3.1</version>
119+
120+
<build>
121+
<plugins>
122+
<plugin>
123+
<groupId>org.apache.maven.plugins</groupId>
124+
<artifactId>maven-compiler-plugin</artifactId>
125+
<version>3.1</version>
126+
<configuration>
127+
<source>1.8</source>
128+
<target>1.8</target>
129+
</configuration>
130+
</plugin>
131+
<plugin>
132+
<groupId>org.jacoco</groupId>
133+
<artifactId>jacoco-maven-plugin</artifactId>
134+
<version>0.8.4</version>
135+
<executions>
136+
<execution>
137+
<id>pre-unit-test</id>
138+
<goals>
139+
<goal>prepare-agent</goal>
140+
</goals>
128141
<configuration>
129-
<source>1.8</source>
130-
<target>1.8</target>
142+
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
143+
<propertyName>surefireArgLine</propertyName>
131144
</configuration>
132-
</plugin>
133-
<plugin>
134-
<groupId>org.jacoco</groupId>
135-
<artifactId>jacoco-maven-plugin</artifactId>
136-
<version>0.8.4</version>
137-
<executions>
138-
<execution>
139-
<id>pre-unit-test</id>
140-
<goals>
141-
<goal>prepare-agent</goal>
142-
</goals>
143-
<configuration>
144-
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
145-
<propertyName>surefireArgLine</propertyName>
146-
</configuration>
147-
</execution>
148-
<execution>
149-
<id>post-unit-test</id>
150-
<phase>test</phase>
151-
<goals>
152-
<goal>report</goal>
153-
</goals>
154-
<configuration>
155-
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
156-
<outputDirectory>${project.build.directory}/coverage-report</outputDirectory>
157-
</configuration>
158-
</execution>
159-
</executions>
160-
</plugin>
161-
<plugin>
162-
<groupId>org.apache.maven.plugins</groupId>
163-
<artifactId>maven-surefire-plugin</artifactId>
164-
<version>2.20</version>
145+
</execution>
146+
<execution>
147+
<id>post-unit-test</id>
148+
<phase>test</phase>
149+
<goals>
150+
<goal>report</goal>
151+
</goals>
165152
<configuration>
166-
<argLine>${surefireArgLine} -Dfile.encoding=UTF-8</argLine>
167-
<reuseForks>false</reuseForks>
168-
<suiteXmlFiles>
169-
<suiteXmlFile>src/test/resources/TestSuite.xml</suiteXmlFile>
170-
</suiteXmlFiles>
153+
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
154+
<outputDirectory>${project.build.directory}/coverage-report</outputDirectory>
171155
</configuration>
172-
</plugin>
173-
<plugin>
174-
<groupId>org.apache.maven.plugins</groupId>
175-
<artifactId>maven-assembly-plugin</artifactId>
176-
<executions>
177-
<execution>
178-
<goals>
179-
<goal>attached</goal>
180-
</goals>
181-
<phase>package</phase>
182-
<configuration>
183-
<descriptorRefs>
184-
<descriptorRef>jar-with-dependencies</descriptorRef>
185-
</descriptorRefs>
186-
</configuration>
187-
</execution>
188-
</executions>
189-
</plugin>
190-
<plugin>
191-
<groupId>org.apache.maven.plugins</groupId>
192-
<artifactId>maven-source-plugin</artifactId>
193-
<executions>
194-
<execution>
195-
<id>attach-sources</id>
196-
<goals>
197-
<goal>jar</goal>
198-
</goals>
199-
</execution>
200-
</executions>
201-
</plugin>
202-
<plugin>
203-
<groupId>org.apache.maven.plugins</groupId>
204-
<artifactId>maven-javadoc-plugin</artifactId>
205-
<executions>
206-
<execution>
207-
<id>attach-javadocs</id>
208-
<goals>
209-
<goal>jar</goal>
210-
</goals>
211-
</execution>
212-
</executions>
213-
</plugin>
214-
<plugin>
215-
<groupId>org.apache.maven.plugins</groupId>
216-
<artifactId>maven-gpg-plugin</artifactId>
217-
<version>1.6</version>
218-
<executions>
219-
<execution>
220-
<id>sign-artifacts</id>
221-
<phase>verify</phase>
222-
<goals>
223-
<goal>sign</goal>
224-
</goals>
225-
</execution>
226-
</executions>
227-
</plugin>
228-
<plugin>
229-
<groupId>org.sonatype.plugins</groupId>
230-
<artifactId>nexus-staging-maven-plugin</artifactId>
231-
<version>1.6.8</version>
232-
<extensions>true</extensions>
156+
</execution>
157+
</executions>
158+
</plugin>
159+
<plugin>
160+
<groupId>org.apache.maven.plugins</groupId>
161+
<artifactId>maven-surefire-plugin</artifactId>
162+
<version>2.20</version>
163+
<configuration>
164+
<argLine>${surefireArgLine} -Dfile.encoding=UTF-8</argLine>
165+
<reuseForks>false</reuseForks>
166+
<suiteXmlFiles>
167+
<suiteXmlFile>src/test/resources/TestSuite.xml</suiteXmlFile>
168+
</suiteXmlFiles>
169+
</configuration>
170+
</plugin>
171+
<plugin>
172+
<groupId>org.apache.maven.plugins</groupId>
173+
<artifactId>maven-assembly-plugin</artifactId>
174+
<executions>
175+
<execution>
176+
<goals>
177+
<goal>attached</goal>
178+
</goals>
179+
<phase>package</phase>
233180
<configuration>
234-
<serverId>ossrh</serverId>
235-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
236-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
181+
<descriptorRefs>
182+
<descriptorRef>jar-with-dependencies</descriptorRef>
183+
</descriptorRefs>
237184
</configuration>
238-
</plugin>
239-
</plugins>
240-
</build>
241-
</profile>
242-
<profile>
243-
<id>sonar</id>
244-
<build>
245-
<pluginManagement>
246-
<plugins>
247-
<plugin>
248-
<groupId>org.sonarsource.scanner.maven</groupId>
249-
<artifactId>sonar-maven-plugin</artifactId>
250-
<version>3.6.0.1398</version>
251-
</plugin>
252-
</plugins>
253-
</pluginManagement>
254-
</build>
255-
<properties>
256-
<sonar.host.url>http://172.20.68.34:9000</sonar.host.url>
257-
<sonar.login>a9d71a45706333578fa9d518a0aa82d89ecbe3ce</sonar.login>
258-
<sonar.projectKey>sonar.selenium-core-java</sonar.projectKey>
259-
<sonar.sources>src/main</sonar.sources>
260-
<sonar.tests>src/test</sonar.tests>
261-
<sonar.language>java</sonar.language>
262-
<sonar.java.binaries>.</sonar.java.binaries>
263-
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
264-
</properties>
265-
</profile>
266-
</profiles>
185+
</execution>
186+
</executions>
187+
</plugin>
188+
<plugin>
189+
<groupId>org.apache.maven.plugins</groupId>
190+
<artifactId>maven-source-plugin</artifactId>
191+
<executions>
192+
<execution>
193+
<id>attach-sources</id>
194+
<goals>
195+
<goal>jar</goal>
196+
</goals>
197+
</execution>
198+
</executions>
199+
</plugin>
200+
<plugin>
201+
<groupId>org.apache.maven.plugins</groupId>
202+
<artifactId>maven-javadoc-plugin</artifactId>
203+
<executions>
204+
<execution>
205+
<id>attach-javadocs</id>
206+
<goals>
207+
<goal>jar</goal>
208+
</goals>
209+
</execution>
210+
</executions>
211+
</plugin>
212+
<plugin>
213+
<groupId>org.apache.maven.plugins</groupId>
214+
<artifactId>maven-gpg-plugin</artifactId>
215+
<version>1.6</version>
216+
<executions>
217+
<execution>
218+
<id>sign-artifacts</id>
219+
<phase>verify</phase>
220+
<goals>
221+
<goal>sign</goal>
222+
</goals>
223+
</execution>
224+
</executions>
225+
</plugin>
226+
<plugin>
227+
<groupId>org.sonatype.plugins</groupId>
228+
<artifactId>nexus-staging-maven-plugin</artifactId>
229+
<version>1.6.8</version>
230+
<extensions>true</extensions>
231+
<configuration>
232+
<serverId>ossrh</serverId>
233+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
234+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
235+
</configuration>
236+
</plugin>
237+
</plugins>
238+
</build>
267239
</project>

src/main/java/aquality/selenium/core/utilities/ActionRetrier.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import com.google.inject.Inject;
55

66
import java.util.Collection;
7-
import java.util.Optional;
87
import java.util.function.Supplier;
98

109
public class ActionRetrier implements IActionRetrier {
@@ -28,10 +27,10 @@ public void doWithRetry(Runnable runnable, Collection<Class<? extends Throwable>
2827
@Override
2928
public <T> T doWithRetry(Supplier<T> function, Collection<Class<? extends Throwable>> handledExceptions) {
3029
int retryAttemptsLeft = retryConfiguration.getNumber();
31-
Optional<T> result = Optional.empty();
30+
T result = null;
3231
while (retryAttemptsLeft >= 0) {
3332
try {
34-
result = Optional.of(function.get());
33+
result = function.get();
3534
break;
3635
} catch (Exception exception) {
3736
if (isExceptionHandled(handledExceptions, exception) && retryAttemptsLeft != 0) {
@@ -46,7 +45,7 @@ public <T> T doWithRetry(Supplier<T> function, Collection<Class<? extends Throwa
4645
}
4746
}
4847
}
49-
return result.orElse(null);
48+
return result;
5049
}
5150

5251
protected boolean isExceptionHandled(Collection<Class<? extends Throwable>> handledExceptions, Exception exception) {

0 commit comments

Comments
 (0)