/** * Creates a new (enabled) {@link Statistics} instance. * @return a new instance. */ public static Statistics create() { return create( true ); }
@Test( dataProvider = "methodNamesProvider" ) public void testCounts( final String getterMethod, final String updateMethod ) throws Exception { final Statistics cut = Statistics.create(); final Method getMethod = Statistics.class.getMethod( getterMethod ); assertEquals( ((Long)getMethod.invoke( cut )).longValue(), 0 ); Statistics.class.getMethod( updateMethod ).invoke( cut ); assertEquals( ((Long)getMethod.invoke( cut )).longValue(), 1 ); }
@Nonnull protected RequestTrackingHostValve createSessionTrackerValve() { return new RequestTrackingHostValve(".*\\.(png|gif|jpg|css|js|ico)$", "somesessionid", _service, Statistics.create(), new AtomicBoolean( true ), new CurrentRequest()) { @Override protected String[] getSetCookieHeaders(final Response response) { return RequestTrackingHostValveTest.this.getSetCookieHeaders(response); } }; }
@Test public final void testGetSessionCookieName() throws IOException, ServletException { final RequestTrackingHostValve cut = new RequestTrackingHostValve(null, "foo", _service, Statistics.create(), new AtomicBoolean( true ), new CurrentRequest()) { @Override protected String[] getSetCookieHeaders(final Response response) { final Collection<String> result = response.getHeaders("Set-Cookie"); return result.toArray(new String[result.size()]); } }; assertEquals(cut.getSessionCookieName(), "foo"); }
@Test public void testDisabledRequestWithBackup() { final Statistics cut = Statistics.create( false ); assertEquals( cut.getRequestsWithBackupFailure(), 0 ); cut.requestWithBackupFailure(); assertEquals( cut.getRequestsWithBackupFailure(), 0 ); }
private MemcachedClient createMemcachedClient( final String memcachedNodes, final InetSocketAddress address ) throws IOException, InterruptedException { final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(memcachedNodes, null, null, _storageClientCallback); final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId() ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ) : new DefaultConnectionFactory(); final MemcachedClient result = new MemcachedClient( cf, Arrays.asList( address ) ); // Wait a little bit, so that the memcached client can connect and is ready when test starts Thread.sleep( 100 ); return result; }
/** * Creates a new (enabled) {@link Statistics} instance. * @return a new instance. */ public static Statistics create() { return create( true ); }
" nodes definition " + _memcachedNodes + ", failover nodes " + _failoverNodes + ")" ); _statistics = Statistics.create( _enableStatistics );
@BeforeMethod public void setUp(final Method testMethod) throws Throwable { final InetSocketAddress address = new InetSocketAddress( "localhost", MEMCACHED_PORT ); _daemon = createDaemon( address ); _daemon.start(); final String[] testGroups = testMethod.getAnnotation(Test.class).groups(); final String nodePrefix = testGroups.length == 0 || !GROUP_WITHOUT_NODE_ID.equals(testGroups[0]) ? NODE_ID + ":" : ""; _memcachedNodes = nodePrefix + "localhost:" + MEMCACHED_PORT; try { _tomcat1 = startTomcat( TC_PORT_1, JVM_ROUTE_1 ); _tomcat2 = startTomcat( TC_PORT_2, JVM_ROUTE_2 ); } catch ( final Throwable e ) { LOG.error( "could not start tomcat.", e ); throw e; } final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(_memcachedNodes, null, null, _storageClientCallback); final ConnectionFactory cf = nodesManager.isEncodeNodeIdInSessionId() ? new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ) : new DefaultConnectionFactory(); _client = new MemcachedClient( cf, Arrays.asList( address ) ); _httpClient = new DefaultHttpClient(); }
@BeforeMethod public void setUp() throws Throwable { final InetSocketAddress address1 = new InetSocketAddress( "localhost", MEMCACHED_PORT_1 ); _daemon1 = createDaemon( address1 ); _daemon1.start(); final InetSocketAddress address2 = new InetSocketAddress( "localhost", MEMCACHED_PORT_2 ); _daemon2 = createDaemon( address2 ); _daemon2.start(); try { _tomcat1 = startTomcat( TC_PORT_1 ); _tomcat2 = startTomcat( TC_PORT_2 ); } catch ( final Throwable e ) { LOG.error( "could not start tomcat.", e ); throw e; } final MemcachedNodesManager nodesManager = MemcachedNodesManager.createFor(MEMCACHED_NODES, null, null, _storageClientCallback); _client = new MemcachedClient( new SuffixLocatorConnectionFactory( nodesManager, nodesManager.getSessionIdFormat(), Statistics.create(), 1000, 1000 ), Arrays.asList( address1, address2 ) ); final SchemeRegistry schemeRegistry = new SchemeRegistry(); schemeRegistry.register( new Scheme("http", 80, PlainSocketFactory.getSocketFactory())); _httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager(schemeRegistry)); _executor = Executors.newCachedThreadPool(); }
" nodes definition " + _memcachedNodes + ", failover nodes " + _failoverNodes + ")" ); _statistics = Statistics.create( _enableStatistics );