Search in sources :

Example 6 with Assert

use of org.junit.Assert in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method sstableListChangedAddAndRemove.

@Test
public void sstableListChangedAddAndRemove() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    SSTableReader sstable1 = makeSSTable(true);
    mutateRepaired(sstable1, repairID);
    SSTableReader sstable2 = makeSSTable(true);
    mutateRepaired(sstable2, repairID);
    Assert.assertFalse(repairedContains(sstable1));
    Assert.assertFalse(unrepairedContains(sstable1));
    Assert.assertFalse(repairedContains(sstable2));
    Assert.assertFalse(unrepairedContains(sstable2));
    csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
    // add only
    SSTableListChangedNotification notification;
    notification = new SSTableListChangedNotification(Collections.singleton(sstable1), Collections.emptyList(), OperationType.COMPACTION);
    csm.handleNotification(notification, cfs.getTracker());
    csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
    Assert.assertFalse(repairedContains(sstable1));
    Assert.assertFalse(unrepairedContains(sstable1));
    Assert.assertTrue(pendingContains(repairID, sstable1));
    Assert.assertFalse(repairedContains(sstable2));
    Assert.assertFalse(unrepairedContains(sstable2));
    Assert.assertFalse(pendingContains(repairID, sstable2));
    // remove and add
    notification = new SSTableListChangedNotification(Collections.singleton(sstable2), Collections.singleton(sstable1), OperationType.COMPACTION);
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(repairedContains(sstable1));
    Assert.assertFalse(unrepairedContains(sstable1));
    Assert.assertFalse(pendingContains(repairID, sstable1));
    Assert.assertFalse(repairedContains(sstable2));
    Assert.assertFalse(unrepairedContains(sstable2));
    Assert.assertTrue(pendingContains(repairID, sstable2));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) SSTableListChangedNotification(org.apache.cassandra.notifications.SSTableListChangedNotification) Assert(org.junit.Assert) UUID(java.util.UUID) Test(org.junit.Test)

Example 7 with Assert

use of org.junit.Assert in project cassandra by apache.

the class CompactionStrategyManagerPendingRepairTest method sstableRepairStatusChanged.

@Test
public void sstableRepairStatusChanged() {
    UUID repairID = registerSession(cfs, true, true);
    LocalSessionAccessor.prepareUnsafe(repairID, COORDINATOR, PARTICIPANTS);
    // add as unrepaired
    SSTableReader sstable = makeSSTable(false);
    Assert.assertTrue(unrepairedContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
    csm.getForPendingRepair(repairID).forEach(Assert::assertNull);
    SSTableRepairStatusChanged notification;
    // change to pending repaired
    mutateRepaired(sstable, repairID);
    notification = new SSTableRepairStatusChanged(Collections.singleton(sstable));
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertFalse(repairedContains(sstable));
    csm.getForPendingRepair(repairID).forEach(Assert::assertNotNull);
    Assert.assertTrue(pendingContains(repairID, sstable));
    // change to repaired
    mutateRepaired(sstable, System.currentTimeMillis());
    notification = new SSTableRepairStatusChanged(Collections.singleton(sstable));
    csm.handleNotification(notification, cfs.getTracker());
    Assert.assertFalse(unrepairedContains(sstable));
    Assert.assertTrue(repairedContains(sstable));
    Assert.assertFalse(pendingContains(repairID, sstable));
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) Assert(org.junit.Assert) SSTableRepairStatusChanged(org.apache.cassandra.notifications.SSTableRepairStatusChanged) UUID(java.util.UUID) Test(org.junit.Test)

Example 8 with Assert

use of org.junit.Assert in project L42 by ElvisResearchGroup.

the class Test212_or_170_MethodTypes method testListGenerateAllOfMap.

@Test
public void testListGenerateAllOfMap() {
    for (MethodType mt : dataSet) {
        Map<MethodType, String> all = fixMap(mt);
        List<MethodType> list = AlternativeMethodTypes.types(mt);
        //mi(mVp would be promotable in imm, but is unuseful:
        //the direct promotion to mc is more expressive
        Set<MethodType> removeUnuseful = all.entrySet().stream().filter(e -> !e.getValue().contains("mI(mVp")).map(e -> e.getKey()).collect(Collectors.toSet());
        boolean either = new HashSet<>(list).equals(removeUnuseful) || new HashSet<>(list).equals(all.keySet());
        assert either : mapToS(all) + "\n" + mtsToS(list);
    }
}
Also used : TestProgram(programReduction.TestProgram) WellFormednessCore(auxiliaryGrammar.WellFormednessCore) Arrays(java.util.Arrays) Program(programReduction.Program) Path(ast.Ast.Path) Collection(java.util.Collection) Type(ast.Ast.Type) Set(java.util.Set) HashMap(java.util.HashMap) Test(org.junit.Test) MethodType(ast.Ast.MethodType) Collectors(java.util.stream.Collectors) Functions(auxiliaryGrammar.Functions) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) Map(java.util.Map) Assert(org.junit.Assert) Collections(java.util.Collections) AlternativeMethodTypes(newTypeSystem.AlternativeMethodTypes) Mdf(ast.Ast.Mdf) MethodType(ast.Ast.MethodType) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 9 with Assert

