本文整理汇总了Java中org.apache.hadoop.hbase.util.ManualEnvironmentEdge.incValue方法的典型用法代码示例。如果您正苦于以下问题:Java ManualEnvironmentEdge.incValue方法的具体用法?Java ManualEnvironmentEdge.incValue怎么用?Java ManualEnvironmentEdge.incValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.hadoop.hbase.util.ManualEnvironmentEdge
的用法示例。
在下文中一共展示了ManualEnvironmentEdge.incValue方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testSortExtract
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testSortExtract(){
ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(mee);
mee.setValue(1);
DeadServer d = new DeadServer();
d.add(hostname123);
mee.incValue(1);
d.add(hostname1234);
mee.incValue(1);
d.add(hostname12345);
List<Pair<ServerName, Long>> copy = d.copyDeadServersSince(2L);
Assert.assertEquals(2, copy.size());
Assert.assertEquals(hostname1234, copy.get(0).getFirst());
Assert.assertEquals(new Long(2L), copy.get(0).getSecond());
Assert.assertEquals(hostname12345, copy.get(1).getFirst());
Assert.assertEquals(new Long(3L), copy.get(1).getSecond());
EnvironmentEdgeManager.reset();
}
示例2: testUnconfiguredLimiters
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testUnconfiguredLimiters() throws InterruptedException {
ManualEnvironmentEdge testEdge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(testEdge);
long limit = Long.MAX_VALUE;
// For unconfigured limiters, it is supposed to use as much as possible
RateLimiter avgLimiter = new AverageIntervalRateLimiter();
RateLimiter fixLimiter = new FixedIntervalRateLimiter();
assertEquals(limit, avgLimiter.getAvailable());
assertEquals(limit, fixLimiter.getAvailable());
assertTrue(avgLimiter.canExecute(limit));
avgLimiter.consume(limit);
assertTrue(fixLimiter.canExecute(limit));
fixLimiter.consume(limit);
// Make sure that available is Long.MAX_VALUE
assertTrue(limit == avgLimiter.getAvailable());
assertTrue(limit == fixLimiter.getAvailable());
// after 100 millseconds, it should be able to execute limit as well
testEdge.incValue(100);
assertTrue(avgLimiter.canExecute(limit));
avgLimiter.consume(limit);
assertTrue(fixLimiter.canExecute(limit));
fixLimiter.consume(limit);
// Make sure that available is Long.MAX_VALUE
assertTrue(limit == avgLimiter.getAvailable());
assertTrue(limit == fixLimiter.getAvailable());
EnvironmentEdgeManager.reset();
}
示例3: testConnectionIdle
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
/**
* Test that connection can become idle without breaking everything.
*/
@Test
public void testConnectionIdle() throws Exception {
TableName tableName = TableName.valueOf("HCM-testConnectionIdle");
TEST_UTIL.createTable(tableName, FAM_NAM).close();
int idleTime = 20000;
boolean previousBalance = TEST_UTIL.getHBaseAdmin().setBalancerRunning(false, true);
Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
// We want to work on a separate connection.
c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); // Don't retry: retry = test failed
c2.setInt(RpcClient.IDLE_TIME, idleTime);
final Table table = new HTable(c2, tableName);
Put put = new Put(ROW);
put.add(FAM_NAM, ROW, ROW);
table.put(put);
ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
mee.setValue(System.currentTimeMillis());
EnvironmentEdgeManager.injectEdge(mee);
LOG.info("first get");
table.get(new Get(ROW));
LOG.info("first get - changing the time & sleeping");
mee.incValue(idleTime + 1000);
Thread.sleep(1500); // we need to wait a little for the connection to be seen as idle.
// 1500 = sleep time in RpcClient#waitForWork + a margin
LOG.info("second get - connection has been marked idle in the middle");
// To check that the connection actually became idle would need to read some private
// fields of RpcClient.
table.get(new Get(ROW));
mee.incValue(idleTime + 1000);
LOG.info("third get - connection is idle, but the reader doesn't know yet");
// We're testing here a special case:
// time limit reached BUT connection not yet reclaimed AND a new call.
// in this situation, we don't close the connection, instead we use it immediately.
// If we're very unlucky we can have a race condition in the test: the connection is already
// under closing when we do the get, so we have an exception, and we don't retry as the
// retry number is 1. The probability is very very low, and seems acceptable for now. It's
// a test issue only.
table.get(new Get(ROW));
LOG.info("we're done - time will change back");
table.close();
EnvironmentEdgeManager.reset();
TEST_UTIL.getHBaseAdmin().setBalancerRunning(previousBalance, true);
}
示例4: testFailedServer
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testFailedServer(){
ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge( ee );
FailedServers fs = new FailedServers(new Configuration());
InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12); // same server as ia
InetSocketAddress ia3 = InetSocketAddress.createUnresolved("badtoo", 12);
InetSocketAddress ia4 = InetSocketAddress.createUnresolved("badtoo", 13);
Assert.assertFalse( fs.isFailedServer(ia) );
fs.addToFailedServers(ia);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( 1 );
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
fs.addToFailedServers(ia);
fs.addToFailedServers(ia3);
fs.addToFailedServers(ia4);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
Assert.assertTrue( fs.isFailedServer(ia3) );
Assert.assertTrue( fs.isFailedServer(ia4) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
Assert.assertFalse( fs.isFailedServer(ia3) );
Assert.assertFalse( fs.isFailedServer(ia4) );
fs.addToFailedServers(ia3);
Assert.assertFalse( fs.isFailedServer(ia4) );
}
示例5: testDeleteExpiredStoreFiles
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
public void testDeleteExpiredStoreFiles() throws Exception {
ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
EnvironmentEdgeManagerTestHelper.injectEdge(mee);
int storeFileNum = 4;
int ttl = 4;
Configuration conf = HBaseConfiguration.create();
// Enable the expired store file deletion
conf.setBoolean("hbase.store.delete.expired.storefile", true);
HColumnDescriptor hcd = new HColumnDescriptor(family);
hcd.setTimeToLive(ttl);
init(getName(), conf, hcd);
long sleepTime = this.store.scanInfo.getTtl() / storeFileNum;
long timeStamp;
// There are 4 store files and the max time stamp difference among these
// store files will be (this.store.ttl / storeFileNum)
for (int i = 1; i <= storeFileNum; i++) {
LOG.info("Adding some data for the store file #" + i);
timeStamp = EnvironmentEdgeManager.currentTimeMillis();
this.store.add(new KeyValue(row, family, qf1, timeStamp, (byte[]) null));
this.store.add(new KeyValue(row, family, qf2, timeStamp, (byte[]) null));
this.store.add(new KeyValue(row, family, qf3, timeStamp, (byte[]) null));
flush(i);
mee.incValue(sleepTime);
}
// move time forward a bit more, so that the first file is expired
mee.incValue(1);
// Verify the total number of store files
assertEquals(storeFileNum, this.store.getStorefiles().size());
// Each compaction request will find one expired store file and delete it
// by the compaction.
for (int i = 1; i <= storeFileNum; i++) {
// verify the expired store file.
CompactionRequest cr = this.store.requestCompaction();
// the first is expired normally.
// If not the first compaction, there is another empty store file,
assertEquals(Math.min(i, 2), cr.getFiles().size());
for (int j = 0; i < cr.getFiles().size(); j++) {
assertTrue(cr.getFiles().get(j).getReader().getMaxTimestamp() < (EnvironmentEdgeManager
.currentTimeMillis() - this.store.scanInfo.getTtl()));
}
// Verify that the expired store file is compacted to an empty store file.
this.store.compact(cr);
// It is an empty store file.
assertEquals(0, this.store.getStorefiles().get(0).getReader()
.getEntries());
// Let the next store file expired.
mee.incValue(sleepTime);
}
}
示例6: testFailedServer
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testFailedServer(){
ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge( ee );
RpcClient.FailedServers fs = new RpcClient.FailedServers(new Configuration());
InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12); // same server as ia
InetSocketAddress ia3 = InetSocketAddress.createUnresolved("badtoo", 12);
InetSocketAddress ia4 = InetSocketAddress.createUnresolved("badtoo", 13);
Assert.assertFalse( fs.isFailedServer(ia) );
fs.addToFailedServers(ia);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( 1 );
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
fs.addToFailedServers(ia);
fs.addToFailedServers(ia3);
fs.addToFailedServers(ia4);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
Assert.assertTrue( fs.isFailedServer(ia3) );
Assert.assertTrue( fs.isFailedServer(ia4) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
Assert.assertFalse( fs.isFailedServer(ia3) );
Assert.assertFalse( fs.isFailedServer(ia4) );
fs.addToFailedServers(ia3);
Assert.assertFalse( fs.isFailedServer(ia4) );
}
示例7: testConnectionIdle
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
/**
* Test that connection can become idle without breaking everything.
*/
@Test
public void testConnectionIdle() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
TEST_UTIL.createTable(tableName, FAM_NAM).close();
int idleTime = 20000;
boolean previousBalance = TEST_UTIL.getAdmin().setBalancerRunning(false, true);
Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
// We want to work on a separate connection.
c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); // Don't retry: retry = test failed
c2.setInt(RpcClient.IDLE_TIME, idleTime);
Connection connection = ConnectionFactory.createConnection(c2);
final Table table = connection.getTable(tableName);
Put put = new Put(ROW);
put.addColumn(FAM_NAM, ROW, ROW);
table.put(put);
ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
mee.setValue(System.currentTimeMillis());
EnvironmentEdgeManager.injectEdge(mee);
LOG.info("first get");
table.get(new Get(ROW));
LOG.info("first get - changing the time & sleeping");
mee.incValue(idleTime + 1000);
Thread.sleep(1500); // we need to wait a little for the connection to be seen as idle.
// 1500 = sleep time in RpcClient#waitForWork + a margin
LOG.info("second get - connection has been marked idle in the middle");
// To check that the connection actually became idle would need to read some private
// fields of RpcClient.
table.get(new Get(ROW));
mee.incValue(idleTime + 1000);
LOG.info("third get - connection is idle, but the reader doesn't know yet");
// We're testing here a special case:
// time limit reached BUT connection not yet reclaimed AND a new call.
// in this situation, we don't close the connection, instead we use it immediately.
// If we're very unlucky we can have a race condition in the test: the connection is already
// under closing when we do the get, so we have an exception, and we don't retry as the
// retry number is 1. The probability is very very low, and seems acceptable for now. It's
// a test issue only.
table.get(new Get(ROW));
LOG.info("we're done - time will change back");
table.close();
connection.close();
EnvironmentEdgeManager.reset();
TEST_UTIL.getAdmin().setBalancerRunning(previousBalance, true);
}
示例8: testExtremeLimiters
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testExtremeLimiters() throws InterruptedException {
ManualEnvironmentEdge testEdge = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge(testEdge);
long limit = Long.MAX_VALUE - 1;
RateLimiter avgLimiter = new AverageIntervalRateLimiter();
avgLimiter.set(limit, TimeUnit.SECONDS);
RateLimiter fixLimiter = new FixedIntervalRateLimiter();
fixLimiter.set(limit, TimeUnit.SECONDS);
assertEquals(limit, avgLimiter.getAvailable());
assertEquals(limit, fixLimiter.getAvailable());
assertTrue(avgLimiter.canExecute(limit / 2));
avgLimiter.consume(limit / 2);
assertTrue(fixLimiter.canExecute(limit / 2));
fixLimiter.consume(limit / 2);
// Make sure that available is whatever left
assertTrue((limit - (limit / 2)) == avgLimiter.getAvailable());
assertTrue((limit - (limit / 2)) == fixLimiter.getAvailable());
// after 100 millseconds, both should not be able to execute the limit
testEdge.incValue(100);
assertFalse(avgLimiter.canExecute(limit));
assertFalse(fixLimiter.canExecute(limit));
// after 500 millseconds, average interval limiter should be able to execute the limit
testEdge.incValue(500);
assertTrue(avgLimiter.canExecute(limit));
assertFalse(fixLimiter.canExecute(limit));
// Make sure that available is correct
assertTrue(limit == avgLimiter.getAvailable());
assertTrue((limit - (limit / 2)) == fixLimiter.getAvailable());
// after 500 millseconds, both should be able to execute
testEdge.incValue(500);
assertTrue(avgLimiter.canExecute(limit));
assertTrue(fixLimiter.canExecute(limit));
// Make sure that available is Long.MAX_VALUE
assertTrue(limit == avgLimiter.getAvailable());
assertTrue(limit == fixLimiter.getAvailable());
EnvironmentEdgeManager.reset();
}
示例9: testFailedServer
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testFailedServer(){
ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge( ee );
FailedServers fs = new FailedServers(new Configuration());
Throwable testThrowable = new Throwable();//throwable already tested in TestFailedServers.java
InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12); // same server as ia
InetSocketAddress ia3 = InetSocketAddress.createUnresolved("badtoo", 12);
InetSocketAddress ia4 = InetSocketAddress.createUnresolved("badtoo", 13);
Assert.assertFalse( fs.isFailedServer(ia) );
fs.addToFailedServers(ia,testThrowable);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( 1 );
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
fs.addToFailedServers(ia,testThrowable);
fs.addToFailedServers(ia3,testThrowable);
fs.addToFailedServers(ia4,testThrowable);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
Assert.assertTrue( fs.isFailedServer(ia3) );
Assert.assertTrue( fs.isFailedServer(ia4) );
ee.incValue( RpcClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
Assert.assertFalse( fs.isFailedServer(ia3) );
Assert.assertFalse( fs.isFailedServer(ia4) );
fs.addToFailedServers(ia3,testThrowable);
Assert.assertFalse( fs.isFailedServer(ia4) );
}
示例10: testConnectionIdle
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
/**
* Test that connection can become idle without breaking everything.
*/
@Test
public void testConnectionIdle() throws Exception {
String tableName = "HCM-testConnectionIdle";
TEST_UTIL.createTable(tableName.getBytes(), FAM_NAM).close();
int idleTime = 20000;
boolean previousBalance = TEST_UTIL.getHBaseAdmin().setBalancerRunning(false, true);
Configuration c2 = new Configuration(TEST_UTIL.getConfiguration());
// We want to work on a separate connection.
c2.set(HConstants.HBASE_CLIENT_INSTANCE_ID, String.valueOf(-1));
c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); // Don't retry: retry = test failed
c2.setInt(RpcClient.IDLE_TIME, idleTime);
final HTable table = new HTable(c2, tableName.getBytes());
Put put = new Put(ROW);
put.add(FAM_NAM, ROW, ROW);
table.put(put);
ManualEnvironmentEdge mee = new ManualEnvironmentEdge();
mee.setValue(System.currentTimeMillis());
EnvironmentEdgeManager.injectEdge(mee);
LOG.info("first get");
table.get(new Get(ROW));
LOG.info("first get - changing the time & sleeping");
mee.incValue(idleTime + 1000);
Thread.sleep(1500); // we need to wait a little for the connection to be seen as idle.
// 1500 = sleep time in RpcClient#waitForWork + a margin
LOG.info("second get - connection has been marked idle in the middle");
// To check that the connection actually became idle would need to read some private
// fields of RpcClient.
table.get(new Get(ROW));
mee.incValue(idleTime + 1000);
LOG.info("third get - connection is idle, but the reader doesn't know yet");
// We're testing here a special case:
// time limit reached BUT connection not yet reclaimed AND a new call.
// in this situation, we don't close the connection, instead we use it immediately.
// If we're very unlucky we can have a race condition in the test: the connection is already
// under closing when we do the get, so we have an exception, and we don't retry as the
// retry number is 1. The probability is very very low, and seems acceptable for now. It's
// a test issue only.
table.get(new Get(ROW));
LOG.info("we're done - time will change back");
table.close();
EnvironmentEdgeManager.reset();
TEST_UTIL.getHBaseAdmin().setBalancerRunning(previousBalance, true);
}
示例11: testFailedServer
import org.apache.hadoop.hbase.util.ManualEnvironmentEdge; //导入方法依赖的package包/类
@Test
public void testFailedServer(){
ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
EnvironmentEdgeManager.injectEdge( ee );
HBaseClient.FailedServers fs = new HBaseClient.FailedServers(new Configuration());
InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12); // same server as ia
InetSocketAddress ia3 = InetSocketAddress.createUnresolved("badtoo", 12);
InetSocketAddress ia4 = InetSocketAddress.createUnresolved("badtoo", 13);
Assert.assertFalse( fs.isFailedServer(ia) );
fs.addToFailedServers(ia);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( 1 );
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
ee.incValue( HBaseClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
fs.addToFailedServers(ia);
fs.addToFailedServers(ia3);
fs.addToFailedServers(ia4);
Assert.assertTrue( fs.isFailedServer(ia) );
Assert.assertTrue( fs.isFailedServer(ia2) );
Assert.assertTrue( fs.isFailedServer(ia3) );
Assert.assertTrue( fs.isFailedServer(ia4) );
ee.incValue( HBaseClient.FAILED_SERVER_EXPIRY_DEFAULT + 1 );
Assert.assertFalse( fs.isFailedServer(ia) );
Assert.assertFalse( fs.isFailedServer(ia2) );
Assert.assertFalse( fs.isFailedServer(ia3) );
Assert.assertFalse( fs.isFailedServer(ia4) );
fs.addToFailedServers(ia3);
Assert.assertFalse( fs.isFailedServer(ia4) );
}