Пример #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 configureChannel() {
   while (contextsToAdd.size() > 0) {
     try {
       ChannelContext context = contextsToAdd.pop();
       context.channel.configureBlocking(false);
       context.channel.register(selector, SelectionKey.OP_WRITE | SelectionKey.OP_READ, context);
     } catch (IOException e) {
       throw new RuntimeException(e);
     }
     if (!running()) {
       break;
     }
   }
 }
Пример #4
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);
  }
Пример #5
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);
  }
Пример #6
0
 public void runTasks() {
   synchronized (this) {
     this.notifyAll();
   }
   if (getProgressTask() != null) {
     try {
       getProgressTask().run(ProgressType.DONE, 1);
     } catch (Throwable e) {
       e.printStackTrace();
     }
   }
   while (!tasks.isEmpty()) {
     Runnable task = tasks.poll();
     if (task != null) {
       try {
         task.run();
       } catch (Throwable e) {
         MainUtil.handleError(e);
       }
     }
   }
 }
Пример #7
0
 public void addContext(ChannelContext context) {
   contextsToAdd.push(context);
   selector.wakeup();
 }
Пример #8
0
 public void addTask(Runnable whenFree) {
   tasks.add(whenFree);
 }