Java 类org.apache.hadoop.hbase.util.CoprocessorClassLoader 实例源码

项目:ditb    文件:RegionCoprocessorHost.java   
/**
 * Sanity check the table coprocessor attributes of the supplied schema. Will
 * throw an exception if there is a problem.
 * @param conf
 * @param htd
 * @throws IOException
 */
public static void testTableCoprocessorAttrs(final Configuration conf,
    final HTableDescriptor htd) throws IOException {
  String pathPrefix = UUID.randomUUID().toString();
  for (TableCoprocessorAttribute attr: getTableCoprocessorAttrsFromSchema(conf, htd)) {
    if (attr.getPriority() < 0) {
      throw new IOException("Priority for coprocessor " + attr.getClassName() +
        " cannot be less than 0");
    }
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
      ClassLoader cl;
      if (attr.getPath() != null) {
        cl = CoprocessorClassLoader.getClassLoader(attr.getPath(),
          CoprocessorHost.class.getClassLoader(), pathPrefix, conf);
      } else {
        cl = CoprocessorHost.class.getClassLoader();
      }
      Thread.currentThread().setContextClassLoader(cl);
      cl.loadClass(attr.getClassName());
    } catch (ClassNotFoundException e) {
      throw new IOException("Class " + attr.getClassName() + " cannot be loaded", e);
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
}
项目:ditb    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  Admin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (Region region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:LCIndex-HBase-0.94.16    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:pbase    文件:RegionCoprocessorHost.java   
/**
 * Sanity check the table coprocessor attributes of the supplied schema. Will
 * throw an exception if there is a problem.
 * @param conf
 * @param htd
 * @throws IOException
 */
public static void testTableCoprocessorAttrs(final Configuration conf,
    final HTableDescriptor htd) throws IOException {
  String pathPrefix = UUID.randomUUID().toString();
  for (TableCoprocessorAttribute attr: getTableCoprocessorAttrsFromSchema(conf, htd)) {
    if (attr.getPriority() < 0) {
      throw new IOException("Priority for coprocessor " + attr.getClassName() +
        " cannot be less than 0");
    }
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
      ClassLoader cl;
      if (attr.getPath() != null) {
        cl = CoprocessorClassLoader.getClassLoader(attr.getPath(),
          CoprocessorHost.class.getClassLoader(), pathPrefix, conf);
      } else {
        cl = CoprocessorHost.class.getClassLoader();
      }
      Thread.currentThread().setContextClassLoader(cl);
      cl.loadClass(attr.getClassName());
    } catch (ClassNotFoundException e) {
      throw new IOException("Class " + attr.getClassName() + " cannot be loaded", e);
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
}
项目:pbase    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  Admin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:HIndex    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:IRIndex    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:hbase    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  Admin admin = TEST_UTIL.getAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region: hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionInfo().getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:hbase    文件:RegionCoprocessorHost.java   
/**
 * Sanity check the table coprocessor attributes of the supplied schema. Will
 * throw an exception if there is a problem.
 * @param conf
 * @param htd
 * @throws IOException
 */
public static void testTableCoprocessorAttrs(final Configuration conf,
    final TableDescriptor htd) throws IOException {
  String pathPrefix = UUID.randomUUID().toString();
  for (TableCoprocessorAttribute attr: getTableCoprocessorAttrsFromSchema(conf, htd)) {
    if (attr.getPriority() < 0) {
      throw new IOException("Priority for coprocessor " + attr.getClassName() +
        " cannot be less than 0");
    }
    ClassLoader old = Thread.currentThread().getContextClassLoader();
    try {
      ClassLoader cl;
      if (attr.getPath() != null) {
        cl = CoprocessorClassLoader.getClassLoader(attr.getPath(),
          CoprocessorHost.class.getClassLoader(), pathPrefix, conf);
      } else {
        cl = CoprocessorHost.class.getClassLoader();
      }
      Thread.currentThread().setContextClassLoader(cl);
      cl.loadClass(attr.getClassName());
    } catch (ClassNotFoundException e) {
      throw new IOException("Class " + attr.getClassName() + " cannot be loaded", e);
    } finally {
      Thread.currentThread().setContextClassLoader(old);
    }
  }
}
项目:PyroDB    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:c5    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(TableName.valueOf(cpName4));
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getTableName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:HBase-Research    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:hbase-0.94.8-qod    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:hbase-0.94.8-qod    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}
项目:hindex    文件:TestClassLoading.java   
@Test
// HBASE-6308: Test CP classloader is the CoprocessorClassLoader
public void testPrivateClassLoader() throws Exception {
  File jarFile = buildCoprocessorJar(cpName4);

  // create a table that references the jar
  HTableDescriptor htd = new HTableDescriptor(cpName4);
  htd.addFamily(new HColumnDescriptor("test"));
  htd.setValue("COPROCESSOR$1", getLocalPath(jarFile) + "|" + cpName4 + "|" +
    Coprocessor.PRIORITY_USER);
  HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
  admin.createTable(htd);
  waitForTable(htd.getName());

  // verify that the coprocessor was loaded correctly
  boolean found = false;
  MiniHBaseCluster hbase = TEST_UTIL.getHBaseCluster();
  for (HRegion region:
      hbase.getRegionServer(0).getOnlineRegionsLocalContext()) {
    if (region.getRegionNameAsString().startsWith(cpName4)) {
      Coprocessor cp = region.getCoprocessorHost().findCoprocessor(cpName4);
      if (cp != null) {
        found = true;
        assertEquals("Class " + cpName4 + " was not loaded by CoprocessorClassLoader",
          cp.getClass().getClassLoader().getClass(), CoprocessorClassLoader.class);
      }
    }
  }
  assertTrue("Class " + cpName4 + " was missing on a region", found);
}