-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix/adapt chunking implementation to fix wrong chunk size based on…
… utf8 strings (#107) * Adapt release version. Change owner of the assembly. * Adapt release version to prepare release 3.1.0 * Adapt chunking implementation and chunk based on the byte[]. Adapt test case to real outcome checking. * Remove abstract parameter class from payload parameters to decrease clutter. * Add raw data fetching for data provider. * Reduce logging for test cases. * Change name to make the functionality a little more obvious. * Changed implementation order. * ... * ...
- Loading branch information
1 parent
efceca1
commit ca99b16
Showing
14 changed files
with
219 additions
and
42 deletions.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
agrirouter-sdk-dotnet-standard-api/Service/Messaging/ICancellationToken.cs
This file contains 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,24 @@ | ||
namespace Agrirouter.Api.Service.Messaging | ||
{ | ||
/// <summary> | ||
/// An implementation for a cancellation token to run multiple attempts for fetching messages. | ||
/// </summary> | ||
public interface ICancellationToken | ||
{ | ||
/// <summary> | ||
/// Signal for the polling process to cancel the polling. | ||
/// </summary> | ||
/// <returns>true if the polling can be cancelled, false otherwise.</returns> | ||
bool IsNotCancelled(); | ||
|
||
/// <summary> | ||
/// Will wait a dedicated amount of time before starting the next step if the token is not cancelled. | ||
/// </summary> | ||
void WaitIfNotCancelled(); | ||
|
||
/// <summary> | ||
/// Will be called after one step of the polling is completed and the next step is about to start. | ||
/// </summary> | ||
void NextStep(); | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
40 changes: 40 additions & 0 deletions
40
...-sdk-dotnet-standard-impl/Service/Messaging/CancellationToken/DefaultCancellationToken.cs
This file contains 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,40 @@ | ||
using System.Threading; | ||
using Agrirouter.Api.Service.Messaging; | ||
|
||
namespace Agrirouter.Impl.Service.Messaging.CancellationToken | ||
{ | ||
/// <summary> | ||
/// A default implementation, based on tries and waiting time. | ||
/// </summary> | ||
public class DefaultCancellationToken : ICancellationToken | ||
{ | ||
private readonly int _maxTries; | ||
private readonly int _waitTimeInMilliseconds; | ||
|
||
private int _nrOfRetries = 0; | ||
|
||
public DefaultCancellationToken(int maxTries, int waitTimeInMilliseconds) | ||
{ | ||
_maxTries = maxTries; | ||
_waitTimeInMilliseconds = waitTimeInMilliseconds; | ||
} | ||
|
||
public bool IsNotCancelled() | ||
{ | ||
return _nrOfRetries < _maxTries; | ||
} | ||
|
||
public void WaitIfNotCancelled() | ||
{ | ||
if (IsNotCancelled()) | ||
{ | ||
Thread.Sleep(_waitTimeInMilliseconds); | ||
} | ||
} | ||
|
||
public void NextStep() | ||
{ | ||
_nrOfRetries++; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
38 changes: 38 additions & 0 deletions
38
agrirouter-sdk-dotnet-standard-test/Service/Messaging/Http/CancellationTokenTest.cs
This file contains 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,38 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using Agrirouter.Request.Payload.Endpoint; | ||
using Agrirouter.Api.Dto.Onboard; | ||
using Agrirouter.Api.Service.Parameters; | ||
using Agrirouter.Api.Service.Parameters.Inner; | ||
using Agrirouter.Impl.Service.Common; | ||
using Agrirouter.Impl.Service.Messaging; | ||
using Agrirouter.Impl.Service.Messaging.CancellationToken; | ||
using Agrirouter.Test.Data; | ||
using Agrirouter.Test.Helper; | ||
using Xunit; | ||
|
||
namespace Agrirouter.Test.Service.Messaging.Http | ||
{ | ||
/// <summary> | ||
/// Functional tests. | ||
/// </summary> | ||
[Collection("Integrationtest")] | ||
public class CancellationTokenTest : AbstractIntegrationTestForCommunicationUnits | ||
{ | ||
private static readonly HttpClient HttpClient = HttpClientFactory.AuthenticatedHttpClient(OnboardResponse); | ||
|
||
private static OnboardResponse OnboardResponse => | ||
OnboardResponseIntegrationService.Read(Identifier.Http.CommunicationUnit.SingleEndpointWithP12Certificate); | ||
|
||
[Fact(Timeout = 1600)] | ||
public void | ||
GivenDefaultCancellationTokenWhenFetchingMessagesTheCancellationTokenShouldBeCancelledAfterCertainRetries() | ||
{ | ||
var fetchMessageService = new FetchMessageService(HttpClient); | ||
var fetch = fetchMessageService.Fetch(OnboardResponse, new DefaultCancellationToken(3, 500)); | ||
Assert.Empty(fetch); | ||
} | ||
} | ||
} |
Oops, something went wrong.