@@ -0,0 +1,2759 @@
+/**%0A * Copyright 2013 Netflix, Inc.%0A *%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *     http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A */%0Apackage com.netflix.servo.monitor;%0A%0Aimport com.netflix.servo.tag.Tag;%0A%0Aimport org.testng.annotations.Test;%0A%0Aimport static org.testng.Assert.*;%0A%0Apublic class ResettableCounterTest extends AbstractMonitorTest%3CResettableCounter%3E %7B%0A%0A    public ResettableCounter newInstance(String name) %7B%0A        return new ResettableCounter(MonitorConfig.builder(name).build());%0A    %7D%0A%0A    @Test%0A    public void testHasGaugeTag() throws Exception %7B%0A        Tag type = newInstance(%22foo%22).getConfig().getTags().getTag(%22type%22);%0A        assertEquals(type.getValue(), %22GAUGE%22);%0A    %7D%0A%0A    @Test%0A    public void testGetValue() throws Exception %7B%0A        ResettableCounter c = newInstance(%22foo%22);%0A        assertEquals(c.getValue().longValue(), 0L);%0A%0A        // Check basic rate, if sleep exactly 50ms rate since the reset would be 20.0%0A        c.increment();%0A        Thread.sleep(50);%0A        double rate = c.getValue().doubleValue();%0A        assertTrue(rate %3C= 20.0 && rate %3E 0.0);%0A%0A        // Should be around 10m, allow %0A        c.increment(1000000);%0A        rate = c.getValue().doubleValue();%0A        assertTrue(rate %3C= 2.001e7 && rate %3E 5e6);%0A    %7D%0A%0A    @Test%0A    public void testGetAndResetValue() throws Exception %7B%0A        ResettableCounter c = newInstance(%22foo%22);%0A        assertEquals(c.getValue().longValue(), 0L);%0A%0A        // Check basic rate, if sleep exactly 50ms rate since the reset would be 20.0%0A        c.increment();%0A        Thread.sleep(50);%0A        double rate = c.getValue().doubleValue();%0A        assertTrue(rate %3C= 20.0 && rate %3E 0.0);%0A%0A        // Should be around 10m, allow %0A        c.increment(1000000);%0A        rate = c.getAndResetValue().doubleValue();%0A        assertTrue(rate %3C= 2.001e7 && rate %3E 5e6);%0A        assertEquals(c.getValue().longValue(), 0L);%0A    %7D%0A%0A    @Test%0A    public void testOverflow() throws Exception %7B%0A        ResettableCounter c = newInstance(%22foo%22);%0A        assertEquals(c.getValue().longValue(), 0L);%0A%0A        // Check basic rate, if sleep exactly 50ms rate since the reset would be 20.0%0A        c.increment(Long.MAX_VALUE);%0A        c.increment(1);%0A        long rate = c.getValue().longValue();%0A        assertEquals(rate, 0L);%0A    %7D%0A%7D%0A

add test case for resettable counter