示例#1
0
 public void run() {
   try {
     while (!testStatus.isStopTestRequested()) {
       TCObjectSelf tcoSelf = factory.newTCObjectSelf();
       serverMapLocalCache.put(tcoSelf);
       writeTps.incrementAndGet();
     }
   } catch (Throwable t) {
     testStatus.requestStopWithError(t);
   }
 }
  /** ***************************************************************************** */
  synchronized String getToolTip() {
    StringBuffer buf = new StringBuffer();
    buf.append("<html>");
    buf.append("<c><b>TEST ");
    buf.append(test_name);
    buf.append("</b></c><hr>");
    buf.append("<table cellpadding=0 cellspacing=1 align=left >");
    buf.append("<tr><td>STATUS&nbsp;</td><td>");
    buf.append(test_status.toString());
    buf.append("</td></tr>");
    buf.append("<tr><td>STATE</td><td>");
    buf.append(test_state.toString());
    buf.append("</td></tr>");
    if (fail_message != null) {
      buf.append("<tr><td>ERROR</td><td>");
      buf.append(fail_message);
      buf.append("</td></tr>");
    }
    if (fail_trace != null) {
      StringTokenizer tok = new StringTokenizer(fail_trace, "\n\t");
      String s1 = tok.nextToken();
      buf.append("<tr><td>TRACE</td><td>" + s1 + "</td></tr>");
      while (tok.hasMoreTokens()) {
        String s = tok.nextToken();
        buf.append("<tr><td></td><td>&nbsp;&nbsp;" + s + "</td></tr>");
      }
    }
    buf.append("</table>");

    return buf.toString();
  }
示例#3
0
 public void run() {
   try {
     while (!testStatus.isStopTestRequested()) {
       long oid = random.nextInt((int) factory.getOidCounter().get());
       TCObjectSelf tcoSelf = serverMapLocalCache.getFromTCObjectSelfStore(oid);
       if (tcoSelf != null) {
         nonNullReadsCounter.incrementAndGet();
         Assert.assertEquals(oid, tcoSelf.getOid());
         Assert.assertEquals(factory.getKeyForId(tcoSelf.getOid()), tcoSelf.getKey());
         Assert.assertEquals(factory.getValueForId(tcoSelf.getOid()), tcoSelf.getValue());
       }
       readTps.incrementAndGet();
     }
   } catch (Throwable e) {
     testStatus.requestStopWithError(e);
   }
 }
