@Override public void start(CoprocessorEnvironment environment) { // make sure we are on a region server if (!(environment instanceof RegionCoprocessorEnvironment)) { throw new IllegalArgumentException( "Constraints only act on regions - started in an environment that was not a region"); } RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) environment; TableDescriptor desc = env.getRegion().getTableDescriptor(); // load all the constraints from the HTD try { this.constraints = Constraints.getConstraints(desc, classloader); } catch (IOException e) { throw new IllegalArgumentException(e); } if (LOG.isInfoEnabled()) { LOG.info("Finished loading " + constraints.size() + " user Constraints on table: " + desc.getTableName()); } }
@SuppressWarnings("unchecked") @Test public void testSimpleReadWrite() throws Throwable { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, WorksConstraint.class); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); assertEquals(1, constraints.size()); assertEquals(WorksConstraint.class, constraints.get(0).getClass()); // Check that we can add more than 1 constraint and that ordering is // preserved Constraints.add(desc, AlsoWorks.class, NameConstraint.class); constraints = Constraints.getConstraints(desc, this.getClass() .getClassLoader()); assertEquals(3, constraints.size()); assertEquals(WorksConstraint.class, constraints.get(0).getClass()); assertEquals(AlsoWorks.class, constraints.get(1).getClass()); assertEquals(NameConstraint.class, constraints.get(2).getClass()); }
@SuppressWarnings("unchecked") @Test public void testReadWriteWithConf() throws Throwable { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, new Pair<>(CheckConfigurationConstraint.class, CheckConfigurationConstraint.getConfiguration())); List<? extends Constraint> c = Constraints.getConstraints(desc, this .getClass().getClassLoader()); assertEquals(1, c.size()); assertEquals(CheckConfigurationConstraint.class, c.get(0).getClass()); // check to make sure that we overwrite configurations Constraints.add(desc, new Pair<>( CheckConfigurationConstraint.class, new Configuration(false))); try { Constraints.getConstraints(desc, this.getClass().getClassLoader()); fail("No exception thrown - configuration not overwritten"); } catch (IllegalArgumentException e) { // expect to have the exception, so don't do anything } }
/** * Test that when we update a constraint the ordering is not modified. * * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testUpdateConstraint() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, CheckConfigurationConstraint.class, CheckWasRunConstraint.class); Constraints.setConfiguration(desc, CheckConfigurationConstraint.class, CheckConfigurationConstraint.getConfiguration()); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); assertEquals(2, constraints.size()); // check to make sure the order didn't change assertEquals(CheckConfigurationConstraint.class, constraints.get(0) .getClass()); assertEquals(CheckWasRunConstraint.class, constraints.get(1).getClass()); }
@Test public void testConfigurationPreserved() throws Throwable { Configuration conf = new Configuration(); conf.setBoolean("_ENABLED", false); conf.setLong("_PRIORITY", 10); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, AlsoWorks.class, conf); Constraints.add(desc, WorksConstraint.class); assertFalse(Constraints.enabled(desc, AlsoWorks.class)); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); for (Constraint c : constraints) { Configuration storedConf = c.getConf(); if (c instanceof AlsoWorks) assertEquals(10, storedConf.getLong("_PRIORITY", -1)); // its just a worksconstraint else assertEquals(2, storedConf.getLong("_PRIORITY", -1)); } }
@Override public void start(CoprocessorEnvironment environment) { // make sure we are on a region server if (!(environment instanceof RegionCoprocessorEnvironment)) { throw new IllegalArgumentException( "Constraints only act on regions - started in an environment that was not a region"); } RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) environment; HTableDescriptor desc = env.getRegion().getTableDesc(); // load all the constraints from the HTD try { this.constraints = Constraints.getConstraints(desc, classloader); } catch (IOException e) { throw new IllegalArgumentException(e); } if (LOG.isInfoEnabled()) { LOG.info("Finished loading " + constraints.size() + " user Constraints on table: " + new String(desc.getName())); } }
@Override public void start(CoprocessorEnvironment environment) { // make sure we are on a region server if (!(environment instanceof RegionCoprocessorEnvironment)) { throw new IllegalArgumentException( "Constraints only act on regions - started in an environment that was not a region"); } RegionCoprocessorEnvironment env = (RegionCoprocessorEnvironment) environment; HTableDescriptor desc = env.getRegion().getTableDesc(); // load all the constraints from the HTD try { this.constraints = Constraints.getConstraints(desc, classloader); } catch (IOException e) { throw new IllegalArgumentException(e); } if (LOG.isInfoEnabled()) { LOG.info("Finished loading " + constraints.size() + " user Constraints on table: " + desc.getTableName()); } }
@SuppressWarnings("unchecked") @Test public void testSimpleReadWrite() throws Throwable { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, WorksConstraint.class); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); assertEquals(1, constraints.size()); assertEquals(WorksConstraint.class, constraints.get(0).getClass()); // Check that we can add more than 1 constraint and that ordering is // preserved Constraints.add(desc, AlsoWorks.class, NameConstraint.class); constraints = Constraints.getConstraints(desc, this.getClass() .getClassLoader()); assertEquals(3, constraints.size()); assertEquals(WorksConstraint.class, constraints.get(0).getClass()); assertEquals(AlsoWorks.class, constraints.get(1).getClass()); assertEquals(NameConstraint.class, constraints.get(2).getClass()); }
@SuppressWarnings("unchecked") @Test public void testReadWriteWithConf() throws Throwable { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, new Pair<>(CheckConfigurationConstraint.class, CheckConfigurationConstraint.getConfiguration())); List<? extends Constraint> c = Constraints.getConstraints(desc, this .getClass().getClassLoader()); assertEquals(1, c.size()); assertEquals(CheckConfigurationConstraint.class, c.get(0).getClass()); // check to make sure that we overwrite configurations Constraints.add(desc, new Pair<>( CheckConfigurationConstraint.class, new Configuration(false))); try { Constraints.getConstraints(desc, this.getClass().getClassLoader()); fail("No exception thrown - configuration not overwritten"); } catch (IllegalArgumentException e) { // expect to have the exception, so don't do anything } }
/** * Test that when we update a constraint the ordering is not modified. * * @throws Exception */ @SuppressWarnings("unchecked") @Test public void testUpdateConstraint() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, CheckConfigurationConstraint.class, CheckWasRunConstraint.class); Constraints.setConfiguration(desc, CheckConfigurationConstraint.class, CheckConfigurationConstraint.getConfiguration()); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); assertEquals(2, constraints.size()); // check to make sure the order didn't change assertEquals(CheckConfigurationConstraint.class, constraints.get(0) .getClass()); assertEquals(CheckWasRunConstraint.class, constraints.get(1).getClass()); }
@Test public void testConfigurationPreserved() throws Throwable { Configuration conf = new Configuration(); conf.setBoolean("_ENABLED", false); conf.setLong("_PRIORITY", 10); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(name.getMethodName())); Constraints.add(desc, AlsoWorks.class, conf); Constraints.add(desc, WorksConstraint.class); assertFalse(Constraints.enabled(desc, AlsoWorks.class)); List<? extends Constraint> constraints = Constraints.getConstraints(desc, this.getClass().getClassLoader()); for (Constraint c : constraints) { Configuration storedConf = c.getConf(); if (c instanceof AlsoWorks) assertEquals(10, storedConf.getLong("_PRIORITY", -1)); // its just a worksconstraint else assertEquals(2, storedConf.getLong("_PRIORITY", -1)); } }