use of org.forgerock.openam.cts.CTSOperation in project OpenAM by OpenRock.
the class CTSMonitoringStoreImplTest method shouldGetAverageOperationsPerPeriodForSpecificTokenType.
@Test
public void shouldGetAverageOperationsPerPeriodForSpecificTokenType() {
//Given
TokenType tokenType = TokenType.OAUTH;
CTSOperation operation = CTSOperation.READ;
given(tokenOperationsStore.getAverageOperationsPerPeriod(tokenType, operation)).willReturn(1D);
//When
double result = ctsOperationsMonitoringStore.getAverageOperationsPerPeriod(tokenType, operation);
//Then
assertEquals(result, 1D);
}
use of org.forgerock.openam.cts.CTSOperation in project OpenAM by OpenRock.
the class OperationStoreTest method shouldGetMinimumRate.
@Test
public void shouldGetMinimumRate() {
//Given
CTSOperation operation = CTSOperation.CREATE;
OperationMonitor opRate = mock(OperationMonitor.class);
operationRate.put(operation, opRate);
given(opRate.getMinRate()).willReturn(1L);
//When
long result = operationStore.getMinRate(operation);
//Then
assertEquals(result, 1L);
}
use of org.forgerock.openam.cts.CTSOperation in project OpenAM by OpenRock.
the class OperationStoreTest method shouldOnlyAllowSingleThreadToAddOperationRateToOperationRateMap.
@Test
public void shouldOnlyAllowSingleThreadToAddOperationRateToOperationRateMap() throws InterruptedException {
//Given
final OperationMonitor opRate = mock(OperationMonitor.class);
OperationStore.OperationRateFactory operationRateFactory = new OperationStore.OperationRateFactory() {
@Override
OperationMonitor createOperationRate() {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
e.printStackTrace();
}
return opRate;
}
};
final OperationStore localOperationStore = new OperationStore(operationRateFactory, operationRate);
final CTSOperation operation = CTSOperation.CREATE;
Runnable runnable = new Runnable() {
public void run() {
localOperationStore.add(operation);
}
};
//When
Thread t1 = new Thread(runnable);
t1.setName("t1");
Thread t2 = new Thread(runnable);
t2.setName("t2");
t1.start();
t2.start();
//Then
t1.join();
t2.join();
verify(opRate, times(2)).increment();
assertEquals(operationRate.size(), 1);
}
use of org.forgerock.openam.cts.CTSOperation in project OpenAM by OpenRock.
the class OperationStoreTest method getAverageRateShouldReturnZeroIfOperationNotSet.
@Test
public void getAverageRateShouldReturnZeroIfOperationNotSet() {
//Given
CTSOperation operation = CTSOperation.CREATE;
//When
double result = operationStore.getAverageRate(operation);
//Then
assertEquals(result, 0D);
}
use of org.forgerock.openam.cts.CTSOperation in project OpenAM by OpenRock.
the class OperationStoreTest method shouldGetAverageRate.
@Test
public void shouldGetAverageRate() {
//Given
CTSOperation operation = CTSOperation.CREATE;
OperationMonitor opRate = mock(OperationMonitor.class);
operationRate.put(operation, opRate);
given(opRate.getAverageRate()).willReturn(1D);
//When
double result = operationStore.getAverageRate(operation);
//Then
assertEquals(result, 1D);
}
Aggregations