示例#4
0
  public void testCallbacks() throws Exception {
    // Check the correct callbacks get invoked
    InitialContext ctx = new InitialContext();
    TestStatus status = (TestStatus) ctx.lookup("initial-ejb3-test/TestStatusBean/remote");
    status.clear();
    InterceptedSLTest test =
        (InterceptedSLTest) ctx.lookup("initial-ejb3-test/InterceptedSLTestBean/local");
    test.testMethod(5);
    // PostConstruct test is invalid, because you can't assume that postConstruct is called during
    // the lookup
    // the instance might already be available from a previous call or prefill of the pool.
    // if (!status.postConstruct()) throw new Exception("PostConstruct should be called for SLSB");
    if (status.prePassivate()) throw new Exception("PrePassivate should not be called for SLSB");
    if (status.postActivate()) throw new Exception("PostActivate should not be called for SLSB");

    // TODO: Figure out when destroy gets called
    // if (!status.preDestroy()) throw new Exception("PreDestroy should be called for SLSB");
  }
  private void writeCoverage(OutputStream out) throws IOException {

    out.write("<h3 id=\"coverageDetail\">Coverage Detail</h3>\n".getBytes());

    StringBuilder key = new StringBuilder();
    key.append("<table>");
    key.append("<tr><th style=\"background-color:#dddddd\">Colour Key</th></tr>");
    key.append(
        "<tr><td style=\"background-color:"
            + COLOUR_SHADE_GREEN
            + ";text-align:center\">Assertion is covered</td></tr>");
    key.append(
        "<tr><td style=\"background-color:"
            + COLOUR_SHADE_RED
            + ";text-align:center\">Assertion is not covered</td></tr>");
    key.append(
        "<tr><td style=\"background-color:"
            + COLOUR_SHADE_ORANGE
            + ";text-align:center\">Assertion test is unimplemented</td></tr>");
    key.append(
        "<tr><td style=\"background-color:"
            + COLOUR_SHADE_BLUE
            + ";text-align:center\">Assertion is untestable</td></tr>");
    key.append("</table>");
    out.write(key.toString().getBytes());

    for (String sectionId : auditParser.getSectionIds()) {

      List<AuditAssertion> sectionAssertions = auditParser.getAssertionsForSection(sectionId);

      if (sectionAssertions != null && !sectionAssertions.isEmpty()) {
        StringBuilder sb = new StringBuilder();

        out.write(
            ("<h4 class=\"sectionHeader\" id=\""
                    + sectionId
                    + "\">Section "
                    + sectionId
                    + " - "
                    + escape(auditParser.getSectionTitle(sectionId))
                    + "</h4>\n")
                .getBytes());

        for (AuditAssertion assertion : sectionAssertions) {
          List<SpecReference> coverage = getCoverageForAssertion(sectionId, assertion.getId());
          TestStatus status = getStatus(coverage);

          String divClass = null;

          if (assertion.isTestable()) {
            if (status.equals(TestStatus.UNCOVERED)) {
              divClass = "fail";
            } else if (status.equals(TestStatus.UNIMPLEMENTED)) {
              divClass = "skip";
            } else {
              divClass = "pass";
            }
          } else {
            divClass = "untestable";
          }

          sb.append("  <div class=\"" + divClass + "\">\n");

          if (assertion.isImplied()) {
            sb.append(
                "<span class=\"implied\">The following assertion is not made explicitly by the spec, however it is implied</span>");
          }

          sb.append("    <span class=\"code\">");
          sb.append(assertion.getId());
          sb.append(")");

          if (!Strings.isEmpty(assertion.getNote())) {
            sb.append(
                "<img title=\""
                    + assertion.getNote()
                    + "\" src=\"images/blank.png\" class=\"stickynote\"/>");
            // sb.append("<a title=\"" + assertion.getNote() + "\"><img title=\"" +
            // assertion.getNote() + "\" src=\"images/blank.png\" class=\"stickynote\"/></a>");
          }

          sb.append("</span>\n");

          sb.append("    <div class=\"results\">");

          sb.append("<p class=\"description\">");
          String imageFilename = sectionId + "." + assertion.getId() + ".png";
          File imageFile = new File(imageSrcDir, imageFilename);

          if (imageFile.exists()) {
            sb.append("<img src=\"images/" + imageFile.getName() + "\" class=\"embeddedImage\"/>");
            copyFile(imageFile, new File(imageTargetDir, imageFilename));
          }

          String assertionText =
              parseStrikethrough(parseBold(parseLiteral(escape(assertion.getText()))));
          sb.append(assertionText);
          sb.append("</p>\n");

          if (assertion.isTestable()) {
            sb.append("    <div class=\"coverage\">\n");
            sb.append("      <p class=\"coverageHeader\">Coverage</p>\n");

            String currentPackageName = null;

            if (status.equals(TestStatus.UNCOVERED)) {
              sb.append("        <p class=\"noCoverage\">No tests exist for this assertion</p>\n");
            } else {
              for (SpecReference ref : coverage) {
                if (!ref.getPackageName().equals(currentPackageName)) {
                  currentPackageName = ref.getPackageName();
                  sb.append("        <div class=\"packageName\">");
                  sb.append(currentPackageName);
                  sb.append("        </div>\n");
                }

                sb.append("        <div class=\"coverageMethod\">");
                sb.append(ref.getClassName());
                sb.append(".");
                sb.append(ref.getMethodName());
                sb.append("()");

                if (fisheyeBaseUrl != null) {
                  sb.append("<a class=\"external\" target=\"_blank\" href=\"");
                  sb.append(fisheyeBaseUrl);
                  sb.append(currentPackageName.replace('.', '/'));
                  sb.append("/");
                  sb.append(ref.getClassName());
                  sb.append(".java");
                  sb.append("\">fisheye</a>");
                }

                if (svnBaseUrl != null) {
                  if (fisheyeBaseUrl != null) {
                    sb.append("|");
                  }

                  sb.append("<a class=\"external\" target=\"_blank\" href=\"");
                  sb.append(svnBaseUrl);
                  sb.append(currentPackageName.replace('.', '/'));
                  sb.append("/");
                  sb.append(ref.getClassName());
                  sb.append(".java");
                  sb.append("\">svn</a>");
                }

                sb.append("</div>\n");
              }
            }

            sb.append("    </div>\n");
          } else if (!coverage.isEmpty()) {
            sb.append("<b>A test exists for this untestable assertion!</b>");
          }

          sb.append("</div></div>");
        }

        out.write(sb.toString().getBytes());
      } else {
        // We still want to be able to jump to this section by clicking on the links
        // in the chapter and section summaries
        out.write(
            ("<div style=\"visibility:hidden\" id=\"" + sectionId + "\"></div>\n").getBytes());
      }
    }
  }
  private void writeSectionSummary(OutputStream out) throws IOException {
    StringBuilder sb = new StringBuilder();

    sb.append("<h3 id=\"sectionSummary\">Section Summary</h3>\n");

    sb.append("<table width=\"100%\">");

    sb.append("<tr style=\"background-color:#dddddd\">");
    sb.append("<th align=\"left\">Section</th>");
    sb.append("<th>Assertions</th>");
    sb.append("<th>Testable</th>");
    sb.append("<th>Total Tested</th>");
    sb.append("<th>Tested<br /> (unimplemented)</th>");
    sb.append("<th>Tested<br /> (implemented)</th>");
    sb.append("<th>Coverage %</th>");
    sb.append("</tr>");

    boolean odd = true;

    for (String sectionId : auditParser.getSectionIds()) {

      if (odd) {
        sb.append("<tr style=\"background-color:#f7f7f7\">");
      } else {
        sb.append("<tr>");
      }

      odd = !odd;

      int margin = (sectionId.split("[.]").length - 1) * 16;

      sb.append("<td style=\"padding-left:" + margin + "px\">");
      sb.append("<a href=\"#" + sectionId + "\">");
      sb.append(sectionId);
      sb.append(" ");
      sb.append(auditParser.getSectionTitle(sectionId));
      sb.append("</a>");
      sb.append("</td>");

      int assertions = auditParser.getAssertionsForSection(sectionId).size();
      int testable = 0;
      int implemented = 0;
      int unimplemented = 0;

      for (AuditAssertion assertion : auditParser.getAssertionsForSection(sectionId)) {
        if (assertion.isTestable()) testable++;

        TestStatus status = getStatus(getCoverageForAssertion(sectionId, assertion.getId()));
        if (status.equals(TestStatus.COVERED)) {
          implemented++;
        } else if (status.equals(TestStatus.UNIMPLEMENTED)) {
          unimplemented++;
        }
      }

      int tested = implemented + unimplemented;

      double coveragePercent = testable > 0 ? ((implemented * 1.0) / testable) * 100 : -1;

      sb.append("<td align=\"center\">");
      sb.append(assertions);
      sb.append("</td>");

      sb.append("<td align=\"center\">");
      sb.append(testable);
      sb.append("</td>");

      sb.append("<td align=\"center\">");
      sb.append(tested);
      sb.append("</td>");

      sb.append("<td align=\"center\">");
      sb.append(unimplemented);
      sb.append("</td>");

      sb.append("<td align=\"center\">");
      sb.append(implemented);
      sb.append("</td>");

      if (coveragePercent >= 0) {
        String bgColor =
            coveragePercent < failThreshold
                ? "#ffaaaa"
                : coveragePercent < passThreshold
                    ? "#ffffaa"
                    : coveragePercent > 100 ? "#FF00CC" : "#aaffaa";

        sb.append("<td align=\"center\" style=\"background-color:" + bgColor + "\">");
        sb.append(String.format("%.2f%%", coveragePercent));
        sb.append("</td>");
      } else {
        sb.append("<td />");
      }

      sb.append("</tr>");
    }

    sb.append("</table>");
    out.write(sb.toString().getBytes());
  }
 public boolean isIgnored() {
   Method testMethod = getTestMethodIfPresent();
   return testMethod != null && TestStatus.of(testMethod).isIgnored();
 }
