Search in sources :

Example 6 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class UserAgentWindows method test_windows2000_chrome.

public void test_windows2000_chrome() throws Exception {
    WebAppStat stat = new WebAppStat("");
    stat.computeUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US) AppleWebKit/525.19 (KHTML, like Gecko) Chrome/1.0.154.53 Safari/525.19");
    Assert.assertEquals(0, stat.getBrowserIECount());
    Assert.assertEquals(1, stat.getBrowserChromeCount());
    Assert.assertEquals(0, stat.getBrowserFirefoxCount());
    Assert.assertEquals(0, stat.getBrowserIE10Count());
    Assert.assertEquals(0, stat.getBrowserIE5Count());
    Assert.assertEquals(0, stat.getBrowserIE6Count());
    Assert.assertEquals(0, stat.getBrowserIE7Count());
    Assert.assertEquals(0, stat.getBrowserIE8Count());
    Assert.assertEquals(0, stat.getBrowserIE9Count());
    Assert.assertEquals(0, stat.getBrowserOperaCount());
    Assert.assertEquals(0, stat.getBrowserSafariCount());
    Assert.assertEquals(0, stat.getDeviceAndroidCount());
    Assert.assertEquals(0, stat.getDeviceIpadCount());
    Assert.assertEquals(0, stat.getDeviceIphoneCount());
    Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
    Assert.assertEquals(0, stat.getOSLinuxCount());
    Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
    Assert.assertEquals(0, stat.getOSMacOSXCount());
    Assert.assertEquals(1, stat.getOSWindowsCount());
    Assert.assertEquals(0, stat.getOSSymbianCount());
    Assert.assertEquals(0, stat.getOSFreeBSDCount());
    Assert.assertEquals(0, stat.getOSOpenBSDCount());
    Assert.assertEquals(0, stat.getOSWindows98Count());
    Assert.assertEquals(1, stat.getOSWindows2000Count());
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Example 7 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class UserAgentWindows method test_windowsXP_firefox.

public void test_windowsXP_firefox() throws Exception {
    WebAppStat stat = new WebAppStat("");
    stat.computeUserAgent("Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8");
    Assert.assertEquals(0, stat.getBrowserIECount());
    Assert.assertEquals(0, stat.getBrowserChromeCount());
    Assert.assertEquals(1, stat.getBrowserFirefoxCount());
    Assert.assertEquals(0, stat.getBrowserIE10Count());
    Assert.assertEquals(0, stat.getBrowserIE5Count());
    Assert.assertEquals(0, stat.getBrowserIE6Count());
    Assert.assertEquals(0, stat.getBrowserIE7Count());
    Assert.assertEquals(0, stat.getBrowserIE8Count());
    Assert.assertEquals(0, stat.getBrowserIE9Count());
    Assert.assertEquals(0, stat.getBrowserOperaCount());
    Assert.assertEquals(0, stat.getBrowserSafariCount());
    Assert.assertEquals(0, stat.getDeviceAndroidCount());
    Assert.assertEquals(0, stat.getDeviceIpadCount());
    Assert.assertEquals(0, stat.getDeviceIphoneCount());
    Assert.assertEquals(0, stat.getDeviceWindowsPhoneCount());
    Assert.assertEquals(0, stat.getOSLinuxCount());
    Assert.assertEquals(0, stat.getOSLinuxUbuntuCount());
    Assert.assertEquals(0, stat.getOSMacOSXCount());
    Assert.assertEquals(1, stat.getOSWindowsCount());
    Assert.assertEquals(0, stat.getOSSymbianCount());
    Assert.assertEquals(0, stat.getOSFreeBSDCount());
    Assert.assertEquals(0, stat.getOSOpenBSDCount());
    Assert.assertEquals(0, stat.getOSWindows98Count());
    Assert.assertEquals(1, stat.getOSWindowsXPCount());
}
Also used : WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat)

Example 8 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class WebStatFilterTest method test_sessionStatDisable.

