Counter implements Cloneable, Serializable { public void addErrors(List<CounterError> counterErrorList) { assert errorCounter; if (counterErrorList.isEmpty()) { return; } synchronized (errors) { if (!errors.isEmpty() && errors.get(0).getTime() > counterErrorList.get(0).getTime()) { errors.addAll(0, counterErrorList); } else { errors.addAll(counterErrorList); } if (errors.size() > 1) { Collections.sort(errors, new CounterErrorComparator()); while (errors.size() > MAX_ERRORS_COUNT) { errors.removeFirst(); } } } } Counter(String name, String iconName);  Counter(String name, String storageName, String iconName, String childCounterName);  Counter(String name, String iconName, Counter childCounter); private  Counter(String name, String storageName, String iconName, String childCounterName,
			ThreadLocal<CounterRequestContext> contextThreadLocal); String getName(); String getStorageName(); String getIconName(); String getChildCounterName(); Date getStartDate(); boolean isDisplayed(); void setDisplayed(boolean displayed); boolean isUsed(); void setUsed(boolean used); void setRequestTransformPattern(Pattern requestTransformPattern); void setMaxRequestsCount(int maxRequestsCount); void bindContextIncludingCpu(String requestName); void bindContext(String requestName, String completeRequestName,
			HttpServletRequest httpRequest, long startCpuTime, long startAllocatedBytes); void unbindContext(); void addRequestForCurrentContext(boolean systemError); void addRequestForCurrentContext(String systemErrorStackTrace); void addRequest(String requestName, long duration, int cpuTime, int allocatedKBytes,
			boolean systemError, long responseSize); void addRequestForSystemError(String requestName, long duration, int cpuTime,
			int allocatedKBytes, String stackTrace); void addRumHit(String requestName, long networkTime, long domProcessing,
			long pageRendering); boolean isErrorCounter(); boolean isJobCounter(); boolean isJspOrStrutsCounter(); boolean isBusinessFacadeCounter(); boolean isRequestIdFromThisCounter(String requestId); void addErrors(List<CounterError> counterErrorList); CounterRequest getCounterRequest(CounterRequestContext context); CounterRequest getCounterRequestByName(String requestName, boolean saveRequestIfAbsent); CounterRequest getCounterRequestById(String requestId); int getRequestsCount(); List<CounterRequest> getRequests(); List<CounterRequest> getOrderedRequests(); List<CounterError> getErrors(); int getErrorsCount(); void clear(); @Override //CHECKSTYLE:OFF Counter clone(); @Override String toString(); static final String HTTP_COUNTER_NAME; static final String ERROR_COUNTER_NAME; static final String LOG_COUNTER_NAME; static final String JSP_COUNTER_NAME; static final String STRUTS_COUNTER_NAME; static final String JSF_COUNTER_NAME; static final String SQL_COUNTER_NAME; static final String JOB_COUNTER_NAME; static final String BUILDS_COUNTER_NAME; static final int MAX_ERRORS_COUNT; }
@Test public void testAddErrors() { final CounterError beforeError = new CounterError("before", null); assertNotNull("CounterError.toString()", beforeError.toString()); try { Thread.sleep(50); } catch (final InterruptedException e) { throw new IllegalStateException(e); } final Counter errorCounter = new Counter(Counter.ERROR_COUNTER_NAME, null); CounterError.bindRequest(null); CounterError.unbindRequest(); final HttpServletRequest httpRequest = createNiceMock(HttpServletRequest.class); expect(httpRequest.getAttribute(CounterError.REQUEST_KEY)).andReturn("/test GET"); expect(httpRequest.getRemoteUser()).andReturn("me"); replay(httpRequest); CounterError.bindRequest(httpRequest); assertNotNull("new CounterError", new CounterError("with request", null)); CounterError.unbindRequest(); verify(httpRequest); final int errorsCount = errorCounter.getErrorsCount(); final List<CounterError> errors = new ArrayList<CounterError>(); errors.add(new CounterError("erreur", null)); errors.add(new CounterError("erreur", "stacktrace")); errorCounter.addErrors(errors); errors.add(0, beforeError); errorCounter.addErrors(errors); assertEquals("addErrors", errorsCount + 5, errorCounter.getErrorsCount()); while (errorCounter.getErrorsCount() < Counter.MAX_ERRORS_COUNT) { errorCounter.addErrors(errors); } errorCounter.addErrors(errors); }