Beispiel #1
0
 private RemoteFileDescContext newRFDWithURN(String host, int speed) throws Exception {
   Set set = new HashSet();
   try {
     // for convenience, don't require that they pass the urn.
     // assume a null one is the TestFile's hash.
     set.add(TestFile.hash());
   } catch (Exception e) {
     fail("SHA1 not created");
   }
   return toContext(
       remoteFileDescFactory.createRemoteFileDesc(
           new ConnectableImpl(host, 1, false),
           0,
           "asdf",
           TestFile.length(),
           new byte[16],
           speed,
           4,
           false,
           null,
           set,
           false,
           "",
           -1));
 }
  @Override
  protected void analyzeAndCheck(File testDataFile, List<TestFile> testFiles) {
    List<JetFile> jetFiles = getJetFiles(testFiles);

    CliLightClassGenerationSupport support =
        CliLightClassGenerationSupport.getInstanceForCli(getProject());

    BindingContext bindingContext =
        AnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(
                getProject(),
                jetFiles,
                support.getTrace(),
                Predicates.<PsiFile>alwaysTrue(),
                false,
                support.getModule(),
                MemberFilter.ALWAYS_TRUE)
            .getBindingContext();

    boolean ok = true;

    StringBuilder actualText = new StringBuilder();
    for (TestFile testFile : testFiles) {
      ok &= testFile.getActualText(bindingContext, actualText);
    }

    JetTestUtils.assertEqualsToFile(testDataFile, actualText.toString());

    assertTrue("Diagnostics mismatch. See the output above", ok);

    checkAllResolvedCallsAreCompleted(jetFiles, bindingContext);
  }
  /** tests that an uploader will pass a push loc which will be included in the swarm */
  public void testUploaderPassesPushLoc() throws Exception {
    LOG.info("-Testing swarming from two sources one based on a push alt...");
    final int RATE = 500;
    testUploaders[0].setRate(RATE);
    testUploaders[0].stopAfter(800000);

    TestUploader pusher = injector.getInstance(TestUploader.class);
    pusher.start("push uploader");
    pusher.setRate(RATE);

    GUID guid = new GUID();
    AlternateLocation pushLoc =
        alternateLocationFactory.create(
            guid.toHexString() + ";127.0.0.1:" + PPORT_1, TestFile.hash());

    AlternateLocationCollection<AlternateLocation> alCol =
        AlternateLocationCollection.create(TestFile.hash());
    alCol.add(pushLoc);

    testUploaders[0].setGoodAlternateLocations(alCol);

    RemoteFileDesc rfd = newRFDWithURN(PORTS[0], TestFile.hash().toString(), false);

    RemoteFileDesc[] rfds = {rfd};

    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_1, networkManager.getPort(), savedFile.getName(), pusher, guid, _currentTestName);

    tGeneric(rfds);

    assertGreaterThan(
        "u1 didn't do enough work ", 100 * 1024, testUploaders[0].fullRequestsUploaded());
    assertGreaterThan("pusher didn't do enough work ", 100 * 1024, pusher.fullRequestsUploaded());
  }
  public void testSimpleSwarmPush() throws Exception {
    LOG.info("-Testing swarming from two sources, one push...");

    GUID guid = new GUID();
    RemoteFileDesc rfd1 = newRFDWithURN(PORTS[0], false);
    AlternateLocation pushLoc =
        alternateLocationFactory.create(
            guid.toHexString() + ";127.0.0.1:" + PPORT_2, TestFile.hash());
    ((PushAltLoc) pushLoc).updateProxies(true);
    RemoteFileDesc rfd2 = pushLoc.createRemoteFileDesc(TestFile.length(), remoteFileDescFactory);

    TestUploader uploader = injector.getInstance(TestUploader.class);
    uploader.start("push uploader");
    uploader.setRate(100);
    testUploaders[0].setRate(100);

    RemoteFileDesc[] rfds = {rfd1, rfd2};

    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_2, networkManager.getPort(), savedFile.getName(), uploader, guid, _currentTestName);

    tGeneric(rfds);

    assertLessThan(
        "u1 did all the work", TestFile.length(), testUploaders[0].fullRequestsUploaded());

    assertGreaterThan("pusher did all the work ", 0, testUploaders[0].fullRequestsUploaded());
  }
  /**
   * tests that a download from a push location becomes an alternate location.
   *
   * <p>It creates a push uploader from which we must create a PushLoc. After a while, two open
   * uploaders join the swarm -one which is interested in receiving push locs and one which isn't.
   * The interested one should receive the push loc, the other one should not.
   */
  public void testPusherBecomesPushLocAndSentToInterested() throws Exception {
    LOG.info("-Testing push download creating a push location...");
    final int RATE = 200;
    testUploaders[0].setRate(RATE);
    testUploaders[0].setInterestedInFalts(true);
    testUploaders[0].stopAfter(600000);
    testUploaders[1].setRate(RATE);
    testUploaders[1].setInterestedInFalts(false);
    testUploaders[1].stopAfter(300000);

    TestUploader pusher = injector.getInstance(TestUploader.class);
    pusher.start("push uploader");
    pusher.setRate(RATE);
    pusher.stopAfter(200000);

    GUID guid = new GUID();
    AlternateLocation pushLoc =
        alternateLocationFactory.create(
            guid.toHexString() + ";127.0.0.2:" + PPORT_1, TestFile.hash());

    RemoteFileDesc pushRFD = newRFDPush(guid, PPORT_1, 1, 2);

    PushEndpoint pushEndpoint = (PushEndpoint) pushRFD.getAddress();
    assertEquals(0, pushEndpoint.getFWTVersion());

    RemoteFileDesc openRFD1 = newRFDWithURN(PORTS[0], TestFile.hash().toString(), false);
    RemoteFileDesc openRFD2 = newRFDWithURN(PORTS[1], TestFile.hash().toString(), false);

    RemoteFileDesc[] now = {pushRFD};
    HashSet<RemoteFileDesc> later = new HashSet<RemoteFileDesc>();
    later.add(openRFD1);
    later.add(openRFD2);

    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_1, networkManager.getPort(), savedFile.getName(), pusher, guid, _currentTestName);

    ManagedDownloader download =
        (ManagedDownloader) downloadServices.download(now, RemoteFileDesc.EMPTY_LIST, null, false);
    Thread.sleep(1000);
    download.addDownload(later, false);

    waitForComplete();

    assertGreaterThan("u1 did no work", 100000, testUploaders[0].getAmountUploaded());

    assertGreaterThan("u2 did no work", 100000, testUploaders[1].getAmountUploaded());
    assertLessThan("u2 did too much work", 550 * 1024, testUploaders[1].getAmountUploaded());

    assertGreaterThan("pusher did no work", 100 * 1024, pusher.getAmountUploaded());

    List alc = testUploaders[0].getIncomingGoodAltLocs();
    assertTrue("interested uploader did not get pushloc", alc.contains(pushLoc));

    alc = testUploaders[1].getIncomingGoodAltLocs();
    assertFalse("not interested uploader got pushloc", alc.contains(pushLoc));

    alc = pusher.getIncomingGoodAltLocs();
    assertFalse("not interested uploader got pushloc", alc.contains(pushLoc));
  }
