This repository was archived by the owner on May 8, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Feature/add sequence numbering for missing sequence numbers #138
Merged
saschadoemer
merged 3 commits into
develop
from
feature/add_sequence_numbering_for_missing_sequence_numbers
Nov 28, 2020
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 16 additions & 17 deletions
33
...r-api-java-api/src/main/java/com/dke/data/agrirouter/api/exception/RevokingException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,27 +1,26 @@ | ||
| package com.dke.data.agrirouter.api.exception; | ||
|
|
||
| import com.dke.data.agrirouter.api.dto.revoke.RevokingError; | ||
|
|
||
| import java.util.Optional; | ||
|
|
||
| public class RevokingException extends RuntimeException { | ||
| private final RevokingError revokingError; | ||
| private final RevokingError revokingError; | ||
|
|
||
| @SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
| public RevokingException(Optional<RevokingError> lastError) { | ||
| this.revokingError = lastError.orElse(null); | ||
| } | ||
| @SuppressWarnings("OptionalUsedAsFieldOrParameterType") | ||
| public RevokingException(Optional<RevokingError> lastError) { | ||
| this.revokingError = lastError.orElse(null); | ||
| } | ||
|
|
||
| public RevokingError getRevokingError() { | ||
| return revokingError; | ||
| } | ||
| public RevokingError getRevokingError() { | ||
| return revokingError; | ||
| } | ||
|
|
||
| @Override | ||
| public String getMessage() { | ||
| return null != revokingError | ||
| ? String.format( | ||
| "There was an error '%s' during the revoking, details were '%s'", | ||
| revokingError.getError().getCode(), revokingError.getError().message) | ||
| : "There was an error during the revoking process."; | ||
| } | ||
| @Override | ||
| public String getMessage() { | ||
| return null != revokingError | ||
| ? String.format( | ||
| "There was an error '%s' during the revoking, details were '%s'", | ||
| revokingError.getError().getCode(), revokingError.getError().message) | ||
| : "There was an error during the revoking process."; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...java-impl/src/main/java/com/dke/data/agrirouter/impl/messaging/SequenceNumberService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.dke.data.agrirouter.impl.messaging; | ||
|
|
||
| import com.dke.data.agrirouter.api.dto.onboard.OnboardingResponse; | ||
| import java.util.concurrent.ConcurrentHashMap; | ||
|
|
||
| /** | ||
| * Service to generate sequence numbers while sending messages to the agrirouter. The sequence | ||
| * number generation is based on the ID of the endpoint, therefore a sequence number can be used | ||
| * multiple times for different endpoints. | ||
| */ | ||
| public class SequenceNumberService { | ||
|
|
||
| private static final ConcurrentHashMap<String, Long> sequenceNumbersForEndpoints = | ||
| new ConcurrentHashMap<>(); | ||
|
|
||
| /** | ||
| * Generate the sequence number for the onboarding response. | ||
| * | ||
| * @param onboardingResponse - | ||
| * @return 1 if this was the first call, 1+n for the n-th call. | ||
| */ | ||
| public static synchronized long generateSequenceNumberForEndpoint( | ||
| OnboardingResponse onboardingResponse) { | ||
| sequenceNumbersForEndpoints.putIfAbsent(onboardingResponse.getSensorAlternateId(), 1L); | ||
| Long currentSequenceNumber = | ||
| sequenceNumbersForEndpoints.get(onboardingResponse.getSensorAlternateId()); | ||
| sequenceNumbersForEndpoints.put( | ||
| onboardingResponse.getSensorAlternateId(), currentSequenceNumber + 1); | ||
| return currentSequenceNumber; | ||
| } | ||
| } |
67 changes: 67 additions & 0 deletions
67
...-impl/src/test/java/com/dke/data/agrirouter/impl/messaging/SequenceNumberServiceTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| package com.dke.data.agrirouter.impl.messaging; | ||
|
|
||
| import com.dke.data.agrirouter.api.dto.onboard.OnboardingResponse; | ||
| import org.junit.jupiter.api.Assertions; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class SequenceNumberServiceTest { | ||
|
|
||
| @Test | ||
| void givenOnboardingResponseWhenGeneratingSequenceNumberForTheFirstTimeThenTheResultShouldBe1() { | ||
| OnboardingResponse onboardingResponse = new OnboardingResponse(); | ||
| onboardingResponse.setSensorAlternateId("this-is-my-id"); | ||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(onboardingResponse)); | ||
| } | ||
|
|
||
| @Test | ||
| void | ||
| givenOnboardingResponseWhenGeneratingSequenceNumberForTwoTimesInARowThenTheResultShouldBe1And2() { | ||
| OnboardingResponse onboardingResponse = new OnboardingResponse(); | ||
| onboardingResponse.setSensorAlternateId("this-is-another-id"); | ||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(onboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 2, SequenceNumberService.generateSequenceNumberForEndpoint(onboardingResponse)); | ||
| } | ||
|
|
||
| @Test | ||
| void | ||
| givenTwoOnboardingResponsesWhenGeneratingSequenceNumberForTheFirstTimeThenTheResultShouldBe1ForBoth() { | ||
| OnboardingResponse firstOnboardingResponse = new OnboardingResponse(); | ||
| firstOnboardingResponse.setSensorAlternateId("this-is-the-first-id"); | ||
| OnboardingResponse secondOnboardingResponse = new OnboardingResponse(); | ||
| secondOnboardingResponse.setSensorAlternateId("this-is-the-second-id"); | ||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(secondOnboardingResponse)); | ||
| } | ||
|
|
||
| @Test | ||
| void | ||
| givenTwoOnboardingResponsesWhenGeneratingSequenceNumberForMultipleTimesThenTheResultShouldBeMatchingTheTimesTheMethodWasCalled() { | ||
| OnboardingResponse firstOnboardingResponse = new OnboardingResponse(); | ||
| firstOnboardingResponse.setSensorAlternateId("this-is-the-first-id-for-multiple-calls"); | ||
| OnboardingResponse secondOnboardingResponse = new OnboardingResponse(); | ||
| secondOnboardingResponse.setSensorAlternateId("this-is-the-second-id-multiple-calls"); | ||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 2, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 3, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 4, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
|
|
||
| Assertions.assertEquals( | ||
| 1, SequenceNumberService.generateSequenceNumberForEndpoint(secondOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 2, SequenceNumberService.generateSequenceNumberForEndpoint(secondOnboardingResponse)); | ||
| Assertions.assertEquals( | ||
| 3, SequenceNumberService.generateSequenceNumberForEndpoint(secondOnboardingResponse)); | ||
|
|
||
| Assertions.assertEquals( | ||
| 5, SequenceNumberService.generateSequenceNumberForEndpoint(firstOnboardingResponse)); | ||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.