Skip to content

Commit

Permalink
#399 - use only one tck timeout config. Rename it for clarity. Move d…
Browse files Browse the repository at this point in the history
…ocumentation to running_the_tck doc.

Signed-off-by: brunobat <brunobat@gmail.com>
  • Loading branch information
brunobat committed Jun 12, 2019
1 parent 5b39387 commit 18d1659
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 46 deletions.
20 changes: 0 additions & 20 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -127,26 +127,6 @@ public class FaultToleranceBean {
}
}
```
##### Timeout Configs
Since v2.1 we can configure the existing test timeouts. With the following configurations, timeouts can be greatly
reduced for local usage or in fast CI environments.

The properties can be set either with MP Config or System Properties.

.TCK Timeout configs
|===
|Property |Default |unit

|org.eclipse.microprofile.fault.tolerance.basetimeout
|100
|ms

|org.eclipse.microprofile.fault.tolerance.basemultiplier
|10
|Dimensionless
|===


## Impact on existing code

n/a
Expand Down
18 changes: 18 additions & 0 deletions tck/running_the_tck.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,21 @@ Once you've added the dependency, you don't need a `tck-suite.xml` you can just
</plugins>
</build>
----
## Timeout Configs
We can configure the existing tck test timeouts. With the following configurations, timeouts can be greatly
reduced for use in local executions or in fast CI environments.

The property is a multiplier applied to all timeouts linearly, namely @Timeout annotation values, workload simulations
and test assertions.

.TCK Timeout config
|===
|Property |Default |Unit

|org.eclipse.microprofile.fault.tolerance.tck.timeout.multiplier
|1.0
|Dimensionless double
|===

The property can be set either with MP Config or System Properties.
Example:
Original file line number Diff line number Diff line change
Expand Up @@ -26,41 +26,30 @@

public class TCKConfig {

private static final int DEFAULT_TIMEOUT = 1000;
private static final TCKConfig INSTANCE = new TCKConfig();

public static TCKConfig getConfig() {
return INSTANCE;
}

private long baseTimeout;

private int baseMultiplier;
private double baseMultiplier;

private TCKConfig() {
try {
final Config config = ConfigProvider.getConfig();
baseTimeout = config
.getOptionalValue("org.eclipse.microprofile.fault.tolerance.basetimeout", Long.class)
.orElse(100L);
baseMultiplier = config
.getOptionalValue("org.eclipse.microprofile.fault.tolerance.basemultiplier", Integer.class)
.orElse(10);
.getOptionalValue("org.eclipse.microprofile.fault.tolerance.tck.timeout.multiplier", Double.class)
.orElse(1.0D);
}
catch (Exception e) {
System.out.println("Could not use microprofile config. Falling back to system properties. Problem:" + e.getMessage());
baseTimeout = Long.valueOf(
System.getProperty("org.eclipse.microprofile.fault.tolerance.basetimeout", "100"));
baseMultiplier = Integer.valueOf(
System.getProperty("org.eclipse.microprofile.fault.tolerance.basemultiplier", "10"));
baseMultiplier = Double.valueOf(
System.getProperty("org.eclipse.microprofile.fault.tolerance.tck.timeout.multiplier", "1.0"));
}
if (baseMultiplier <= 0) {
throw new IllegalArgumentException("baseMultiplier must be a positive number. Was set to: " + baseMultiplier);
}
}

/**
* The base timeout serves as the base multiplier for all timeouts and is expressed in milliseconds.
* Must not be less than 10ms.
*/
public long getBaseTimeout() {
return baseTimeout;
}

/**
Expand All @@ -69,7 +58,7 @@ public long getBaseTimeout() {
* @return
*/
public String getTimeoutInStr() {
return String.valueOf(getTimeoutInMillis(1000));
return String.valueOf(getTimeoutInMillis(DEFAULT_TIMEOUT));
}

public String getTimeoutInStr(final int originalInMillis) {
Expand All @@ -81,10 +70,7 @@ public long getTimeoutInMillis(final int originalInMillis) {
}

public long getTimeoutInMillis(final long originalInMillis) {
if (originalInMillis < baseTimeout) {
throw new IllegalArgumentException("Timeout must be bigger than " + baseTimeout + "ms, the baseTimeout.");
}
final float offset = Float.valueOf(originalInMillis) / 1000;
final double offset = Double.valueOf(originalInMillis) / DEFAULT_TIMEOUT;
return Math.round(getTimeoutInMillis() * offset);
}

Expand All @@ -98,7 +84,7 @@ public Duration getTimeoutInDuration(final int originalInMillis) {
* @return
*/
public long getTimeoutInMillis() {
return baseTimeout * baseMultiplier;
return Math.round(DEFAULT_TIMEOUT * baseMultiplier);
}

}

0 comments on commit 18d1659

Please sign in to comment.