Beispiel #6
0
 /** Close the context. */
 public void close() {
   try {
     ((Context) cx).exit();
   } catch (Exception e) {
     suite.passed = false;
     file.passed = false;
     file.exception = "file failed with exception:  " + e;
   }
 }
 @Test
 public void testReportWithoutAggregate() throws Exception {
   SurefireLauncher surefireLauncher = unpack().failNever();
   surefireLauncher.executeTest();
   surefireLauncher.reset();
   surefireLauncher.executeSurefireReport();
   OutputValidator module1 = surefireLauncher.getSubProjectValidator("module1");
   TestFile siteFile = module1.getSiteFile("surefire-report.html");
   siteFile.assertContainsText("MyModule1ClassTest");
   siteFile.assertContainsText("MyDummyClassM1Test");
 }
  @Test
  public void testReportWithAggregate() throws Exception {

    SurefireLauncher surefireLauncher = unpack().failNever();
    surefireLauncher.executeTest();
    surefireLauncher.addGoal("-Daggregate=true");
    OutputValidator validator = surefireLauncher.executeSurefireReport();
    TestFile siteFile = validator.getSiteFile("surefire-report.html");
    siteFile.assertContainsText("MyModule1ClassTest");
    siteFile.assertContainsText("MyModule2ClassTest");
    siteFile.assertContainsText("MyDummyClassM1Test");
  }
  /** tests that bad push locs get removed */
  public void testBadPushLocGetsDemotedNotAdvertised() throws Exception {
    setDownloadWaitTime(2 * DOWNLOAD_WAIT_TIME);
    LOG.info("test that bad push loc gets demoted and not advertised");
    // this test needs to go slowly so that the push attempt may time out
    final int RATE = 15;

    testUploaders[0].setInterestedInFalts(true);
    testUploaders[1].setInterestedInFalts(true);
    testUploaders[0].setRate(RATE);
    testUploaders[1].setRate(RATE);
    testUploaders[0].stopAfter(550000);
    testUploaders[1].stopAfter(550000);

    GUID guid = new GUID();
    AlternateLocation badPushLoc =
        alternateLocationFactory.create(guid.toHexString() + ";1.2.3.4:5", TestFile.hash());
    ((PushAltLoc) badPushLoc).updateProxies(true);

    AlternateLocationCollection<AlternateLocation> alc =
        AlternateLocationCollection.create(TestFile.hash());

    alc.add(badPushLoc);

    testUploaders[0].setGoodAlternateLocations(alc);

    RemoteFileDesc rfd1 = newRFDWithURN(PORTS[0], false);
    RemoteFileDesc rfd2 = newRFDWithURN(PORTS[1], false);

    RemoteFileDesc[] rfds = {rfd1, rfd2};

    tGeneric(rfds);

    assertGreaterThan("u1 did no work", 100 * 1024, testUploaders[0].fullRequestsUploaded());
    assertGreaterThan("u2 did no work", 100 * 1024, testUploaders[1].fullRequestsUploaded());

    assertFalse(
        "bad pushloc got advertised",
        testUploaders[1].getIncomingGoodAltLocs().contains(badPushLoc));
    assertEquals(1, testUploaders[0].getIncomingGoodAltLocs().size());
    assertTrue(
        testUploaders[0].getIncomingGoodAltLocs().contains(alternateLocationFactory.create(rfd2)));

    assertEquals(1, testUploaders[0].getIncomingBadAltLocs().size());
    AlternateLocation current = testUploaders[0].getIncomingBadAltLocs().get(0);
    assertTrue(current instanceof PushAltLoc);
    PushAltLoc pcurrent = (PushAltLoc) current;
    assertEquals(guid.bytes(), pcurrent.getPushAddress().getClientGUID());

    // Now get the PE from our cache and make sure no proxies exist & its demoted.
    PushEndpoint pe = injector.getInstance(PushEndpointCache.class).getPushEndpoint(guid);
    assertTrue("pe: " + pe, pe.getProxies().isEmpty());
    assertTrue("pe: " + pe, badPushLoc.isDemoted());
  }
  /**
   * tests that a push uploader passes push loc and the new push loc receives the first uploader as
   * an altloc.
   */
  public void testPushUploaderPassesPushLoc() throws Exception {
    LOG.info("Test push uploader passes push loc");
    final int RATE = 500;

    TestUploader first = injector.getInstance(TestUploader.class);
    first.start("first pusher");
    first.setRate(RATE / 3);
    first.stopAfter(700000);

    TestUploader second = injector.getInstance(TestUploader.class);
    second.start("second pusher");
    second.setRate(RATE);
    second.stopAfter(700000);
    second.setInterestedInFalts(true);

    GUID guid = new GUID();
    GUID guid2 = new GUID(GUID.makeGuid());

    AlternateLocation firstLoc =
        alternateLocationFactory.create(
            guid.toHexString() + ";127.0.0.2:" + PPORT_1, TestFile.hash());

    AlternateLocation pushLoc =
        alternateLocationFactory.create(
            guid2.toHexString() + ";127.0.0.2:" + PPORT_2, TestFile.hash());

    AlternateLocationCollection<AlternateLocation> alCol =
        AlternateLocationCollection.create(TestFile.hash());
    alCol.add(pushLoc);

    first.setGoodAlternateLocations(alCol);

    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_1, networkManager.getPort(), savedFile.getName(), first, guid, _currentTestName);
    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_2, networkManager.getPort(), savedFile.getName(), second, guid2, _currentTestName);

    RemoteFileDesc[] rfd = {newRFDPush(guid, PPORT_1, 1, 2)};

    tGeneric(rfd);

    assertGreaterThan("first pusher did no work", 100000, first.fullRequestsUploaded());
    assertGreaterThan("second pusher did no work", 100000, second.fullRequestsUploaded());

    assertEquals(1, second.getIncomingGoodAltLocs().size());

    assertTrue(
        "interested uploader didn't get first loc",
        second.getIncomingGoodAltLocs().contains(firstLoc));
  }
  public void testSimplePushDownload() throws Exception {
    int successfulPushes =
        ((AtomicInteger) ((Map) statsTracker.inspect()).get("push connect success")).intValue();
    LOG.info("-Testing non-swarmed push download");

    GUID guid = new GUID();
    AlternateLocation pushLoc =
        alternateLocationFactory.create(
            guid.toHexString() + ";127.0.0.1:" + PPORT_1, TestFile.hash());
    ((PushAltLoc) pushLoc).updateProxies(true);

    RemoteFileDesc rfd = newRFDPush(guid, PPORT_1, 1);

    assertTrue(rfd.getAddress() instanceof PushEndpoint);

    RemoteFileDesc[] rfds = {rfd};
    TestUploader uploader = injector.getInstance(TestUploader.class);
    uploader.start("push uploader");
    testUDPAcceptorFactoryImpl.createTestUDPAcceptor(
        PPORT_1, networkManager.getPort(), savedFile.getName(), uploader, guid, _currentTestName);

    tGeneric(rfds);
    assertEquals(
        successfulPushes + 1,
        ((AtomicInteger) ((Map) statsTracker.inspect()).get("push connect success")).intValue());
  }
