-
- for(int i=1;i<11;i++){
- // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
- // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
- doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(commitSnapshot).getValue(i * 0.1);
- }
-
-
- TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
- commitCallback.run();
- commitCallback.success();
-
- verify(actorContext).setTxCreationLimit(Matchers.doubleThat(approximately(292)));
- }
-
- @Test
- public void testSuccessPercentileValueZero(){
-
- for(int i=1;i<11;i++){
- // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
- // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
- doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(commitSnapshot).getValue(i * 0.1);
- }
-
- doReturn(TimeUnit.MILLISECONDS.toNanos(0) * 1D).when(commitSnapshot).getValue(0.1);
-
- TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
- commitCallback.run();
- commitCallback.success();
-
- verify(actorContext).setTxCreationLimit(Matchers.doubleThat(approximately(192)));
- }
-
- @Test
- public void testSuccessOnePercentileValueVeryHigh(){
-
- for(int i=1;i<11;i++){
- // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
- // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
- doReturn(TimeUnit.MILLISECONDS.toNanos(i) * 1D).when(commitSnapshot).getValue(i * 0.1);
- }
-
- // ten seconds
- doReturn(TimeUnit.MILLISECONDS.toNanos(10000) * 1D).when(commitSnapshot).getValue(1.0);
-
- TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
- commitCallback.run();
- commitCallback.success();
-
- verify(actorContext).setTxCreationLimit(Matchers.doubleThat(approximately(282)));
- }
-
- @Test
- public void testSuccessWithAllPercentileValueVeryHigh(){
-
- for(int i=1;i<11;i++){
- // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
- // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
- doReturn(TimeUnit.MILLISECONDS.toNanos(10000) * 1D).when(commitSnapshot).getValue(i * 0.1);
- }
-
- TransactionRateLimitingCallback commitCallback = new TransactionRateLimitingCallback(actorContext);
- commitCallback.run();
- commitCallback.success();
-
- verify(actorContext).setTxCreationLimit(Matchers.doubleThat(approximately(0)));
- }
-
- @Test
- public void testSuccessWithRealPercentileValues(){
-
- for(int i=1;i<11;i++){
- // Keep on increasing the amount of time it takes to complete transaction for each tenth of a
- // percentile. Essentially this would be 1ms for the 10th percentile, 2ms for 20th percentile and so on.
- doReturn(TimeUnit.MILLISECONDS.toNanos(8) * 1D).when(commitSnapshot).getValue(i * 0.1);
- }
-
- doReturn(TimeUnit.MILLISECONDS.toNanos(20) * 1D).when(commitSnapshot).getValue( 0.7);
- doReturn(TimeUnit.MILLISECONDS.toNanos(100) * 1D).when(commitSnapshot).getValue( 0.9);
- doReturn(TimeUnit.MILLISECONDS.toNanos(200) * 1D).when(commitSnapshot).getValue( 1.0);
-