Created
April 12, 2012 10:57
-
-
Save zygm0nt/2366503 to your computer and use it in GitHub Desktop.
Illustrate github question
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.apache.hadoop.conf.Configuration; | |
import org.apache.hadoop.fs.Path; | |
import org.apache.hadoop.hbase.*; | |
import org.apache.hadoop.hbase.client.Get; | |
import org.apache.hadoop.hbase.client.Put; | |
import org.apache.hadoop.hbase.client.Result; | |
import org.apache.hadoop.hbase.coprocessor.BaseRegionObserver; | |
import org.apache.hadoop.hbase.coprocessor.ObserverContext; | |
import org.apache.hadoop.hbase.coprocessor.RegionCoprocessorEnvironment; | |
import org.apache.hadoop.hbase.regionserver.HRegion; | |
import org.apache.hadoop.hbase.regionserver.RegionCoprocessorHost; | |
import org.apache.hadoop.hbase.regionserver.wal.WALEdit; | |
import org.apache.hadoop.hbase.util.Bytes; | |
public class CoprocessorTest { | |
HRegion initHRegion (byte [] tableName, String callingMethod, Configuration conf, byte [] ... families) throws IOException { | |
HTableDescriptor htd = new HTableDescriptor(tableName); | |
for(byte [] family : families) { | |
htd.addFamily(new HColumnDescriptor(family)); | |
} | |
HRegionInfo info = new HRegionInfo(htd.getName(), null, null, false); | |
Path path = new Path(DIR + callingMethod); | |
HRegion r = HRegion.createHRegion(info, path, conf, htd); | |
RegionCoprocessorHost host = new RegionCoprocessorHost(r, null, conf); | |
r.setCoprocessorHost(host); | |
return r; | |
} | |
@Test | |
public void testDataModification() throws Exception { | |
HBaseTestingUtility cluster = new HBaseTestingUtility(); | |
cluster.startMiniCluster(); | |
byte[] ROW = Bytes.toBytes("testRow"); | |
byte[] TABLE = Bytes.toBytes(getClass().getName()); | |
byte[] A = Bytes.toBytes("A"); | |
byte[] STATS = Bytes.toBytes("stats"); | |
byte[] CONTENT = Bytes.toBytes("content"); | |
byte[][] FAMILIES = new byte[][] { A, STATS, CONTENT } ; | |
Configuration conf = HBaseConfiguration.create(); | |
HRegion region = initHRegion(TABLE, getClass().getName(), conf, FAMILIES); | |
RegionCoprocessorHost h = region.getCoprocessorHost(); | |
h.load(MyCoprocessor.class, Coprocessor.PRIORITY_HIGHEST, conf); | |
Put put = new Put(ROW); | |
put.add(A, A, A); | |
put.add(CONTENT, Bytes.toBytes("raw"), Bytes.toBytes("ABC"); | |
int lockid = region.obtainRowLock(ROW); | |
region.put(put, lockid); | |
region.releaseRowLock(lockid); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment