/** * Test cps in the table description * @throws Exception */ @Test public void testGetSetRemoveCP() throws Exception { HTableDescriptor desc = new HTableDescriptor("table"); // simple CP String className = BaseRegionObserver.class.getName(); // add and check that it is present desc.addCoprocessor(className); assertTrue(desc.hasCoprocessor(className)); // remove it and check that it is gone desc.removeCoprocessor(className); assertFalse(desc.hasCoprocessor(className)); }
/** * Test cps in the table description * @throws Exception */ @Test public void testSetListRemoveCP() throws Exception { HTableDescriptor desc = new HTableDescriptor("testGetSetRemoveCP"); // simple CP String className1 = BaseRegionObserver.class.getName(); String className2 = SampleRegionWALObserver.class.getName(); // Check that any coprocessor is present. assertTrue(desc.getCoprocessors().size() == 0); // Add the 1 coprocessor and check if present. desc.addCoprocessor(className1); assertTrue(desc.getCoprocessors().size() == 1); assertTrue(desc.getCoprocessors().contains(className1)); // Add the 2nd coprocessor and check if present. // remove it and check that it is gone desc.addCoprocessor(className2); assertTrue(desc.getCoprocessors().size() == 2); assertTrue(desc.getCoprocessors().contains(className2)); // Remove one and check desc.removeCoprocessor(className1); assertTrue(desc.getCoprocessors().size() == 1); assertFalse(desc.getCoprocessors().contains(className1)); assertTrue(desc.getCoprocessors().contains(className2)); // Remove the last and check desc.removeCoprocessor(className2); assertTrue(desc.getCoprocessors().size() == 0); assertFalse(desc.getCoprocessors().contains(className1)); assertFalse(desc.getCoprocessors().contains(className2)); }
/** * Test cps in the table description * @throws Exception */ @Test public void testGetSetRemoveCP() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("table")); // simple CP String className = BaseRegionObserver.class.getName(); // add and check that it is present desc.addCoprocessor(className); assertTrue(desc.hasCoprocessor(className)); // remove it and check that it is gone desc.removeCoprocessor(className); assertFalse(desc.hasCoprocessor(className)); }
/** * Test cps in the table description * @throws Exception */ @Test public void testSetListRemoveCP() throws Exception { HTableDescriptor desc = new HTableDescriptor(TableName.valueOf("testGetSetRemoveCP")); // simple CP String className1 = BaseRegionObserver.class.getName(); String className2 = SampleRegionWALObserver.class.getName(); // Check that any coprocessor is present. assertTrue(desc.getCoprocessors().size() == 0); // Add the 1 coprocessor and check if present. desc.addCoprocessor(className1); assertTrue(desc.getCoprocessors().size() == 1); assertTrue(desc.getCoprocessors().contains(className1)); // Add the 2nd coprocessor and check if present. // remove it and check that it is gone desc.addCoprocessor(className2); assertTrue(desc.getCoprocessors().size() == 2); assertTrue(desc.getCoprocessors().contains(className2)); // Remove one and check desc.removeCoprocessor(className1); assertTrue(desc.getCoprocessors().size() == 1); assertFalse(desc.getCoprocessors().contains(className1)); assertTrue(desc.getCoprocessors().contains(className2)); // Remove the last and check desc.removeCoprocessor(className2); assertTrue(desc.getCoprocessors().size() == 0); assertFalse(desc.getCoprocessors().contains(className1)); assertFalse(desc.getCoprocessors().contains(className2)); }
/** * Constructor * @param region the region * @param rsServices interface to available region server functionality * @param conf the configuration */ public RegionCoprocessorHost(final Region region, final RegionServerServices rsServices, final Configuration conf) { super(rsServices); this.conf = conf; this.rsServices = rsServices; this.region = region; this.pathPrefix = Integer.toString(this.region.getRegionInfo().hashCode()); // load system default cp's from configuration. loadSystemCoprocessors(conf, REGION_COPROCESSOR_CONF_KEY); // load system default cp's for user tables from configuration. if (!region.getRegionInfo().getTable().isSystemTable()) { loadSystemCoprocessors(conf, USER_REGION_COPROCESSOR_CONF_KEY); } // load Coprocessor From HDFS loadTableCoprocessors(conf); // now check whether any coprocessor implements postScannerFilterRow boolean hasCustomPostScannerFilterRow = false; out: for (RegionEnvironment env: coprocessors) { if (env.getInstance() instanceof RegionObserver) { Class<?> clazz = env.getInstance().getClass(); for(;;) { if (clazz == null) { // we must have directly implemented RegionObserver hasCustomPostScannerFilterRow = true; break out; } if (clazz == BaseRegionObserver.class) { // we reached BaseRegionObserver, try next coprocessor break; } try { clazz.getDeclaredMethod("postScannerFilterRow", ObserverContext.class, InternalScanner.class, byte[].class, int.class, short.class, boolean.class); // this coprocessor has a custom version of postScannerFilterRow hasCustomPostScannerFilterRow = true; break out; } catch (NoSuchMethodException ignore) { } clazz = clazz.getSuperclass(); } } } this.hasCustomPostScannerFilterRow = hasCustomPostScannerFilterRow; }