/** descendingkeySet.toArray returns contains all keys */
 public void testDescendingDescendingKeySetToArray() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.descendingKeySet();
   Object[] ar = s.toArray();
   assertEquals(5, ar.length);
   assertTrue(s.containsAll(Arrays.asList(ar)));
   ar[0] = m10;
   assertFalse(s.containsAll(Arrays.asList(ar)));
 }
Beispiel #2
0
  @Test
  public void testCompactionLog() throws Exception {
    SystemKeyspace.discardCompactionsInProgress();

    String cf = "Standard4";
    ColumnFamilyStore cfs = Keyspace.open(KEYSPACE1).getColumnFamilyStore(cf);
    insertData(KEYSPACE1, cf, 0, 1);
    cfs.forceBlockingFlush();

    Collection<SSTableReader> sstables = cfs.getSSTables();
    assert !sstables.isEmpty();
    Set<Integer> generations =
        Sets.newHashSet(
            Iterables.transform(
                sstables,
                new Function<SSTableReader, Integer>() {
                  public Integer apply(SSTableReader sstable) {
                    return sstable.descriptor.generation;
                  }
                }));
    UUID taskId = SystemKeyspace.startCompaction(cfs, sstables);
    SetMultimap<Pair<String, String>, Integer> compactionLogs =
        SystemKeyspace.getUnfinishedCompactions();
    Set<Integer> unfinishedCompactions = compactionLogs.get(Pair.create(KEYSPACE1, cf));
    assert unfinishedCompactions.containsAll(generations);

    SystemKeyspace.finishCompaction(taskId);
    compactionLogs = SystemKeyspace.getUnfinishedCompactions();
    assert !compactionLogs.containsKey(Pair.create(KEYSPACE1, cf));
  }
