diff options
author | sunil.unnava <sunil.unnava@att.com> | 2019-04-03 00:41:55 -0400 |
---|---|---|
committer | sunil.unnava <sunil.unnava@att.com> | 2019-04-03 00:43:04 -0400 |
commit | 34615204bca86d54ebfbedb15e8976515688c56c (patch) | |
tree | 7ff972385359fe1a4d64fbc52bbc069b9301d618 | |
parent | 49924c6b07a7f9418f04d09f9c94fac8e7d44485 (diff) |
add testcases
Issue-ID: DMAAP-1140
Change-Id: I249cf7b1b7f0692de224aee9b33aab8dbab20054
Signed-off-by: sunil.unnava <sunil.unnava@att.com>
5 files changed, 84 insertions, 61 deletions
diff --git a/src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPCambriaLimiter.java b/src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPCambriaLimiter.java index 2091e5f..f645c8d 100644 --- a/src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPCambriaLimiter.java +++ b/src/main/java/org/onap/dmaap/dmf/mr/beans/DMaaPCambriaLimiter.java @@ -52,7 +52,6 @@ import com.att.nsa.metrics.impl.CdmRateTicker; @Component public class DMaaPCambriaLimiter { private final HashMap<String, RateInfo> fRateInfo; - private final HashMap<String, RateInfoCheck> fRateInfoCheck; private final double fMaxEmptyPollsPerMinute; private final double fMaxPollsPerMinute; private final int fWindowLengthMins; @@ -70,7 +69,6 @@ public class DMaaPCambriaLimiter { @Autowired public DMaaPCambriaLimiter(@Qualifier("propertyReader") rrNvReadable settings) { fRateInfo = new HashMap<>(); - fRateInfoCheck = new HashMap<>(); fMaxEmptyPollsPerMinute = settings.getDouble(CambriaConstants.kSetting_MaxEmptyPollsPerMinute, CambriaConstants.kDefault_MaxEmptyPollsPerMinute); fMaxPollsPerMinute = settings.getDouble(CambriaConstants.kSetting_MaxPollsPerMinute, @@ -105,7 +103,6 @@ public class DMaaPCambriaLimiter { */ public DMaaPCambriaLimiter(double maxEmptyPollsPerMinute,double maxPollsPerMinute, int windowLengthMins, long sleepMs ,long sleepMS1) { fRateInfo = new HashMap<>(); - fRateInfoCheck = new HashMap<>(); fMaxEmptyPollsPerMinute = Math.max(0, maxEmptyPollsPerMinute); fMaxPollsPerMinute = Math.max(0, maxPollsPerMinute); fWindowLengthMins = windowLengthMins; @@ -226,42 +223,6 @@ public class DMaaPCambriaLimiter { - private static class RateInfoCheck { - - private final String fLabel; - private final CdmRateTicker fCallRateSinceLastMsgSend; - /** - * constructor initialzes - * - * @param label - * @param windowLengthMinutes - */ - public RateInfoCheck(String label, int windowLengthMinutes) { - fLabel = label; - fCallRateSinceLastMsgSend = new CdmRateTicker("Call rate since last msg send", 1, TimeUnit.MINUTES, - windowLengthMinutes, TimeUnit.MINUTES); - } - - public String getLabel() { - return fLabel; - } - - /** - * CdmRateTicker is reset - */ - public void reset() { - fCallRateSinceLastMsgSend.reset(); - } - - /** - * - * @return - */ - public double onCall() { - fCallRateSinceLastMsgSend.tick(); - return fCallRateSinceLastMsgSend.getRate(); - } - } diff --git a/src/test/java/org/onap/dmaap/mr/cambria/beans/ApiKeyBeanTest.java b/src/test/java/org/onap/dmaap/mr/cambria/beans/ApiKeyBeanTest.java index 2a79e92..beec641 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/beans/ApiKeyBeanTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/beans/ApiKeyBeanTest.java @@ -53,6 +53,16 @@ public class ApiKeyBeanTest { } + @Test + public void testApiKeyBean(){ + ApiKeyBean bean = new ApiKeyBean(); + bean.setDescription("description"); + bean.setEmail("email"); + assertEquals("description", bean.getDescription()); + assertEquals("email", bean.getEmail()); + + } + } diff --git a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPCambriaLimiterTest.java b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPCambriaLimiterTest.java index 853d770..f9b2554 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPCambriaLimiterTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPCambriaLimiterTest.java @@ -18,7 +18,7 @@ * ============LICENSE_END========================================================= */ - package org.onap.dmaap.mr.cambria.beans; +package org.onap.dmaap.mr.cambria.beans; import static org.junit.Assert.*; @@ -41,43 +41,57 @@ public class DMaaPCambriaLimiterTest { @Test public void testGetSleepMsForRate() { - - - double value = 3; - DMaaPCambriaLimiter.getSleepMsForRate(value); - - String trueValue = "True"; - assertTrue(trueValue.equalsIgnoreCase("True")); - + + assertEquals(1000, DMaaPCambriaLimiter.getSleepMsForRate(100)); + assertEquals(0, DMaaPCambriaLimiter.getSleepMsForRate(0)); + } - + @Test public void testOnCall() { - - DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(1,2, 3); + + DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(1, 2, 3); try { - limiter.onCall("testTopic", "ConsumerGroup1", "client2","remoteHost"); + limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost"); } catch (CambriaApiException e) { // TODO Auto-generated catch block e.printStackTrace(); } - + String trueValue = "True"; assertTrue(trueValue.equalsIgnoreCase("True")); - + + } + + @Test + public void testOnCallError2() { + + DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(0, 2, 3, 1, 1); + try { + limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost"); + } catch (CambriaApiException e) { + assertTrue(false); + } + + } + + @Test(expected = CambriaApiException.class) + public void testOnCallError() throws CambriaApiException { + + DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(0.9, 2, 3, 1, 1); + limiter.onCall("testTopic", "ConsumerGroup1", "client2", "remoteHost"); + } - + @Test public void testOnSend() { - - DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(3,3, 3); + + DMaaPCambriaLimiter limiter = new DMaaPCambriaLimiter(3, 3, 3); limiter.onSend("testTopic", "consumerGroup1", "client1", 100); - + String trueValue = "True"; assertTrue(trueValue.equalsIgnoreCase("True")); - + } - - } diff --git a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPContextTest.java b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPContextTest.java index 9a67673..a945cd6 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPContextTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/beans/DMaaPContextTest.java @@ -27,6 +27,9 @@ import org.junit.Before; import org.junit.Test; import org.onap.dmaap.dmf.mr.beans.DMaaPContext; +import org.springframework.mock.http.client.MockClientHttpRequest; +import org.springframework.mock.web.MockHttpServletRequest; +import org.springframework.mock.web.MockHttpSession; public class DMaaPContextTest { @@ -48,6 +51,21 @@ public class DMaaPContextTest { } + @Test + public void testDMaaPContext(){ + + DMaaPContext context=new DMaaPContext(); + context.setConsumerRequestTime("consumerRequestTime"); + assertEquals("consumerRequestTime", context.getConsumerRequestTime()); + MockHttpServletRequest request= new MockHttpServletRequest(); + MockHttpSession session=new MockHttpSession(); + request.setSession(session); + context.setRequest(request); + assertNotNull(context.getSession()); + + + } + } diff --git a/src/test/java/org/onap/dmaap/mr/cambria/beans/TopicBeanTest.java b/src/test/java/org/onap/dmaap/mr/cambria/beans/TopicBeanTest.java index bb3af25..d88c408 100644 --- a/src/test/java/org/onap/dmaap/mr/cambria/beans/TopicBeanTest.java +++ b/src/test/java/org/onap/dmaap/mr/cambria/beans/TopicBeanTest.java @@ -51,6 +51,26 @@ public class TopicBeanTest { } + @Test + public void testTopicBean() { + + TopicBean bean = new TopicBean("topicName", "topicDescription", 1,1,true); + assertNotNull(bean); + + } + + @Test + public void testTopicBeanStter() { + + TopicBean bean = new TopicBean(); + bean.setPartitionCount(1); + bean.setReplicationCount(1); + bean.setTopicDescription("topicDescription"); + bean.setTopicName("topicName"); + bean.setTransactionEnabled(true); + assertNotNull(bean); + } + } |