bump the version
[dmaap/messagerouter/msgrtr.git] / src / test / java / com / att / nsa / cambria / CambriaRateLimiterTest.java
1 /*******************************************************************************
2  *  ============LICENSE_START=======================================================
3  *  org.onap.dmaap
4  *  ================================================================================
5  *  Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  *  ================================================================================
7  *  Licensed under the Apache License, Version 2.0 (the "License");
8  *  you may not use this file except in compliance with the License.
9  *  You may obtain a copy of the License at
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *  
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *  ============LICENSE_END=========================================================
18  *
19  *  ECOMP is a trademark and service mark of AT&T Intellectual Property.
20  *  
21  *******************************************************************************/
22 package com.att.nsa.cambria;
23
24 import junit.framework.TestCase;
25
26 import org.junit.Test;
27
28 import com.att.nsa.apiServer.util.NsaTestClock;
29
30 public class CambriaRateLimiterTest 
31 {
32         @Test
33         public void testRateLimiter ()
34         {
35                 /*final NsaTestClock clock = new NsaTestClock(1, false);
36
37                 final String topic = "topic";
38                 final String consumerGroup = "group";
39                 final String clientId = "id";
40
41                 final int window = 5;
42
43                 // rate limit: 1 empty call/min avg over 5 minutes, with 10ms delay
44                 final CambriaRateLimiter rater = new CambriaRateLimiter ( 1.0, window, 10 );
45                 try
46                 {
47                         // prime with a call to start rate window
48                         rater.onCall ( topic, consumerGroup, clientId );
49                         rater.onSend ( topic, consumerGroup, clientId, 1 );
50                         clock.addMs ( 1000*60*window );
51
52                         // rate should now be 0, with a good window
53                         for ( int i=0; i<4; i++ )
54                         {
55                                 clock.addMs ( 1000*15 );
56                                 rater.onCall ( topic, consumerGroup, clientId );
57                                 rater.onSend ( topic, consumerGroup, clientId, 0 );
58                         }
59                         // rate is now 0.8 = 4 calls in last 5 minutes = 4/5 = 0.8
60
61                         clock.addMs ( 1000*15 );
62                         rater.onCall ( topic, consumerGroup, clientId );
63                         rater.onSend ( topic, consumerGroup, clientId, 0 );
64                                 // rate = 1.0 = 5 calls in last 5 mins
65
66                         clock.addMs ( 1000 );
67                         rater.onCall ( topic, consumerGroup, clientId );
68                         rater.onSend ( topic, consumerGroup, clientId, 0 );
69                                 // rate = 1.2 = 6 calls in last 5 mins, should fire
70
71                         fail ( "Should have thrown rate limit exception." );
72                 }
73                 catch ( CambriaApiException x )
74                 {
75                         // good
76                 }*/
77         }
78 }