Beispiel #3
0
  private boolean equalsAccessPoints(HashMap<String, AccessPoint> accessPoints) {
    if (this.accessPoints == null && accessPoints == null) {
      return true;
    } else if (this.accessPoints == null
        || accessPoints == null
        || this.accessPoints.size() != accessPoints.size()) {
      return false;
    }

    Set<String> localAccessPointsIds = this.accessPoints.keySet();
    Set<String> otherAccessPointsIds = accessPoints.keySet();

    return localAccessPointsIds.containsAll(otherAccessPointsIds);
  }
  @Ignore
  @Test
  public void testNormalSimulatedSession()
      throws SolverException, InconsistentTheoryException, NoConflictException,
          OWLOntologyCreationException {
    logger.info("NormalSimulatedSession");

    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
        testSetup("ontologies/ecai2010.owl");
    Set<? extends FormulaSet<OWLLogicalAxiom>> diagnoses = getDiagnoses(search);

    Map<QSSType, DurationStat> nTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> nQueries = new HashMap<QSSType, List<Double>>();

    for (QSSType type : QSSType.values()) { // run for each scoring function
      logger.info("QSSType: " + type);

      nTimes.put(type, new DurationStat());
      nQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        logger.info("targetD: " + CalculateDiagnoses.renderAxioms(targetDiagnosis));
        long completeTime = System.currentTimeMillis();

        computeHS(search, ctTheory, targetDiagnosis, nQueries.get(type), type);
        ctTheory.getKnowledgeBase().removeFormulas(targetDiagnosis);
        completeTime = System.currentTimeMillis() - completeTime;
        nTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(targetDiagnosis);
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        search.reset();
      }
      logStatistics(nQueries, nTimes, type, "normal");
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
    }
  }
  public void run() throws Exception {
    // Selection of files to be compiled
    File absJar = createJar(new File("abs.jar").getAbsoluteFile(), "j.A");
    File relJar = createJar(new File("rel.jar"), "j.R");
    File absDir = createDir(new File("abs.dir").getAbsoluteFile(), "d.A");
    File relDir = createDir(new File("rel.dir"), "d.R");
    File absTestFile =
        writeFile(new File("AbsTest.java").getAbsoluteFile(), "class AbsTest { class Inner { } }");
    File relTestFile = writeFile(new File("RelTest.java"), "class RelTest { class Inner { } }");
    File relTest2File =
        writeFile(new File("p/RelTest2.java"), "package p; class RelTest2 { class Inner { } }");
    // This next class references other classes that will be found on the source path
    // and which will therefore need to be compiled as well.
    File mainFile =
        writeFile(new File("Main.java"), "class Main { j.A ja; j.R jr; d.A da; d.R dr; }" + "");

    String sourcePath = createPath(absJar, relJar, absDir, relDir);
    File outDir = new File("classes");
    outDir.mkdirs();

    String[] args = {
      "-sourcepath",
      sourcePath,
      "-d",
      outDir.getPath(),
      absTestFile.getPath(),
      relTestFile.getPath(),
      relTest2File.getPath(),
      mainFile.getPath(),
    };
    System.err.println("compile: " + Arrays.asList(args));
    StringWriter sw = new StringWriter();
    PrintWriter pw = new PrintWriter(sw);
    int rc = com.sun.tools.javac.Main.compile(args, pw);
    pw.close();
    if (rc != 0) {
      System.err.println(sw.toString());
      throw new Exception("unexpected exit from javac: " + rc);
    }

    Set<File> expect =
        getFiles(
            outDir,
            "d/A.class",
            "d/A$Inner.class",
            "d/R.class",
            "d/R$Inner.class",
            "j/A.class",
            "j/A$Inner.class",
            "j/R.class",
            "j/R$Inner.class",
            "AbsTest.class",
            "AbsTest$Inner.class",
            "RelTest.class",
            "RelTest$Inner.class",
            "p/RelTest2.class",
            "p/RelTest2$Inner.class",
            "Main.class");

    Set<File> found = findFiles(outDir);

    if (!found.equals(expect)) {
      if (found.containsAll(expect))
        throw new Exception("unexpected files found: " + diff(found, expect));
      else if (expect.containsAll(found))
        throw new Exception("expected files not found: " + diff(expect, found));
    }

    for (File f : found) verifySourceFileAttribute(f);

    if (errors > 0) throw new Exception(errors + " errors occurred");
  }
  @Ignore
  @Test
  public void testCompareSearchMethods()
      throws SolverException, InconsistentTheoryException, NoConflictException,
          OWLOntologyCreationException {
    logger.info("NormalSimulatedSession compared to ConflictTreeSimulatedSession");

    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> search =
        testSetup("ontologies/ecai2010.owl");
    Set<? extends FormulaSet<OWLLogicalAxiom>> diagnoses = getDiagnoses(search);

    // setup second search
    TreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom> ctSearch =
        new HsTreeSearch<FormulaSet<OWLLogicalAxiom>, OWLLogicalAxiom>();
    ctSearch.setSearchStrategy(new UniformCostSearchStrategy<OWLLogicalAxiom>());
    ctSearch.setSearcher(new QuickXplain<OWLLogicalAxiom>());
    ctSearch.setSearchable(ctTheory);
    ctSearch.setCostsEstimator(new OWLAxiomKeywordCostsEstimator(ctTheory));

    Map<QSSType, DurationStat> nTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> nQueries = new HashMap<QSSType, List<Double>>();
    Map<QSSType, DurationStat> ctTimes = new HashMap<QSSType, DurationStat>();
    Map<QSSType, List<Double>> ctQueries = new HashMap<QSSType, List<Double>>();

    for (QSSType type : QSSType.values()) { // run for each scoring function
      logger.info("QSSType: " + type);

      // run normal simulated session
      logger.info("NormalSimulatedSession");
      nTimes.put(type, new DurationStat());
      nQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        long completeTime = System.currentTimeMillis();

        computeHS(search, ctTheory, targetDiagnosis, nQueries.get(type), type);
        ctTheory.getKnowledgeBase().removeFormulas(targetDiagnosis);
        completeTime = System.currentTimeMillis() - completeTime;
        nTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(targetDiagnosis);
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        search.reset();
      }
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
      // end (run normal simulated session)

      foundDiagnoses.clear();

      // run conflict tree simulated session
      logger.info("ConflictTreeSimulatedSession");
      ctTimes.put(type, new DurationStat());
      ctQueries.put(type, new LinkedList<Double>());
      for (FormulaSet<OWLLogicalAxiom> targetDiagnosis :
          diagnoses) { // run for each possible target diagnosis
        logger.info("targetD: " + CalculateDiagnoses.renderAxioms(targetDiagnosis));

        ConflictTreeSession conflictTreeSearch = new ConflictTreeSession(this, ctTheory, ctSearch);
        long completeTime = conflictTreeSearch.search(targetDiagnosis, ctQueries, type);
        ctTimes.get(type).add(completeTime);

        foundDiagnoses.addAll(conflictTreeSearch.getDiagnosis());
        ctTheory.getReasoner().addFormulasToCache(ctTheory.getKnowledgeBase().getFaultyFormulas());
        assertTrue(ctTheory.verifyConsistency());
        ctTheory.reset();

        resetTheoryTests(ctTheory);
        ctSearch.reset();
      }
      logger.info("found Diagnoses: " + foundDiagnoses.size());
      logger.info("found Diagnosis: " + CalculateDiagnoses.renderAxioms(foundDiagnoses));
      logger.info(
          "found all target diagnoses: "
              + (foundDiagnoses.size() > 0 && foundDiagnoses.containsAll(diagnoses)));
      // end (run conflict tree simulated session)

      // print time statistics
      logStatistics(nQueries, nTimes, type, "normal");
      logStatistics(ctQueries, ctTimes, type, "treeSearch");

      foundDiagnoses.clear();
    }
  }