private void runVerification(int numberOfRequests, int jobsPerRequest) { // verify control info CountInfo countInfo = new CountInfo(numberOfRequests, jobsPerRequest); ConcurrentHashMap<Long, ConcurrentLinkedDeque<TraceContext.Info>> testInfoMap = TraceContext.getTestInfoMap(); // LOGGER.info("Thread {}: {}", key, testInfoMap.get(key).toString().replace(",", "\n")); for (ConcurrentLinkedDeque<TraceContext.Info> queue : testInfoMap.values()) { mixedInvariants(queue, countInfo); } countInfo.verify(); // verify trace info for (long rqId = 0; rqId < numberOfRequests; rqId++) { ConcurrentLinkedDeque<Trace> traceQueue = TraceContext.getAllTraceInfoMap().get(rqId); assertEquals(traceQueue.size(), jobsPerRequest + 1); Set<Integer> jobIdSet = new HashSet<Integer>(); for (Trace trace : traceQueue) { // one trace is used for request handler, it has no info recorded if (trace.getValue().size() > 0) { Object obj = trace.getValue().get(0); // we have recorded one entry per job in tests String[] tmp = ((String) obj).split(SEP); long reqId = Long.parseLong(tmp[0].trim()); assertEquals(rqId, reqId); int jobId = Integer.parseInt(tmp[1].trim()); jobIdSet.add(jobId); } } assertEquals(jobIdSet.size(), jobsPerRequest); // show trace LOGGER.info("Trace Tree: {}", TraceContext.getTraceInfoOfRequestId(rqId)); } }
private void mixedInvariants( ConcurrentLinkedDeque<TraceContext.Info> queue, CountInfo countInfo) { while (queue.size() > 0) { if (queue.peekFirst().message == TraceContext.CONSTANT.REGISTER_REQUEST) { requestHandlerInvariants(queue, countInfo); } else if (queue.peekFirst().message == TraceContext.CONSTANT.REGISTER_THREAD_TO_REQUEST) { jobHandlerInvariants(queue, countInfo); } else { throw new RuntimeException("Remaining Queue malformed: " + queue); } } }