Skip to content

Commit

Permalink
Add the ability to simulate running at 00:00:00 today
Browse files Browse the repository at this point in the history
See ukf/ukf-meta#203.
This allows better run-to-run consistency so that before/after comparisons are simpler.
  • Loading branch information
iay committed Dec 2, 2019
1 parent 830c030 commit 8ca2449
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 5 deletions.
43 changes: 42 additions & 1 deletion mdx/common-beans.xml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,32 @@
Approximately when the Spring context was initialised,
as a java.time.Instant.
-->
<bean id="now_instant_raw" parent="Instant" factory-method="now"/>
<bean id="start_instant_raw" parent="Instant" factory-method="now"/>

<!--
A java.time.Instant representing 00:00:00Z today.
We use this to pin timestamps in aggregates intended for comparison.
-->
<bean id="today_instant_raw" parent="Instant" factory-method="from"
c:_="#{ start_instant_raw.truncatedTo(T(java.time.temporal.ChronoUnit).DAYS) }"/>

<!--
Select the instant to use as "now" in places like aggregate generation.
By default, this will be the time the Spring context was initialised.
This may be overridden in order to provide a stable value for
run-to-run comparisons.
Set the now.instant.raw.name to the name of the overriding value bean.
If running from build.xml using ant, this needs to be prefixed by "mda.".
Example:
ant -Dmda.now.instant.raw.name=today_instant_raw ...
-->
<bean id="now_instant_raw" parent="Instant" factory-method="from"
c:_-ref="${now.instant.raw.name:start_instant_raw}"/>

<!--
now_instant_raw can have any precision. To get somewhat consistent
Expand All @@ -180,6 +205,22 @@
c:_1="#{ T(java.time.ZoneId).systemDefault() }"/>
<bean id="now_local_ISO" parent="String" c:_="#{ now_local.toString() }"/>

<!--
Make a value for the validUntil attribute for any aggregates we
generate.
This is based on the now_instant plus a number of days specified
by the validUntil.aggregate.days property (or 14 days if for some reason
that is not defined).
Assumes that a day is exactly 86400 seconds, which is close enough for
these purposes.
-->
<bean id="validuntil_aggregate_days" class="java.lang.Integer" factory-method="parseInt"
c:_="${validUntil.aggregate.days:14}"/>
<bean id="validuntil_aggregate_ISO" parent="String"
c:_="#{ now_instant.plusSeconds(86400*validuntil_aggregate_days).toString()}"/>

<!--
***********************************************
*** ***
Expand Down
14 changes: 12 additions & 2 deletions mdx/uk/final_tweak.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,27 @@
-->
<xsl:param name="now_local_ISO"/>

<!--
valid_until_ISO
This parameter is an ISO8601 representation of the UTC instant
at which the aggregate will become invalid. This has been computed
by the caller as now_ISO + validityDays days.
-->
<xsl:param name="valid_until_ISO"/>

<!--
Document element.
-->
<xsl:template match="/md:EntitiesDescriptor">
<xsl:call-template name="document.comment">
<xsl:with-param name="validUntil" select="@validUntil"/>
<xsl:with-param name="validUntil" select="$valid_until_ISO"/>
</xsl:call-template>
<EntitiesDescriptor>
<xsl:apply-templates select="@*"/>
<xsl:attribute name="validUntil"><xsl:value-of select="$valid_until_ISO"/></xsl:attribute>
<xsl:call-template name="document.comment">
<xsl:with-param name="validUntil" select="@validUntil"/>
<xsl:with-param name="validUntil" select="$valid_until_ISO"/>
</xsl:call-template>

<!--
Expand Down
8 changes: 6 additions & 2 deletions mdx/uk/generate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,12 @@
<!--
assembleAggregate
Assemble a UK-style aggregate with an appropriate validUntil and ID.
Assemble a UK-style aggregate with an appropriate ID.
-->
<bean id="assembleAggregate" parent="mda.CompositeStage">
<property name="composedStages">
<list>
<ref bean="uk_assemble"/>
<bean parent="mda.SetValidUntilStage" p:validityDuration="${validUntil.aggregate.duration}"/>
<!--
setStaticID
Expand Down Expand Up @@ -282,6 +281,7 @@
<entry key="validityDays" value="${validUntil.aggregate.days}"/>
<entry key="now_ISO" value-ref="now_ISO"/>
<entry key="now_local_ISO" value-ref="now_local_ISO"/>
<entry key="valid_until_ISO" value-ref="validuntil_aggregate_ISO"/>
</map>
</property>
</bean>
Expand Down Expand Up @@ -438,6 +438,7 @@
<entry key="validityDays" value="${validUntil.aggregate.days}"/>
<entry key="now_ISO" value-ref="now_ISO"/>
<entry key="now_local_ISO" value-ref="now_local_ISO"/>
<entry key="valid_until_ISO" value-ref="validuntil_aggregate_ISO"/>
</map>
</property>
</bean>
Expand Down Expand Up @@ -522,6 +523,7 @@
<entry key="validityDays" value="${validUntil.aggregate.days}"/>
<entry key="now_ISO" value-ref="now_ISO"/>
<entry key="now_local_ISO" value-ref="now_local_ISO"/>
<entry key="valid_until_ISO" value-ref="validuntil_aggregate_ISO"/>
</map>
</property>
</bean>
Expand Down Expand Up @@ -581,6 +583,7 @@
<entry key="validityDays" value="${validUntil.aggregate.days}"/>
<entry key="now_ISO" value-ref="now_ISO"/>
<entry key="now_local_ISO" value-ref="now_local_ISO"/>
<entry key="valid_until_ISO" value-ref="validuntil_aggregate_ISO"/>
</map>
</property>
</bean>
Expand Down Expand Up @@ -638,6 +641,7 @@
<entry key="validityDays" value="${validUntil.aggregate.days}"/>
<entry key="now_ISO" value-ref="now_ISO"/>
<entry key="now_local_ISO" value-ref="now_local_ISO"/>
<entry key="valid_until_ISO" value-ref="validuntil_aggregate_ISO"/>
</map>
</property>
</bean>
Expand Down

0 comments on commit 8ca2449

Please sign in to comment.