public void test_sessionStatDisable() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filterConfig.addInitParameter(WebStatFilter.PARAM_NAME_SESSION_STAT_ENABLE, "false");
    WebStatFilter filter = new WebStatFilter();
    Assert.assertNull(filter.getWebAppStat());
    filter.init(filterConfig);
    WebAppStat appStat = filter.getWebAppStat();
    Assert.assertFalse(filter.isSessionStatEnable());
    Assert.assertTrue(WebAppStatManager.getInstance().getWebAppStatSet().contains(appStat));
    Assert.assertTrue(StatFilterContext.getInstance().getListeners().contains(filter.getStatFilterContextListener()));
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    Assert.assertNull(filter.getSessionStat(request));
    filter.doFilter(request, response, chain);
    Assert.assertEquals(0, appStat.getSessionStatDataList().size());
    filter.destroy();
    Assert.assertFalse(WebAppStatManager.getInstance().getWebAppStatSet().contains(appStat));
    Assert.assertFalse(StatFilterContext.getInstance().getListeners().contains(filter.getStatFilterContextListener()));
    Map<String, Object> statData = appStat.getStatData();
    Assert.assertEquals(1L, statData.get("RequestCount"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Example 9 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class WebStatFilterTest2 method test_lru.

public void test_lru() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filterConfig.addInitParameter(WebStatFilter.PARAM_NAME_SESSION_STAT_MAX_COUNT, "3");
    WebStatFilter filter = new WebStatFilter();
    filter.init(filterConfig);
    WebAppStat appStat = filter.getWebAppStat();
    Assert.assertEquals(3, filter.getSessionStatMaxCount());
    Assert.assertEquals(0, appStat.getSessionStatDataList().size());
    final MockHttpSession session_0 = new MockHttpSession(servletContext);
    final MockHttpSession session_1 = new MockHttpSession(servletContext);
    final MockHttpSession session_2 = new MockHttpSession(servletContext);
    final MockHttpSession session_3 = new MockHttpSession(servletContext);
    final MockHttpSession session_4 = new MockHttpSession(servletContext);
    // 第一个session请求2次
    {
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_0);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(1, appStat.getSessionStatDataList().size());
        Assert.assertEquals(1, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertTrue(appStat.getSessionStat(session_0.getId()).getLastAccessTimeMillis() > 0);
    }
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_0);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(1, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
    }
    // 第2个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_1);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(2, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
    }
    // 第3个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_2);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertEquals(2, appStat.getSessionStat(session_0.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
    }
    // 第4个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_3);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        Assert.assertEquals(1, appStat.getSessionStat(session_1.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_3.getId()).getRequestCount());
    }
    // 第5个sesion请求1次
    {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain() {

            public void doFilter(javax.servlet.ServletRequest request, javax.servlet.ServletResponse response) {
                ((MockHttpServletRequest) request).setSession(session_4);
            }

            ;
        };
        filter.doFilter(request, response, chain);
        Assert.assertEquals(3, appStat.getSessionStatDataList().size());
        Assert.assertNull(appStat.getSessionStat(session_0.getId()));
        Assert.assertNull(appStat.getSessionStat(session_1.getId()));
        Assert.assertEquals(1, appStat.getSessionStat(session_2.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_3.getId()).getRequestCount());
        Assert.assertEquals(1, appStat.getSessionStat(session_4.getId()).getRequestCount());
    }
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpSession(org.springframework.mock.web.MockHttpSession) WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Example 10 with WebAppStat

use of com.alibaba.druid.support.http.stat.WebAppStat in project druid by alibaba.

the class WebStatFilterTest3_WebURIStatNull method test_sessionStatDisable.

public void test_sessionStatDisable() throws Exception {
    MockServletContext servletContext = new MockServletContext();
    MockFilterConfig filterConfig = new MockFilterConfig(servletContext);
    filterConfig.addInitParameter(WebStatFilter.PARAM_NAME_SESSION_STAT_ENABLE, "false");
    WebStatFilter filter = new WebStatFilter();
    WebAppStat appStat = new WebAppStat() {

        public WebURIStat getURIStat(String uri, boolean create) {
            return null;
        }
    };
    filter.setWebAppStat(appStat);
    filter.setProfileEnable(true);
    Assert.assertNotNull(filter.getWebAppStat());
    filter.init(filterConfig);
    Assert.assertSame(appStat, filter.getWebAppStat());
    Assert.assertFalse(filter.isSessionStatEnable());
    Assert.assertTrue(WebAppStatManager.getInstance().getWebAppStatSet().contains(appStat));
    Assert.assertTrue(StatFilterContext.getInstance().getListeners().contains(filter.getStatFilterContextListener()));
    MockHttpServletRequest request = new MockHttpServletRequest();
    MockHttpServletResponse response = new MockHttpServletResponse();
    MockFilterChain chain = new MockFilterChain();
    Assert.assertNull(filter.getSessionStat(request));
    filter.doFilter(request, response, chain);
    Assert.assertEquals(0, appStat.getSessionStatDataList().size());
    filter.destroy();
    Assert.assertFalse(WebAppStatManager.getInstance().getWebAppStatSet().contains(appStat));
    Assert.assertFalse(StatFilterContext.getInstance().getListeners().contains(filter.getStatFilterContextListener()));
    Map<String, Object> statData = appStat.getStatData();
    Assert.assertEquals(1L, statData.get("RequestCount"));
}
Also used : MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) WebAppStat(com.alibaba.druid.support.http.stat.WebAppStat) MockFilterChain(org.springframework.mock.web.MockFilterChain) MockServletContext(org.springframework.mock.web.MockServletContext) WebStatFilter(com.alibaba.druid.support.http.WebStatFilter) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) MockFilterConfig(org.springframework.mock.web.MockFilterConfig)

Aggregations

WebAppStat (com.alibaba.druid.support.http.stat.WebAppStat)113 WebStatFilter (com.alibaba.druid.support.http.WebStatFilter)3 MockFilterChain (org.springframework.mock.web.MockFilterChain)3 MockFilterConfig (org.springframework.mock.web.MockFilterConfig)3 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)3 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)3 MockServletContext (org.springframework.mock.web.MockServletContext)3 WebAppStatValue (com.alibaba.druid.support.http.stat.WebAppStatValue)1 WebRequestStat (com.alibaba.druid.support.http.stat.WebRequestStat)1 WebSessionStat (com.alibaba.druid.support.http.stat.WebSessionStat)1 WebURIStat (com.alibaba.druid.support.http.stat.WebURIStat)1 WebURIStatValue (com.alibaba.druid.support.http.stat.WebURIStatValue)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 MockHttpSession (org.springframework.mock.web.MockHttpSession)1