This is an automated email from the ASF dual-hosted git repository. mmiller pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/accumulo.git
The following commit(s) were added to refs/heads/main by this push: new 6094a53 Fix for Constraint API (#2074) 6094a53 is described below commit 6094a537421f7b2d328c8d1d016a2bf830743d4c Author: Mike Miller <mmil...@apache.org> AuthorDate: Mon May 3 17:13:04 2021 -0400 Fix for Constraint API (#2074) * Add method to deprecated API to prevent errors * Add test to DeprecatedConstraintExtendTest --- .../accumulo/core/constraints/Constraint.java | 11 +++++++ .../DeprecatedConstraintExtendTest.java | 38 ++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java b/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java index 3414970..b24d613 100644 --- a/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java +++ b/core/src/main/java/org/apache/accumulo/core/constraints/Constraint.java @@ -84,4 +84,15 @@ public interface Constraint extends org.apache.accumulo.core.data.constraints.Co * @return list of violation codes, or null if none */ List<Short> check(Environment env, Mutation mutation); + + /** + * Implemented for backwards compatibility. + * + * @since 2.1.0 + */ + @Override + default List<Short> check(org.apache.accumulo.core.data.constraints.Constraint.Environment env, + Mutation mutation) { + return check((Environment) env, mutation); + } } diff --git a/core/src/test/java/org/apache/accumulo/core/constraints/DeprecatedConstraintExtendTest.java b/core/src/test/java/org/apache/accumulo/core/constraints/DeprecatedConstraintExtendTest.java index aa7ef99..dac943d 100644 --- a/core/src/test/java/org/apache/accumulo/core/constraints/DeprecatedConstraintExtendTest.java +++ b/core/src/test/java/org/apache/accumulo/core/constraints/DeprecatedConstraintExtendTest.java @@ -40,13 +40,12 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; @SuppressWarnings("deprecation") public class DeprecatedConstraintExtendTest { - Constraint constraint = new MinKeySizeConstraint(); - byte[] min = new byte[1024]; byte[] oversized = new byte[1048577]; @Test public void testMinKeySizeConstraint() { + Constraint constraint = new MinKeySizeConstraint(); // pass constraints Mutation m = new Mutation(min); @@ -67,6 +66,20 @@ public class DeprecatedConstraintExtendTest { constraint.check(null, m)); } + @Test + public void testFoo() { + FooConstraint fc = new FooConstraint(); + // pass constraints + Mutation m = new Mutation("blah"); + m.put("colf", "colq", new Value(new byte[] {})); + assertEquals(null, fc.check(null, m)); + + // test fail constraint + m = new Mutation("foo"); + m.put("colf", "colq", new Value(new byte[] {})); + assertEquals(Collections.singletonList(Short.valueOf("1")), fc.check(null, m)); + } + /** * Limit the size of 1mb but also a minimum of 1KB */ @@ -94,4 +107,25 @@ public class DeprecatedConstraintExtendTest { return violations; } } + + /** + * Test previously defined constraint. + */ + public class FooConstraint implements Constraint { + public String getViolationDescription(short violationCode) { + switch (violationCode) { + case 1: + return "Contains foo"; + } + throw new IllegalArgumentException(); + } + + public List<Short> check(Constraint.Environment env, Mutation mutation) { + if (new String(mutation.getRow()).contains("foo")) { + return Collections.singletonList(Short.valueOf("1")); + } + return null; + } + } + }