@Test
    public void testQueriesPerSecondCalculatedBasedOnEndTime() throws Exception
    {
        // Setup test fixture.
        ProfiledConnection.start();
        ProfiledConnection.addQuery(ProfiledConnection.Type.select, "SELECT 1", Duration.ofMillis(3));
        ProfiledConnection.addQuery(ProfiledConnection.Type.select, "SELECT 1", Duration.ofMillis(1));
        Thread.sleep(5); // To prevent 'infinity'
        final double expected = ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.select);
        ProfiledConnection.stop();

        // Execute system under test.
        Thread.sleep(50);
        final double result = ProfiledConnection.getQueriesPerSecond(ProfiledConnection.Type.select);

        // Verify results.
        assertTrue(result > expected*.25, "Expected value '" + result + "' to be roughly equal to '" + expected + "', but it was significantly different."); // result will typically be _exact_, but the execution time of getQueriesPerSecond() and stop() may introduce a bit of drift.
        assertTrue(result < expected*2, "Expected value '" + result + "' to be roughly equal to '" + expected + "', but it was significantly different."); // result will typically be _exact_, but the execution time of getQueriesPerSecond() and stop() may introduce a bit of drift.
    }
Unit tests that verify the functionality of {@link ProfiledConnection}

@author Guus der Kinderen, guus.der.kinderen@gmail.com
xmppserver/src/test/java/org/jivesoftware/database/ProfiledConnectionTest.java