Beispiel #12
0
  /**
   * Creates the JavaScript Context, which evaluates the contents of a RhinoFile and returns a
   * result. The RhinoEnv parses the test result, and sets values of the RhinoFile test result
   * properties.
   *
   * @see com.netscape.javascript.Context#setOptimizationLevel
   * @see com.netscape.javascript.Context#setDebugLevel
   */
  public synchronized void runTest() {
    this.driver.p(file.name);
    try {
      cx = createContext();
      ((Context) cx).setOptimizationLevel(driver.OPT_LEVEL);
      ((Context) cx).setDebugLevel(driver.DEBUG_LEVEL);
      Object loadFn = executeTestFile(driver.HELPER_FUNCTIONS.getAbsolutePath());

      file.startTime = driver.getCurrentTime();
      result = executeTestFile(file.filePath);
      file.endTime = driver.getCurrentTime();
      parseResult();

    } catch (Exception e) {
      suite.passed = false;
      file.passed = false;
      file.exception += "file failed with exception:  " + e;
    }
  }
  /**
   * tests that when we receive a headpong claiming that it doesn't have the file, we send out an
   * NAlt for that source
   */
  public void testHeadPongNAlts() throws Exception {

    testUploaders[0].setRate(100);
    testUploaders[1].setRate(100);

    int sleep = DownloadSettings.WORKER_INTERVAL.getValue();

    // make sure we use the ping ranker
    networkManager.setCanReceiveSolicited(true);
    assertTrue(networkManager.canReceiveSolicited());
    assertTrue(sourceRankerFactory.getAppropriateRanker() instanceof FriendsFirstSourceRanker);

    // create one source that will actually download and another one to which a headping should be
    // sent
    RemoteFileDesc rfd = newRFDWithURN(PORTS[0], false);
    RemoteFileDesc noFile = newRFDWithURN(PORTS[1], false);

    AlternateLocation toBeDemoted = alternateLocationFactory.create(noFile);

    // create a listener for the headping
    TestUDPAcceptor l =
        testUDPAcceptorFactoryImpl.createTestUDPAcceptor(PORTS[1], _currentTestName);

    ManagedDownloaderImpl download =
        (ManagedDownloaderImpl)
            downloadServices.download(
                new RemoteFileDesc[] {rfd}, RemoteFileDesc.EMPTY_LIST, null, false);
    SourceRanker ranker = download.getCurrentSourceRanker();
    assertTrue(ranker instanceof FriendsFirstSourceRanker);
    LOG.debug("started download");

    // after a while clear the ranker and add the second host.
    Thread.sleep((int) (sleep * 1.5));
    ranker.stop();
    ranker.setMeshHandler(download);
    download.addDownload(noFile, false);

    LOG.debug("waiting for download to complete");
    waitForComplete();

    // the first downloader should have received an NAlt
    assertTrue(testUploaders[0].getIncomingBadAltLocs().contains(toBeDemoted));
    // the first uploader should have uploaded the whole file
    assertGreaterThan(0, testUploaders[0].getConnections());
    assertEquals(TestFile.length(), testUploaders[0].fullRequestsUploaded());

    // the second downloader should not be contacted
    assertEquals(0, testUploaders[1].getConnections());
    assertEquals(0, testUploaders[1].getAmountUploaded());
    // only one ping should have been sent to the second uploader
    assertEquals(1, l.pings);

    l.shutdown();
  }
 public TestFile getTestDirectory() {
   if (dir == null) {
     if (prefix == null) {
       // This can happen if this is used in a constructor or a @Before method. It also happens
       // when using
       // @RunWith(SomeRunner) when the runner does not support rules.
       prefix = determinePrefix();
     }
     while (true) {
       // Use a random prefix to avoid reusing test directories
       String prefix =
           Integer.toString(RANDOM.nextInt(MAX_RANDOM_PART_VALUE), ALL_DIGITS_AND_LETTERS_RADIX);
       if (WINDOWS_RESERVED_NAMES.matcher(prefix).matches()) {
         continue;
       }
       dir = root.file(this.prefix, prefix);
       if (dir.mkdirs()) {
         break;
       }
     }
   }
   return dir;
 }
 @Override
 public void evaluate() throws Throwable {
   base.evaluate();
   // Don't delete on failure
   try {
     testDirectory.deleteDir();
   } catch (Exception e) {
     boolean suppressException = leaksHandles && OperatingSystem.current().isWindows();
     if (suppressException) {
       e.printStackTrace();
     } else {
       throw e;
     }
   }
 }
