Skip to content

Commit

Permalink
Merge pull request #17 from telekom/fix/circuit-breaker
Browse files Browse the repository at this point in the history
Update lastOpened correctly
  • Loading branch information
Schnix84 authored Aug 19, 2024
2 parents 03505bf + af553d3 commit f758295
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void openCircuitBreaker(String subscriptionId, String eventType, String o
if (result.isPresent()) {
CircuitBreakerMessage existingCircuitBreakerMessage = result.get();
newCircuitBreakerMessage.setLoopCounter(existingCircuitBreakerMessage.getLoopCounter());
newCircuitBreakerMessage.setLastOpened(existingCircuitBreakerMessage.getLastOpened());
newCircuitBreakerMessage.setLastOpened(Date.from(Instant.now()));
}
circuitBreakerCache.set(subscriptionId, newCircuitBreakerMessage);
} catch (JsonCacheException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.mockito.junit.jupiter.MockitoExtension;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.Date;
import java.util.Optional;

Expand Down Expand Up @@ -59,10 +60,13 @@ void writeCircuitBreakerMessage() throws JsonCacheException {
verify(cacheService, times(1)).set(eq(ObjectGenerator.TEST_SUBSCRIPTION_ID), captor.capture());

CircuitBreakerMessage capturedMessage = captor.getValue();

// Check if the loop counter is taken from the existing circuit breaker message
assertEquals(circuitBreakerMessage.getLoopCounter(), capturedMessage.getLoopCounter());
// Check if the last opened date is taken from the existing circuit breaker message
assertEquals(circuitBreakerMessage.getLastOpened(), capturedMessage.getLastOpened());
var expectedTime = Instant.ofEpochMilli(circuitBreakerMessage.getLastOpened().getTime()).truncatedTo(ChronoUnit.SECONDS);
var actualTime = Instant.ofEpochMilli(capturedMessage.getLastOpened().getTime()).truncatedTo(ChronoUnit.SECONDS);
assertEquals(expectedTime, actualTime);
// Check if last modified was updated
assertTrue(capturedMessage.getLastModified().after(testStartDate));
}
Expand Down

0 comments on commit f758295

Please sign in to comment.