@Test
 public void removeTagsJobTest() {
   Collection<Channel> channels = new ArrayList<Channel>();
   channels.add(ch1.build());
   channels.add(ch2.build());
   Job job = new RemoveTagsJob("remove tags", channels, ChannelUtil.getTagNames(ch1.build()));
   job.schedule();
   try {
     // TODO not have a static def for the amount of time needed to
     // complete the update
     job.getThread().join(30000);
   } catch (InterruptedException e) {
     e.printStackTrace();
     assertTrue("The Job is taking too long.", false);
   }
   if (job.getResult() == Status.OK_STATUS) {
     Collection<Channel> chs = new ArrayList<Channel>();
     chs.add(ch1.build());
     chs.add(ch2.build());
     assertNull("Failed to Add tags: ", client.findByTag("cssUnitTestTag"));
   }
 }
Example #2
0
  public boolean isEmpty(Context context, Q7WaitInfoRoot info) {
    // Filter already executed UI jobs with async finish status.
    List<Job> realJobs = new ArrayList<Job>();
    long current = System.currentTimeMillis();
    boolean wasInStepMode = false;
    List<Job> jobsInUI = new ArrayList<Job>();
    synchronized (jobs) {
      // Remove all canceled jobs
      removeCanceledJobs();
      if (jobs.isEmpty()) {
        return logReturnResult(true, realJobs, jobsInUI, info);
      }
      for (JobInfo jobInfo : jobs.values()) {
        if (!jobInfo.isActive()) continue;
        Job job = jobInfo.job;
        IJobCollector[] collectors = JobCollectorExtensions.getDefault().getCollectors();
        boolean allowSkip = true;
        for (IJobCollector ext : collectors) {
          if (ext.noSkipMode(job)) {
            allowSkip = false;
            break;
          }
        }
        if (allowSkip) {
          continue;
        }
        // SWTTeslaActivator.debugLog("Waiting job:" + job.getName() +
        // ": "
        // + job.getClass().getName());
        long jobStartTime = jobInfo.startingTime;

        if (job.getClass().getName().contains("org.eclipse.debug.internal.ui.DebugUIPlugin$")) {
          // It looks like background launching job.
          Thread thread = job.getThread();
          if (thread == null) {
            SWTTeslaActivator.logToReport("Active job " + job.getName() + " has no thread");
            jobInfo.done(false);
          }
          Context ctx = ContextManagement.makeContext(thread.getStackTrace());
          // If Autobuild job is active and on lock and there is Modal
          // Dialog in main thread,
          // lets' skip job from important for us.
          if (ctx.contains("java.util.concurrent.locks.LockSupport", "park")
              || ctx.contains("java.lang.Object", "wait")) {
            // We are waiting some stuff, let's check if main thread
            // have a MessageDialog and if so skip this job right
            // now.
            if (context.contains("org.eclipse.jface.dialogs.MessageDialogWithToggle", "open")
                || context.contains("org.eclipse.jface.dialogs.MessageDialog", "open")) {
              // Skip job from processing since it in lock and
              // waits for a dialog.
              SWTTeslaActivator.logToReport(
                  "Active job "
                      + job.getName()
                      + " has skipped since it in lock state and Message dialog are active");
              continue;
            }
          }
        }

        if (jobInfo.checkForTimeout) {
          if (jobStartTime + TeslaLimits.getStepModeEnableTimeout() < current
              && job.getState() == Job.RUNNING
              && stepModeNext < current) {
            // Job is sleepping to long time already.
            // Check for job are slepping
            // String name = job.getClass().getName();
            // Locate thread
            Thread thread = job.getThread();
            if (thread == null) {
              SWTTeslaActivator.logToReport("Active job " + job.getName() + " has no thread");
              jobInfo.done(false);
            }
            Context ctx = ContextManagement.makeContext(thread.getStackTrace());
            // if (ctx.contains(
            // "org.eclipse.jface.operation.ModalContext$ModalContextThread",
            // "block")) {
            // // Skip model context, since it could
            // continue;
            // }

            if (ctx.contains("java.lang.Thread", "sleep")
                || ctx.contains("java.lang.Object", "wait")
                || ctx.contains("java.util.concurrent.locks.LockSupport", "park")) {
              /*
               * Job are in Thread.sleep(), lets allow one
               * operation.
               */
              if (!jobInfo.jobInStepMode) {
                // Print step information
                SWTTeslaActivator.logToReport(
                    "---->>> Begin step mode for Job: "
                        + getCurrentReportNodeName()
                        + " <<---\n(skipping)"
                        + getJobMessage(jobInfo));
              }
              jobInfo.jobInStepMode = true;
              wasInStepMode = true;
              continue;
            }
          }

          long timeout = TeslaLimits.getJobTimeout();
          if (job.belongsTo(getFamilyAutoBuild())) {
            timeout = TeslaLimits.getAutoBuildJobTimeout();
          }
          if (jobInfo.jobInStepMode) {
            timeout = TeslaLimits.getStepModeTimeout();
          }
          if (job.getClass().getName().contains("org.eclipse.debug.internal.ui.DebugUIPlugin")) {
            timeout = TeslaLimits.getDebugJobTimeout();
          }
          if (jobStartTime + timeout < current) {
            if (context != null && TeslaEventManager.getManager().isJobInSyncExec(job, context)) {
              // Remove from stop waited jobs if called sync
              // exec
              jobInfo.checkForTimeout = false;
            } else {
              printJobTimeoutLogEntry(job);
              continue;
            }
          }
        }
        if (context != null) {
          if (isAsyncSupported()) {
            // If we are executed from async finished job lets
            // filter it
            if (JobsManager.getInstance().isFinishedAsyncJob(job)) {
              if (context.containsClass(job.getClass().getName())) {
                jobsInUI.add(job);
                continue;
              }
            }
          }
          if (isSyncSupported()) {
            // Check for any other job running Display.sleep()
            if (context.contains(Display.class.getName(), "sleep")) {
              if (TeslaEventManager.getManager().isJobInSyncExec(job, context)) {
                // If and only if job is already in synchronizer
                Map<Thread, StackTraceElement[]> traces = Thread.getAllStackTraces();
                Set<String> names = getSuperClassNames(job);
                Thread jobThread = null;
                Context jobContext = null;
                for (Map.Entry<Thread, StackTraceElement[]> thread : traces.entrySet()) {
                  Context ctx = ContextManagement.makeContext(thread.getValue());
                  for (String name : names) {
                    if (ctx.contains("org.eclipse.core.internal.jobs.Worker", "run")
                        && ctx.contains(name, "run")) {
                      jobThread = thread.getKey();
                      jobContext = ctx;
                    }
                  }
                }
                if (jobThread != null && jobContext != null) {
                  if (jobContext.contains("org.eclipse.ui.internal.UISynchronizer", "syncExec")
                      && jobContext.contains("org.eclipse.ui.internal.Semaphore", "acquire")) {
                    if (!SWTUIPlayer.hasRunnables(RWTUtils.findDisplay())) {
                      // also check what sync exec are on
                      // current stack trace
                      List<Context> execs = TeslaEventManager.getManager().getSyncExecs();
                      boolean toContinue = true;
                      for (Context context2 : execs) {
                        StackTraceElement[] stackTrace = context2.getStackTrace();
                        String className = null;
                        for (int i = 0; i < stackTrace.length; i++) {
                          if (stackTrace[i].getClassName().equals("org.eclipse.swt.widgets.Display")
                              && stackTrace[i].getMethodName().equals("syncExec")) {
                            className = stackTrace[i + 1].getClassName();
                            break;
                          }
                        }
                        if (!context.containsClass(className)) {
                          toContinue = false;
                        }
                      }
                      if (toContinue) {
                        jobsInUI.add(job);
                        continue;
                      }
                    }
                  }
                }
              }
            }
          }
        }
        if (jobInfo.isActive()) realJobs.add(job);
      }
    }
    if (!jobsInUI.isEmpty()) {
      if (realJobs.size() == 1 && realJobs.get(0).belongsTo(getFamilyAutoBuild())) {
        realJobs.clear();
      }
    }
    if (realJobs.size() == 1) {
      Job job = realJobs.iterator().next();
      if (job.belongsTo(getFamilyAutoBuild())) {
        // Check for modal dialogs are visible
        int flags = TeslaSWTAccess.getJobFlags(job);
        // Job is alone and blocked
        if ((flags & 0xFF) == 0x08) {
          return logReturnResult(true, realJobs, jobsInUI, info);
        }
        final Display display = RWTUtils.findDisplay();
        final boolean value[] = {false};
        display.syncExec(
            new Runnable() {

              public void run() {
                Shell[] shells = display.getShells();
                for (Shell shell : shells) {
                  if (isModal(shell)) {
                    value[0] = true;
                  }
                }
              }
            });
        if (value[0]) {
          return logReturnResult(true, realJobs, jobsInUI, info);
        }
        if (job.getState() != Job.NONE) {
          return logReturnResult(false, realJobs, jobsInUI, info);
        }
        return logReturnResult(true, realJobs, jobsInUI, info);
      }
    }
    if (wasInStepMode && realJobs.isEmpty()) {
      stepModeNext = current + TeslaLimits.getStepModeStepTime();
    }
    return logReturnResult(realJobs.isEmpty(), realJobs, jobsInUI, info);
  }