Beispiel #16
0
 private RemoteFileDescContext newRFD(String host, int speed) throws Exception {
   return toContext(
       remoteFileDescFactory.createRemoteFileDesc(
           new ConnectableImpl(host, 1, false),
           0,
           "asdf",
           TestFile.length(),
           new byte[16],
           speed,
           4,
           false,
           null,
           URN.NO_URN_SET,
           false,
           "",
           -1));
 }
  public static void main(String[] args) {

    // load a sample document (the contents are equal to "DarmstadtWikipediaArticle.txt")
    String documentText = TestFile.getFileText();

    // get a ParsedPage object
    MediaWikiParserFactory pf = new MediaWikiParserFactory();
    MediaWikiParser parser = pf.createParser();
    ParsedPage pp = parser.parse(documentText);

    // Link Context (return 1 token left, 2 token right of the link)
    for (Link link : pp.getLinks()) {
      System.out.println(
          link.getContext(1, 0)
              + "<"
              + link.getText().toString().toUpperCase()
              + ">"
              + link.getContext(0, 2));
    }
  }
  public void run() {

    TestFile.testFile(filenameString);
  }
Beispiel #19
0
  /**
   * Evaluates the RhinoFile result. If the result is an instance of javax.javascript.Scriptable,
   * assume it is a JavaScript Array of TestCase objects, as described in RhinoDrv.java. For each
   * test case in the array, add an element to the RhinoFile's test case vector. If all test cases
   * passed, set the RhinoFile's passed value to true; else set its passed value to false.
   *
   * <p>If the result is not a Scriptable object, the test failed. Set the the RhinoFile's exception
   * property to the string value of the result. However, negative tests, which should have a
   * "-n.js" extension, are expected to fail.
   */
  public boolean parseResult() {
    FlattenedObject fo = null;

    if (result instanceof Scriptable) {
      fo = new FlattenedObject((Scriptable) result);

      try {
        file.totalCases = ((Number) fo.getProperty("length")).intValue();
        for (int i = 0; i < file.totalCases; i++) {
          Scriptable tc = (Scriptable) ((Scriptable) result).get(i, (Scriptable) result);

          TestCase rt =
              new TestCase(
                  getString(tc.get("passed", tc)),
                  getString(tc.get("name", tc)),
                  getString(tc.get("description", tc)),
                  getString(tc.get("expect", tc)),
                  getString(tc.get("actual", tc)),
                  getString(tc.get("reason", tc)));

          file.bugnumber =
              (getString(tc.get("bugnumber", tc))).startsWith("com.netscape.javascript")
                  ? file.bugnumber
                  : getString(tc.get("bugnumber", tc));

          file.caseVector.addElement(rt);
          if (rt.passed.equals("false")) {
            this.file.passed = false;
            this.suite.passed = false;
          }
        }

        if (file.totalCases == 0) {
          if (file.name.endsWith("-n.js")) {
            this.file.passed = true;
          } else {
            this.file.reason = "File contains no testcases. " + this.file.reason;
            this.file.passed = false;
            this.suite.passed = false;
          }
        }

      } catch (Exception e) {
        this.file.exception =
            "Got a Scriptable result, but failed "
                + "parsing its arguments.  Exception: "
                + e.toString()
                + " Flattened Object is: "
                + fo.toString();

        this.file.passed = false;
        this.suite.passed = false;

        return false;
      }
    } else {
      // if it's not a scriptable object, test failed.  set the file's
      // exception to the string value of whatever result we did get.
      this.file.exception = result.toString();

      // if the file's name ends in "-n", the test expected an error.

      if (file.name.endsWith("-n.js")) {
        this.file.passed = true;
      } else {
        this.file.passed = false;
        this.suite.passed = false;
        return false;
      }
    }

    return true;
  }