/**
 * Copyright 2012 Comcast Corporation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.comcast.cqs.test.unit;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import com.comcast.cmb.common.controller.CMBControllerServlet;
import com.comcast.cmb.common.util.Util;
import com.comcast.cqs.controller.CQSMonitor;
import com.comcast.cqs.controller.CQSMonitor.CacheType;

public class CQSMonitorTest {

    @Before
    public void setup() throws Exception {
        Util.initLog4jTest();
        CMBControllerServlet.valueAccumulator.initializeAllCounters();
        CQSMonitor.getInstance().clearAllState();
    }

    @Test
    public void testMessageCount() {
        CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 10);
        CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 10);
        if (CQSMonitor.getInstance().getRecentNumberOfReceives("test") != 20) {
            fail("Expected 20 messages. Got=" + CQSMonitor.getInstance().getRecentNumberOfReceives("test"));
        }
    }
    
    @Test
    public void testCacheHit() {
        CQSMonitor.getInstance().registerCacheHit("test", 5, 10, CacheType.QCache);
        CQSMonitor.getInstance().registerCacheHit("test", 5, 10, CacheType.QCache);
        //should be 50% hit
        if (CQSMonitor.getInstance().getCacheHitPercent("test", CacheType.QCache) != 50) {
            fail("Expected 50% Got=" + CQSMonitor.getInstance().getCacheHitPercent("test", CacheType.QCache));
        }
    }
    
    @Test
    public void testNumMessages() {
        CQSMonitor.getInstance().addNumberOfMessagesReceived("test", 1);
        if (CQSMonitor.getInstance().getQueueDepth("test") != 1) {
            fail("Expected 1. Got:" + CQSMonitor.getInstance().getQueueDepth("test"));
        }
        CQSMonitor.getInstance().addNumberOfMessagesReturned("test", 1);
        if (CQSMonitor.getInstance().getQueueDepth("test") != 0) {
            fail("Expected 0. Got:" + CQSMonitor.getInstance().getQueueDepth("test"));
        }
        
        if (CQSMonitor.getInstance().getNumberOfMessagesDeleted("test") != 1) {
            fail("Expected 1. Got:" + CQSMonitor.getInstance().getNumberOfMessagesDeleted("test"));
        }
    }
    
}

@@ -2191,34 +2191,43 @@
 stance().get
-QueueDepth
+RecentNumberOfSends
 (%22test%22) != 
@@ -2293,34 +2293,43 @@
 stance().get
-QueueDepth
+RecentNumberOfSends
 (%22test%22));%0A 
@@ -2446,34 +2446,46 @@
 stance().get
-QueueDepth
+RecentNumberOfReceives
 (%22test%22) != 
@@ -2484,17 +2484,17 @@
 st%22) != 
-0
+1
 ) %7B%0A    
@@ -2559,18 +2559,30 @@
 .get
-QueueDepth
+RecentNumberOfReceives
 (%22te

clean unit test