Example #3
0
  private String getJobMessage(JobInfo jobInfo) {
    Job job = jobInfo.job;
    StringBuilder msg = new StringBuilder();
    msg.append("Job: ").append(job.getName()).append("\n");

    msg.append("\tclass: ")
        .append(job.getClass().getName())
        .append(" ")
        .append(DetailUtils.extractSupers(job.getClass()))
        .append("\n");

    Long startTime = jobInfo.startingTime;

    long currentTimeMillis = System.currentTimeMillis();
    long time = 0;
    if (startTime != null) {
      time = currentTimeMillis - startTime.longValue();
    }

    msg.append("\tworking time: ").append(time).append("(ms)\n");
    msg.append("\tstate: ").append(job.getState()).append("\n");

    ISchedulingRule rule = job.getRule();
    if (rule != null) {
      if (rule instanceof IResource) {
        IPath location = ((IResource) rule).getLocation();
        msg.append("\trule is resource: ")
            .append(location != null ? location.toOSString() : "/")
            .append("\n");
      } else {
        msg.append("\trule: ").append(rule.toString()).append("\n");
      }
    } else {
      msg.append("\trule: Empty\n");
    }

    Thread thread = job.getThread();
    if (thread != null) {
      StackTraceElement[] trace = thread.getStackTrace();
      msg.append("\tstack trace: \n");
      // Print 5 lines of stack trace for job
      int c = 0;
      for (StackTraceElement stackTraceElement : trace) {
        if (c > 15) {
          msg.append("\t\t....");
          break;
        }
        c++;
        msg.append(
                "\t\t"
                    + stackTraceElement.getClassName()
                    + "."
                    + stackTraceElement.getMethodName()
                    + ":"
                    + stackTraceElement.getLineNumber()
                    + (stackTraceElement.getFileName() != null
                        ? (" [" + stackTraceElement.getFileName() + "]")
                        : ""))
            .append("\n");
      }
    }
    return msg.toString();
  }
 public void join() throws InterruptedException {
   if (job != null && job.getThread() != Thread.currentThread()) {
     job.join();
   }
 }