Search in sources :

Example 11 with Permit

use of org.opensmartgridplatform.throttling.api.Permit in project open-smart-grid-platform by OSGP.

the class ThrottlingClientTest method clientReleasesPermitForNetworkSegment.

@Test
void clientReleasesPermitForNetworkSegment() {
    final short throttlingConfigId = 901;
    final int clientId = 4518988;
    final int baseTransceiverStationId = 10029;
    final int cellId = 1;
    final int requestId = 23938477;
    this.whenTheThrottlingConfigIsIdentifiedById(throttlingConfigId);
    this.whenTheThrottlingClientHasRegisteredWithId(clientId);
    this.whenTheThrottlingServiceReleasesThePermit(throttlingConfigId, clientId, baseTransceiverStationId, cellId, requestId, true);
    final Permit permitToBeReleased = new Permit(throttlingConfigId, clientId, requestId, baseTransceiverStationId, cellId, Instant.now().minusSeconds(3));
    final boolean released = this.throttlingClient.releasePermit(permitToBeReleased);
    assertThat(released).isTrue();
}
Also used : Permit(org.opensmartgridplatform.throttling.api.Permit) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 12 with Permit

use of org.opensmartgridplatform.throttling.api.Permit in project open-smart-grid-platform by OSGP.

the class ThrottlingClientTest method unregisteredClientRequestsPermitByNetworkSegment.

@Test
void unregisteredClientRequestsPermitByNetworkSegment() {
    final short throttlingConfigId = 37;
    final int clientId = 347198;
    final int baseTransceiverStationId = 983745;
    final int cellId = 2;
    final int requestId = 894;
    this.whenTheThrottlingClientUsesNextRequestId(requestId);
    this.whenTheThrottlingServiceGrantsTheRequestedPermit(throttlingConfigId, clientId, baseTransceiverStationId, cellId, requestId);
    final Permit expectedPermit = new Permit(throttlingConfigId, clientId, requestId, baseTransceiverStationId, cellId, null);
    final Optional<Permit> requestedPermit = this.throttlingClient.requestPermit(baseTransceiverStationId, cellId);
    assertThat(requestedPermit).usingRecursiveComparison().ignoringExpectedNullFields().isEqualTo(Optional.of(expectedPermit));
}
Also used : Permit(org.opensmartgridplatform.throttling.api.Permit) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Permit (org.opensmartgridplatform.throttling.api.Permit)12 Test (org.junit.jupiter.api.Test)8 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)8 Instant (java.time.Instant)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 IOException (java.io.IOException)1 JMSException (javax.jms.JMSException)1 DlmsConnection (org.openmuc.jdlms.DlmsConnection)1 ConnectionTaskException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ConnectionTaskException)1 DeviceKeyProcessAlreadyRunningException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.DeviceKeyProcessAlreadyRunningException)1 NonRetryableException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.NonRetryableException)1 ProtocolAdapterException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.ProtocolAdapterException)1 RecoverKeyException (org.opensmartgridplatform.adapter.protocol.dlms.exceptions.RecoverKeyException)1 InvocationCountingDlmsMessageListener (org.opensmartgridplatform.adapter.protocol.dlms.infra.messaging.InvocationCountingDlmsMessageListener)1 FunctionalException (org.opensmartgridplatform.shared.exceptionhandling.FunctionalException)1 OsgpException (org.opensmartgridplatform.shared.exceptionhandling.OsgpException)1 ThrottlingPermitDeniedException (org.opensmartgridplatform.throttling.ThrottlingPermitDeniedException)1