use of org.junit.Assert in project textdb by TextDB.

the class StatementTestUtils method assertGeneratedBeans.

/**
     * Assert the generated beans by a statement are a valid direct acyclic graph (no cycles nor unreached nodes/links 
     * are present) and that the given list of operators are present in the right order in the path from the initial 
     * node to the final node (while ignoring the PassThroughBean and the value of the ID).
     * The following checks are performed:
     * -Check whether all the build operators have unique IDs (between them).
     * -Check whether the generated links are unique (no duplicate links).
     * -Check whether a path from the initial to the final node exists.
     * -Check whether all the operators in the path between the initial and the final node is are present in
     *     expectedOperators in the same order (ignoring the PassThroughBean)
     * -Check whether all the links connect existing operators.
     * -Check whether all the operator beans are visited once at most (no cycles).
     * -Check whether all the link beans are visited once at most (no cycles).
     * -Check whether all the operators, except for the final operator, have output arity equals to one.
     * -Check whether all the operators beans generated are reachable.
     * -Check whether all the link beans generated are reachable.
     * 
     * @param statement The statement to build the beans to be checked.
     * @param expectedOperators The list of the expected OperatorBeans to be build by the statement.
     */
public static void assertGeneratedBeans(Statement statement, List<PredicateBase> expectedOperators) {
    // Get operators and links from statement
    List<PredicateBase> operators = statement.getInternalOperatorBeans();
    List<OperatorLink> links = statement.getInternalLinkBeans();
    // Assert all statements have an unique id (check whether two operators have the same ID)
    boolean uniqueIds = operators.stream().collect(Collectors.groupingBy(op -> op.getID(), Collectors.counting())).values().stream().allMatch(count -> (count == 1));
    Assert.assertTrue(uniqueIds);
    // Iterate the graph (string of nodes) to look for the expected beans
    HashSet<PredicateBase> visitedOperators = new HashSet<>();
    HashSet<OperatorLink> visitedLinks = new HashSet<>();
    String initialNode = statement.getInputNodeID();
    String finalNode = statement.getOutputNodeID();
    Iterator<PredicateBase> expectedOperatorsIterator = expectedOperators.iterator();
    PredicateBase nextExpectedOperator = null;
    // Start from the initial node and stop when the final node is reached (or an Assert fail)
    String currentBeanId = initialNode;
    while (true) {
        // Get the next expected operator to find (if needed)
        if (nextExpectedOperator == null && expectedOperatorsIterator.hasNext()) {
            nextExpectedOperator = expectedOperatorsIterator.next();
        }
        // Get the current bean by ID
        String currentLookingBeanId = currentBeanId;
        PredicateBase currentOperatorBean = operators.stream().filter(op -> op.getID().equals(currentLookingBeanId)).findAny().orElse(null);
        Assert.assertNotNull(currentOperatorBean);
        // Add the current visited bean to the set of visited beans and assert it hasn't been visited yet (cycle check)
        Assert.assertTrue(visitedOperators.add(currentOperatorBean));
        // Compare the current bean with the next expected bean
        if (nextExpectedOperator != null && currentOperatorBean.getClass() == nextExpectedOperator.getClass()) {
            // Copy the id of the current bean to the bean we are looking for and assert they are equal
            nextExpectedOperator.setID(currentOperatorBean.getID());
            Assert.assertEquals(nextExpectedOperator, currentOperatorBean);
            nextExpectedOperator = null;
        } else if (!(currentOperatorBean instanceof PassThroughPredicate)) {
            // Found a bean that is not PassThrough and is not the expected operator!
            Assert.fail();
        }
        // Break once the final node is visited
        if (currentBeanId.equals(finalNode)) {
            break;
        }
        // Get outgoing links for the current bean
        List<OperatorLink> currentOperatorBeanOutgoingLinks = links.stream().filter(link -> link.getOrigin().equals(currentOperatorBean.getID())).collect(Collectors.toList());
        // Assert there is only one outgoing link
        Assert.assertEquals(currentOperatorBeanOutgoingLinks.size(), 1);
        OperatorLink currentOperatorBeanOutgoingLink = currentOperatorBeanOutgoingLinks.get(0);
        // Add the outgoing link to the set of visited links and assert it hasn't been visited yet (cycle and duplicate check)
        Assert.assertTrue(visitedLinks.add(currentOperatorBeanOutgoingLink));
        // Set the current bean id to the next bean
        currentBeanId = currentOperatorBeanOutgoingLink.getDestination();
    }
    // Assert there are no more expected operators to look for
    Assert.assertFalse(expectedOperatorsIterator.hasNext());
    // Assert all the operators generated by the statement are visited (no unreachable operators)
    Assert.assertTrue(visitedOperators.containsAll(operators));
    // Assert all the links generated by the statement are visited (no unreachable links)
    Assert.assertTrue(visitedLinks.containsAll(links));
}
Also used : HashSet(java.util.HashSet) List(java.util.List) OperatorLink(edu.uci.ics.textdb.exp.plangen.OperatorLink) Iterator(java.util.Iterator) Statement(edu.uci.ics.textdb.textql.statements.Statement) Assert(org.junit.Assert) PassThroughPredicate(edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate) Collectors(java.util.stream.Collectors) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) OperatorLink(edu.uci.ics.textdb.exp.plangen.OperatorLink) PredicateBase(edu.uci.ics.textdb.exp.common.PredicateBase) PassThroughPredicate(edu.uci.ics.textdb.textql.planbuilder.beans.PassThroughPredicate) HashSet(java.util.HashSet)

