@Test public void test() { try { EventRateLimiter eventRateLimiter = new EventRateLimiter(); long testStartTime = System.currentTimeMillis(); System.out.println("Starting at " + testStartTime); int approvedEventCount = 0; while (System.currentTimeMillis() < testStartTime + 60000) { if (eventRateLimiter.isOkayToFireEventNow()) { approvedEventCount++; System.out.println("Now it is "+ System.currentTimeMillis()); } } if ((approvedEventCount > 67) && (approvedEventCount < 73)) { System.out.println(String.valueOf(approvedEventCount)+ " events approved in one minute"); } else { System.out.println(String.valueOf(approvedEventCount)+" events approved in one minute is out of expected bounds"); fail(String.valueOf(approvedEventCount)+" events approved in one minute is out of expected bounds"); } } catch (Exception e) { fail("Exception occured: "+e.getMessage()); } }
public boolean isOkayToFireEventNow(){ long totalElapsedTimeNow = timeRightNow()-startTime; int currentTimeRegimeIndex = 0; for (int i=0; i<intervals.length; i++) { currentTimeRegimeIndex = i; if (totalElapsedTimeNow < intervals[i][TIME_INTERVAL_REGIME]){ break; } } if (timeSinceLastApprovedEvent() < intervals[currentTimeRegimeIndex][TIME_INTERVAL_PER_REGIME]){ return false; } else { timeOfLastEvent = timeRightNow(); return true; } }
EventRateLimiter { public boolean isOkayToFireEventNow(){ long totalElapsedTimeNow = timeRightNow()-startTime; int currentTimeRegimeIndex = 0; for (int i=0; i<intervals.length; i++) { currentTimeRegimeIndex = i; if (totalElapsedTimeNow < intervals[i][TIME_INTERVAL_REGIME]){ break; } } if (timeSinceLastApprovedEvent() < intervals[currentTimeRegimeIndex][TIME_INTERVAL_PER_REGIME]){ return false; } else { timeOfLastEvent = timeRightNow(); return true; } } }
EventRateLimiter { public boolean isOkayToFireEventNow(){ long totalElapsedTimeNow = timeRightNow()-startTime; int currentTimeRegimeIndex = 0; for (int i=0; i<intervals.length; i++) { currentTimeRegimeIndex = i; if (totalElapsedTimeNow < intervals[i][TIME_INTERVAL_REGIME]){ break; } } if (timeSinceLastApprovedEvent() < intervals[currentTimeRegimeIndex][TIME_INTERVAL_PER_REGIME]){ return false; } else { timeOfLastEvent = timeRightNow(); return true; } } EventRateLimiter(long[][] specifiedIntervals);  EventRateLimiter(); }
EventRateLimiter { public boolean isOkayToFireEventNow(){ long totalElapsedTimeNow = timeRightNow()-startTime; int currentTimeRegimeIndex = 0; for (int i=0; i<intervals.length; i++) { currentTimeRegimeIndex = i; if (totalElapsedTimeNow < intervals[i][TIME_INTERVAL_REGIME]){ break; } } if (timeSinceLastApprovedEvent() < intervals[currentTimeRegimeIndex][TIME_INTERVAL_PER_REGIME]){ return false; } else { timeOfLastEvent = timeRightNow(); return true; } } EventRateLimiter(long[][] specifiedIntervals);  EventRateLimiter(); boolean isOkayToFireEventNow(); static void main(String[] args); }
EventRateLimiter { public boolean isOkayToFireEventNow(){ long totalElapsedTimeNow = timeRightNow()-startTime; int currentTimeRegimeIndex = 0; for (int i=0; i<intervals.length; i++) { currentTimeRegimeIndex = i; if (totalElapsedTimeNow < intervals[i][TIME_INTERVAL_REGIME]){ break; } } if (timeSinceLastApprovedEvent() < intervals[currentTimeRegimeIndex][TIME_INTERVAL_PER_REGIME]){ return false; } else { timeOfLastEvent = timeRightNow(); return true; } } EventRateLimiter(long[][] specifiedIntervals);  EventRateLimiter(); boolean isOkayToFireEventNow(); static void main(String[] args);  }