예제 #1
0
  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));
    }
  }
예제 #2
0
 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);
     }
   }
 }
예제 #3
0
  private void jobHandlerInvariants(
      ConcurrentLinkedDeque<TraceContext.Info> queue, CountInfo countInfo) {
    TraceContext.Info info1 = queue.pollFirst();
    TraceContext.Info info2 = queue.pollFirst();
    TraceContext.Info info3 = queue.pollFirst();
    assertEquals(info1.requestId, info2.requestId);
    assertEquals(info2.requestId, info3.requestId);
    assertEquals(info1.message, TraceContext.CONSTANT.REGISTER_THREAD_TO_REQUEST);
    assertEquals(info2.message, TraceContext.CONSTANT.START_NEW_TRACE);
    assertEquals(info3.message, TraceContext.CONSTANT.UNREGISTER_THREAD_FROM_REQUEST);

    putIfAbsent(countInfo.numberOfJobsMap, info1.requestId, 0);
    countInfo.numberOfJobsMap.put(
        info1.requestId, countInfo.numberOfJobsMap.get(info1.requestId) + 1);
  }
예제 #4
0
  private void requestHandlerInvariants(
      ConcurrentLinkedDeque<TraceContext.Info> queue, CountInfo countInfo) {
    TraceContext.Info info1 = queue.pollFirst();
    TraceContext.Info info2 = queue.pollFirst();
    TraceContext.Info info3 = queue.pollFirst();
    TraceContext.Info info4 = queue.pollFirst();
    assertEquals(info1.requestId, info2.requestId);
    assertEquals(info2.requestId, info3.requestId);
    assertEquals(info3.requestId, info4.requestId);
    assertEquals(info1.message, TraceContext.CONSTANT.REGISTER_REQUEST);
    assertEquals(info2.message, TraceContext.CONSTANT.REGISTER_THREAD_TO_REQUEST);
    assertEquals(info3.message, TraceContext.CONSTANT.UNREGISTER_THREAD_FROM_REQUEST);
    assertEquals(info4.message, TraceContext.CONSTANT.UNREGISTER_REQUEST);

    countInfo.numberOfRequests.add(info1.requestId);
  }