@Test
  public void testConstraintFails() throws Exception {
    // create the table
    // it would be nice if this was also a method on the util
    TableDescriptorBuilder builder = TableDescriptorBuilder.newBuilder(tableName);
    for (byte[] family : new byte[][] { dummy, test }) {
      builder.setColumnFamily(ColumnFamilyDescriptorBuilder.of(family));
    }

    // add a constraint that is sure to fail
    Constraints.add(builder, AllFailConstraint.class);

    util.getAdmin().createTable(builder.build());
    Table table = util.getConnection().getTable(tableName);

    // test that we do fail on violation
    Put put = new Put(row1);
    byte[] qualifier = new byte[0];
    put.addColumn(dummy, qualifier, Bytes.toBytes("fail"));
    LOG.warn("Doing put in table");
    try {
      table.put(put);
      fail("This put should not have suceeded - AllFailConstraint was not run!");
    } catch (ConstraintException e) {
      // expected
    }
    table.close();
  }
Test that constraints will fail properly
hbase-server/src/test/java/org/apache/hadoop/hbase/constraint/TestConstraint.java