Skip to content

Commit

Permalink
Mockable time in messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Tristan-WorkGH committed Jun 20, 2024
1 parent 4b94c66 commit 403bacd
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Clock;

@Configuration
public class ComputationConfig {
@Bean
public Jackson2ObjectMapperBuilderCustomizer jsonCustomizer() {
return builder -> builder.modulesToInstall(new ReportNodeJsonModule())
.postConfigurer(objMapper -> objMapper.setInjectableValues(new InjectableValues.Std().addValue(ReportNodeDeserializer.DICTIONARY_VALUE_ID, null)));
}

@Bean
public Clock clock() {
return Clock.systemUTC();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageHeaders;
import org.springframework.messaging.support.MessageBuilder;

import javax.annotation.Nullable;
import java.io.UncheckedIOException;
import java.time.Clock;
import java.util.Map;
import java.util.Objects;
import java.util.UUID;
Expand Down Expand Up @@ -50,7 +53,7 @@ protected AbstractResultContext(UUID resultUuid, R runContext) {
this.runContext = Objects.requireNonNull(runContext);
}

public Message<String> toMessage(ObjectMapper objectMapper) {
public Message<String> toMessage(@Nullable final Clock clock, @Nullable final ObjectMapper objectMapper) {
String parametersJson = "";
if (objectMapper != null) {
try {
Expand All @@ -59,7 +62,11 @@ public Message<String> toMessage(ObjectMapper objectMapper) {
throw new UncheckedIOException(e);
}
}
return MessageBuilder.withPayload(parametersJson)
MessageBuilder<String> messageBuilder = MessageBuilder.withPayload(parametersJson);
if (clock != null) {
messageBuilder.setHeader(MessageHeaders.TIMESTAMP, clock.millis());
}
return messageBuilder
.setHeader(RESULT_UUID_HEADER, resultUuid.toString())
.setHeader(NETWORK_UUID_HEADER, runContext.getNetworkUuid().toString())
.setHeader(VARIANT_ID_HEADER, runContext.getVariantId())
Expand Down

0 comments on commit 403bacd

Please sign in to comment.