示例#8
0
  public void testServerMapLocalCacheUseCaseEviction() throws Exception {
    final TCObjectSelfFactory factory = new TCObjectSelfFactory();
    final CacheManager cacheManager = CacheManager.create(new Configuration().name("test-cm"));
    Cache ehcache =
        new Cache(new CacheConfiguration().name("test-cache").maxEntriesLocalHeap(2000));
    cacheManager.addCache(ehcache);

    TCObjectSelfStore tcoSelfStore = new TCObjectSelfStore(ehcache);
    final ServerMapLocalCache serverMapLocalCache = new ServerMapLocalCache(tcoSelfStore, ehcache);
    final int numMutators = 5;
    final int numReaders = 100;

    final AtomicInteger readTpsCounter = new AtomicInteger();
    final AtomicInteger nonNullReadsCounter = new AtomicInteger();
    final AtomicInteger writeTpsCounter = new AtomicInteger();
    final TestStatus testStatus = new TestStatus();

    Thread[] mutators = new Thread[numMutators];
    for (int i = 0; i < numMutators; i++) {
      mutators[i] =
          new Thread(
              new Mutator(testStatus, factory, serverMapLocalCache, writeTpsCounter),
              "Mutator thread - " + i);
      mutators[i].setDaemon(true);
      mutators[i].start();
    }

    Thread[] readers = new Thread[numReaders];
    for (int i = 0; i < numReaders; i++) {
      readers[i] =
          new Thread(
              new Reader(
                  testStatus, factory, serverMapLocalCache, readTpsCounter, nonNullReadsCounter),
              "Reader thread - " + i);
      readers[i].setDaemon(true);
      readers[i].start();
    }

    Thread reporter =
        new Thread(
            new Runnable() {
              long zeroTpsStartTime = Long.MAX_VALUE;

              public void run() {

                try {
                  final int sleepSecs = 2;
                  while (!testStatus.isStopTestRequested()) {
                    long timeInSecsSinceZeroTPS = getTimeInSecsSinceZeroTPS();
                    if (timeInSecsSinceZeroTPS > 60) {
                      throw new RuntimeException("TPS went to zero for more than 1 min");
                    }

                    int reads = readTpsCounter.getAndSet(0);
                    int nonNullReads = nonNullReadsCounter.getAndSet(0);
                    int writes = writeTpsCounter.getAndSet(0);
                    int readTps = reads / sleepSecs;
                    int writeTps = writes / sleepSecs;
                    int nonNullReadsTps = nonNullReads / sleepSecs;

                    System.out.println("============ Iteration Stats ================");
                    System.out.println("Reads: " + reads + ", Read TPS: " + readTps);
                    System.out.println(
                        "Non-null Reads: "
                            + nonNullReads
                            + ", Non-null Reads TPS: "
                            + nonNullReadsTps);
                    System.out.println("Writes: " + writes + ", Write TPS: " + writeTps);
                    System.out.println("Time since zero TPS: " + timeInSecsSinceZeroTPS + " secs");
                    if (readTps == 0 && nonNullReadsTps == 0 && writeTps == 0) {
                      if (zeroTpsStartTime == Long.MAX_VALUE) {
                        zeroTpsStartTime = System.nanoTime();
                      }
                    } else {
                      zeroTpsStartTime = Long.MAX_VALUE;
                    }
                    try {
                      Thread.sleep(sleepSecs * 1000);
                    } catch (InterruptedException e) {
                      // ignored
                    }
                  }
                } catch (Throwable t) {
                  testStatus.requestStopWithError(t);
                }
              }

              private long getTimeInSecsSinceZeroTPS() {
                if (zeroTpsStartTime != Long.MAX_VALUE) {
                  long currentTime = System.nanoTime();
                  long diff = currentTime - zeroTpsStartTime;
                  Assert.assertTrue("Diff should be > 0", diff > 0);
                  return TimeUnit.NANOSECONDS.toSeconds(diff);
                } else {
                  return -1;
                }
              }
            },
            "Reporter thread");
    reporter.setDaemon(true);
    reporter.start();

    // stop after 5 mins
    testStatus.stopAfterSeconds(60 * 5);
    if (testStatus.getError() != null) {
      testStatus.getError().printStackTrace();
      Assert.fail("Test failed with exception");
    }

    System.out.println("Test completed");

    cacheManager.shutdown();
  }