Skip to content

Commit

Permalink
Bugfix/47 fix action retrier (#48)
Browse files Browse the repository at this point in the history
* Fix action retrier

* Update pom

* Update pipeline

* Fix sonar issue
  • Loading branch information
paveliam authored May 7, 2020
1 parent 9e066cb commit 118d637
Show file tree
Hide file tree
Showing 5 changed files with 169 additions and 162 deletions.
45 changes: 35 additions & 10 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,51 @@
# Maven

trigger:
- master

pool:
vmImage: 'windows-latest'

steps:
jobs:
- job: sonar
displayName: Analyse code with SonarQube

steps:
- task: SonarCloudPrepare@1
displayName: 'Prepare SonarCloud analysis'
inputs:
SonarCloud: 'SonarCloud'
organization: 'aqualityautomation'
scannerMode: 'CLI'
configMode: 'file'
extraProperties: |
sonar.coverage.exclusions=**/**
- task: Maven@3
displayName: 'Build project'
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
javaHomeOption: 'JDKVersion'
jdkVersionOption: '1.8'
jdkArchitectureOption: 'x64'
publishJUnitResults: true
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean'

- task: SonarCloudAnalyze@1
displayName: 'Run SonarCloud code analysis'
continueOnError: true

- task: SonarCloudPublish@1
displayName: 'Publish SonarCloud quality gate results'
inputs:
pollingTimeoutSec: '300'

- job: tests
displayName: Run tests

steps:
- task: ScreenResolutionUtility@1
displayName: 'Set optimal screen resolution'
inputs:
displaySettings: 'optimal'

Expand All @@ -25,6 +55,7 @@ steps:
OperationType: 'Start'

- task: Maven@3
displayName: 'Run tests'
inputs:
mavenPomFile: 'pom.xml'
mavenOptions: '-Xmx3072m'
Expand All @@ -35,13 +66,7 @@ steps:
testResultsFiles: '**/surefire-reports/TEST-*.xml'
goals: 'clean test -Dprofile=local'

- task: SonarCloudAnalyze@1

- task: SonarCloudPublish@1
inputs:
pollingTimeoutSec: '300'

- task: Windows Application Driver@0
displayName: stop WinAppDriver
displayName: 'Stop WinAppDriver'
inputs:
OperationType: 'Stop'
264 changes: 118 additions & 146 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.github.aquality-automation</groupId>
<artifactId>aquality-selenium-core</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>

<packaging>jar</packaging>
<name>Aquality Selenium Core</name>
<description>Library with core functions simplifying work with Selenium-controlled applications.</description>
<url>https://github.com/aquality-automation/aquality-selenium-core-java</url>

<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -113,155 +116,124 @@
<scope>test</scope>
</dependency>
</dependencies>
<profiles>
<profile>
<id>default</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<source>1.8</source>
<target>1.8</target>
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.4</version>
<executions>
<execution>
<id>pre-unit-test</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<destFile>${project.build.directory}/jacoco/jacoco-ut.exec</destFile>
<propertyName>surefireArgLine</propertyName>
</configuration>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
<outputDirectory>${project.build.directory}/coverage-report</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
</execution>
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<argLine>${surefireArgLine} -Dfile.encoding=UTF-8</argLine>
<reuseForks>false</reuseForks>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/TestSuite.xml</suiteXmlFile>
</suiteXmlFiles>
<dataFile>${project.build.directory}/jacoco/jacoco-ut.exec</dataFile>
<outputDirectory>${project.build.directory}/coverage-report</outputDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>${surefireArgLine} -Dfile.encoding=UTF-8</argLine>
<reuseForks>false</reuseForks>
<suiteXmlFiles>
<suiteXmlFile>src/test/resources/TestSuite.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>attached</goal>
</goals>
<phase>package</phase>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>sonar</id>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.6.0.1398</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<sonar.host.url>http://172.20.68.34:9000</sonar.host.url>
<sonar.login>a9d71a45706333578fa9d518a0aa82d89ecbe3ce</sonar.login>
<sonar.projectKey>sonar.selenium-core-java</sonar.projectKey>
<sonar.sources>src/main</sonar.sources>
<sonar.tests>src/test</sonar.tests>
<sonar.language>java</sonar.language>
<sonar.java.binaries>.</sonar.java.binaries>
<sonar.sourceEncoding>UTF-8</sonar.sourceEncoding>
</properties>
</profile>
</profiles>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.8</version>
<extensions>true</extensions>
<configuration>
<serverId>ossrh</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.google.inject.Inject;

import java.util.Collection;
import java.util.Optional;
import java.util.function.Supplier;

public class ActionRetrier implements IActionRetrier {
Expand All @@ -28,10 +27,10 @@ public void doWithRetry(Runnable runnable, Collection<Class<? extends Throwable>
@Override
public <T> T doWithRetry(Supplier<T> function, Collection<Class<? extends Throwable>> handledExceptions) {
int retryAttemptsLeft = retryConfiguration.getNumber();
Optional<T> result = Optional.empty();
T result = null;
while (retryAttemptsLeft >= 0) {
try {
result = Optional.of(function.get());
result = function.get();
break;
} catch (Exception exception) {
if (isExceptionHandled(handledExceptions, exception) && retryAttemptsLeft != 0) {
Expand All @@ -46,7 +45,7 @@ public <T> T doWithRetry(Supplier<T> function, Collection<Class<? extends Throwa
}
}
}
return result.orElse(null);
return result;
}

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

0 comments on commit 118d637

Please sign in to comment.