-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJTestRateLimitar.java
More file actions
71 lines (61 loc) · 1.6 KB
/
JTestRateLimitar.java
File metadata and controls
71 lines (61 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package com.cognizant.swift.processchef.webhelper;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
public class JTestRateLimitar
{
@Test
public void testvalidateReasonCode()
{
try
{
SimpleDateFormat formatter = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
Date w_date = new Date();
System.out.println("starttime:" +w_date);
System.out.println(formatter.format(w_date));
long w_startTime = w_date.getTime();
int w_startTimeIcSec = (int) System.currentTimeMillis();
for(int i=1; i<6; i++)
{
rateLimiter2(i,w_startTime);
Thread.sleep(1000);
}
Date w_date2 = new Date();
System.out.println("endtime: "+w_date2);
}
catch (Exception a_ex)
{
assertFalse(a_ex.getMessage(), true);
}
}
public static void rateLimiter2(int a_reqcount, long a_startTime) throws InterruptedException
{
int w_hitCount = 0;
int w_count = 0;
int w_nonHitCount = 0;
boolean w_isMaxLimitReached = false;
Date w_date = new Date();
long w_currenttime = w_date.getTime();
//long w_startTime1 = w_startTime;
int currentimeInSec = (int) System.currentTimeMillis();
if((w_currenttime - a_startTime) <= 3000L)
{
if (w_count < 3)
{
w_count++;
System.out.println("Called for count: " + a_reqcount );
}
else
{
System.out.println(w_currenttime - a_startTime);
Thread.sleep(3000L - (w_currenttime - a_startTime));
System.out.println("MaxLimitReached");
}
}
else
{
}
}
}