Example 10 with Assert

use of org.junit.Assert in project intellij-community by JetBrains.

the class PyAbstractTestProcessRunner method assertAllTestsAreResolved.

/**
   * Ensures all test locations are resolved (i.e. user may click on test and navigate to it)
   * All tests are checked but [root] (it never resolves).
   */
public final void assertAllTestsAreResolved(@NotNull final Project project) {
    final List<SMTestProxy> allTests = getTestProxy().getAllTests();
    assert !allTests.isEmpty() : "No tests at all.";
    final GlobalSearchScope scope = GlobalSearchScope.allScope(project);
    EdtTestUtil.runInEdtAndWait(() -> allTests.subList(1, allTests.size()).forEach(t -> Assert.assertNotNull("No location " + t, t.getLocation(project, scope))));
}
Also used : ExecutionException(com.intellij.execution.ExecutionException) EdtTestUtil(com.intellij.testFramework.EdtTestUtil) ModalityState(com.intellij.openapi.application.ModalityState) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) AbstractPythonRunConfigurationParams(com.jetbrains.python.run.AbstractPythonRunConfigurationParams) Filter(com.intellij.execution.testframework.Filter) RerunFailedActionsTestTools(com.intellij.execution.testframework.actions.RerunFailedActionsTestTools) Project(com.intellij.openapi.project.Project) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) Logger(com.intellij.openapi.diagnostic.Logger) SMRootTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy.SMRootTestProxy) ProgramRunner(com.intellij.execution.runners.ProgramRunner) ConsoleViewImpl(com.intellij.execution.impl.ConsoleViewImpl) StringUtil(com.intellij.openapi.util.text.StringUtil) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) AbstractTestProxy(com.intellij.execution.testframework.AbstractTestProxy) ConfigurationFactory(com.intellij.execution.configurations.ConfigurationFactory) ProcessHandler(com.intellij.execution.process.ProcessHandler) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SMTRunnerConsoleView(com.intellij.execution.testframework.sm.runner.ui.SMTRunnerConsoleView) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Assert(org.junit.Assert) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) SMTestProxy(com.intellij.execution.testframework.sm.runner.SMTestProxy) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope)

Aggregations

Assert (org.junit.Assert)18 Test (org.junit.Test)14 List (java.util.List)7 ArrayList (java.util.ArrayList)5 UUID (java.util.UUID)5 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)5 HashSet (java.util.HashSet)3 Collectors (java.util.stream.Collectors)3 SSTableAddedNotification (org.apache.cassandra.notifications.SSTableAddedNotification)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Project (com.intellij.openapi.project.Project)2 Ref (com.intellij.openapi.util.Ref)2 InetAddress (java.net.InetAddress)2 Arrays (java.util.Arrays)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 HashMap (java.util.HashMap)2 Iterator (java.util.Iterator)2 Map (java.util.Map)2 Set (java.util.Set)2