Package org.tehuti.utils

Examples of org.tehuti.utils.Time


    @Test
    public void statsExpireOnTime() {
        final long startTime = 1445468640; // Oct 21, 2015
        final int delay = 1000;
        Time mockTime = mock(Time.class);

        when(mockTime.milliseconds()).thenReturn(startTime);

        RequestCounter rc = new RequestCounter("tests.StatsTest.statsExpireOnTime", delay, mockTime);

        // Add some new stats and verify they were calculated correctly
        rc.addRequest(100 * NS_PER_MS, 1, 200, 0, 1);
        rc.addRequest(50 * NS_PER_MS, 0, 1000, 0, 2);
        assertEquals(1, rc.getNumEmptyResponses());
        assertEquals(100, rc.getMaxLatencyInMs());
        assertEquals(75d, rc.getAverageTimeInMs(), 0.0f);
        assertEquals(1000, rc.getMaxValueSizeInBytes());
        assertEquals(3, rc.getGetAllAggregatedCount());

        // Jump into the future after the counter should have expired
        when(mockTime.milliseconds()).thenReturn(startTime + delay * 2 + 1);

        // Now verify that the counter has aged out the previous values
        assertEquals(0, rc.getNumEmptyResponses());
        assertEquals(0, rc.getMaxLatencyInMs());
        assertEquals(Double.NaN, rc.getAverageTimeInMs(), 0.0f);
View Full Code Here


    public void statsShowSpuriousValues() {
        final long startTime = 1445468640; // Some start time : Oct 21, 2015
        final int resetDurationMs = 1000;
        final int numberOfSampleWindows = 2;
        final int tinyDurationMs = 10;
        Time mockTime = mock(Time.class);

        when(mockTime.milliseconds()).thenReturn(startTime);
        RequestCounter rc = new RequestCounter("Tests.statsShowSpuriousValues",
                                               resetDurationMs / numberOfSampleWindows,
                                               mockTime);

        // Add some new stats and verify they were calculated correctly
        rc.addRequest(100 * NS_PER_MS, 0, 1000, 100, 1);
        rc.addRequest(50 * NS_PER_MS, 0, 1000, 100, 2);
        rc.addRequest(50 * NS_PER_MS, 0, 1000, 100, 3);
        rc.addRequest(50 * NS_PER_MS, 0, 1000, 100, 4);
        rc.addRequest(50 * NS_PER_MS, 0, 1000, 100, 5);

        // Jump into the counter window just a little (10 ms)
        when(mockTime.milliseconds()).thenReturn(startTime + tinyDurationMs);

        assertTrue("Throughput should not be absurdly high at beginning of window...", rc.getThroughput() <= 10);

        // Jump in time past the reset duration
        when(mockTime.milliseconds()).thenReturn(startTime + resetDurationMs + 1);

        assertEquals("Make sure counter's value has expired", 0d, rc.getThroughput(), 0.0f);
    }
View Full Code Here

TOP

Related Classes of org.tehuti.utils.Time

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.