diff --git a/ethereal/src/main/java/com/salesforce/apollo/ethereal/Checks.java b/ethereal/src/main/java/com/salesforce/apollo/ethereal/Checks.java deleted file mode 100644 index 105ec5a19..000000000 --- a/ethereal/src/main/java/com/salesforce/apollo/ethereal/Checks.java +++ /dev/null @@ -1,80 +0,0 @@ -/* - * Copyright (c) 2021, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: BSD-3-Clause - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause - */ -package com.salesforce.apollo.ethereal; - -import java.util.Arrays; -import java.util.List; -import java.util.function.BiFunction; - -/** - * @author hal.hildebrand - * - */ -public interface Checks { - - static BiFunction basicCorrectness() { - return (u, dag) -> { - var parents = u.parents(); - var nproc = dag.nProc(); - if (parents.length != nproc) { - return Correctness.COMPLIANCE_ERROR; - } - short nonNillParents = 0; - for (short i = 0; i < nproc; i++) { - if (parents[i] == null) { - continue; - } - nonNillParents++; - if (parents[i].creator() != i) { - return Correctness.COMPLIANCE_ERROR; - } - } - if (u.predecessor() == null && nonNillParents > 0) { - return Correctness.COMPLIANCE_ERROR; - } - if (u.predecessor() != null && u.predecessor().level() >= u.level()) { - return Correctness.COMPLIANCE_ERROR; - } - return null; - }; - } - - static BiFunction forkerMuting() { - return (u, dag) -> null; - } - - static BiFunction noForks() { - return (u, dag) -> null; - } - - static BiFunction noLevelSkipping() { - return (u, dag) -> null; - } - - static BiFunction noSelfForkingEvidence() { - return (u, dag) -> null; - } - - static BiFunction parentConsistency() { - return (unit, dag) -> { - var parents = unit.parents(); - var nproc = dag.nProc(); - for (short i = 0; i < nproc; i++) { - for (short j = 0; j < nproc; j++) { - if (parents[j] == null) { - continue; - } - var u = parents[j].parents()[i]; - if (u != null && (parents[i] == null || parents[i].level() < u.level())) { - return Correctness.COMPLIANCE_ERROR; - } - } - } - return null; - }; - } -} diff --git a/ethereal/src/test/java/com/salesforce/apollo/ethereal/DagFactory.java b/ethereal/src/test/java/com/salesforce/apollo/ethereal/DagFactory.java index 5e2d7e543..da5e2ff6b 100644 --- a/ethereal/src/test/java/com/salesforce/apollo/ethereal/DagFactory.java +++ b/ethereal/src/test/java/com/salesforce/apollo/ethereal/DagFactory.java @@ -8,27 +8,73 @@ import com.salesforce.apollo.ethereal.Dag.DagImpl; +import java.util.function.BiFunction; + /** * @author hal.hildebrand - * */ public interface DagFactory { - public class DefaultChecksFactory implements DagFactory { + static BiFunction parentConsistency() { + return (unit, dag) -> { + var parents = unit.parents(); + var nproc = dag.nProc(); + for (short i = 0; i < nproc; i++) { + for (short j = 0; j < nproc; j++) { + if (parents[j] == null) { + continue; + } + var u = parents[j].parents()[i]; + if (u != null && (parents[i] == null || parents[i].level() < u.level())) { + return Correctness.COMPLIANCE_ERROR; + } + } + } + return null; + }; + } + + static BiFunction basicCorrectness() { + return (u, dag) -> { + var parents = u.parents(); + var nproc = dag.nProc(); + if (parents.length != nproc) { + return Correctness.COMPLIANCE_ERROR; + } + short nonNillParents = 0; + for (short i = 0; i < nproc; i++) { + if (parents[i] == null) { + continue; + } + nonNillParents++; + if (parents[i].creator() != i) { + return Correctness.COMPLIANCE_ERROR; + } + } + if (u.predecessor() == null && nonNillParents > 0) { + return Correctness.COMPLIANCE_ERROR; + } + if (u.predecessor() != null && u.predecessor().level() >= u.level()) { + return Correctness.COMPLIANCE_ERROR; + } + return null; + }; + } + + Dag createDag(short nProc); + + class DefaultChecksFactory implements DagFactory { @Override public Dag createDag(short nProc) { var cnf = Config.newBuilder().setnProc(nProc).build(); var dag = new DagImpl(cnf, 0); - dag.addCheck(Checks.basicCorrectness()); - dag.addCheck(Checks.parentConsistency()); - dag.addCheck(Checks.noSelfForkingEvidence()); - dag.addCheck(Checks.forkerMuting()); - + dag.addCheck(basicCorrectness()); + dag.addCheck(parentConsistency()); return dag; } } - public class TestDagFactory implements DagFactory { + class TestDagFactory implements DagFactory { private final int initialEpoch; @@ -46,6 +92,4 @@ public Dag createDag(short nProc) { return new DagImpl(cnf, initialEpoch); } } - - Dag createDag(short nProc); }