Search in sources :

Example 6 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestFlushRegionEntry method setUp.

@BeforeClass
public static void setUp() throws Exception {
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    edge.setValue(12345);
    EnvironmentEdgeManager.injectEdge(edge);
}
Also used : ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) BeforeClass(org.junit.BeforeClass)

Example 7 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestServerNonceManager method testCleanup.

@Test
public void testCleanup() throws Exception {
    ManualEnvironmentEdge edge = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(edge);
    try {
        ServerNonceManager nm = createManager(6);
        ScheduledChore cleanup = nm.createCleanupScheduledChore(Mockito.mock(Stoppable.class));
        edge.setValue(1);
        assertTrue(nm.startOperation(NO_NONCE, 1, createStoppable()));
        assertTrue(nm.startOperation(NO_NONCE, 2, createStoppable()));
        assertTrue(nm.startOperation(NO_NONCE, 3, createStoppable()));
        edge.setValue(2);
        nm.endOperation(NO_NONCE, 1, true);
        edge.setValue(4);
        nm.endOperation(NO_NONCE, 2, true);
        edge.setValue(9);
        cleanup.choreForTesting();
        // Nonce 1 has been cleaned up.
        assertTrue(nm.startOperation(NO_NONCE, 1, createStoppable()));
        // Nonce 2 has not been cleaned up.
        assertFalse(nm.startOperation(NO_NONCE, 2, createStoppable()));
        // Nonce 3 was active and active ops should never be cleaned up; try to end and start.
        nm.endOperation(NO_NONCE, 3, false);
        assertTrue(nm.startOperation(NO_NONCE, 3, createStoppable()));
        edge.setValue(11);
        cleanup.choreForTesting();
        // Now, nonce 2 has been cleaned up.
        assertTrue(nm.startOperation(NO_NONCE, 2, createStoppable()));
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : ScheduledChore(org.apache.hadoop.hbase.ScheduledChore) Stoppable(org.apache.hadoop.hbase.Stoppable) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Example 8 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestHCM method testErrorBackoffTimeCalculation.

@Test
public void testErrorBackoffTimeCalculation() throws Exception {
    // TODO: This test would seem to presume hardcoded RETRY_BACKOFF which it should not.
    final long ANY_PAUSE = 100;
    ServerName location = ServerName.valueOf("127.0.0.1", 1, 0);
    ServerName diffLocation = ServerName.valueOf("127.0.0.1", 2, 0);
    ManualEnvironmentEdge timeMachine = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(timeMachine);
    try {
        long largeAmountOfTime = ANY_PAUSE * 1000;
        ConnectionImplementation.ServerErrorTracker tracker = new ConnectionImplementation.ServerErrorTracker(largeAmountOfTime, 100);
        // The default backoff is 0.
        assertEquals(0, tracker.calculateBackoffTime(location, ANY_PAUSE));
        // Check some backoff values from HConstants sequence.
        tracker.reportServerError(location);
        assertEqualsWithJitter(ANY_PAUSE * HConstants.RETRY_BACKOFF[0], tracker.calculateBackoffTime(location, ANY_PAUSE));
        tracker.reportServerError(location);
        tracker.reportServerError(location);
        tracker.reportServerError(location);
        assertEqualsWithJitter(ANY_PAUSE * HConstants.RETRY_BACKOFF[3], tracker.calculateBackoffTime(location, ANY_PAUSE));
        // All of this shouldn't affect backoff for different location.
        assertEquals(0, tracker.calculateBackoffTime(diffLocation, ANY_PAUSE));
        tracker.reportServerError(diffLocation);
        assertEqualsWithJitter(ANY_PAUSE * HConstants.RETRY_BACKOFF[0], tracker.calculateBackoffTime(diffLocation, ANY_PAUSE));
        // Check with different base.
        assertEqualsWithJitter(ANY_PAUSE * 2 * HConstants.RETRY_BACKOFF[3], tracker.calculateBackoffTime(location, ANY_PAUSE * 2));
    } finally {
        EnvironmentEdgeManager.reset();
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Example 9 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestHBaseClient method testFailedServer.

@Test
public void testFailedServer() {
    ManualEnvironmentEdge ee = new ManualEnvironmentEdge();
    EnvironmentEdgeManager.injectEdge(ee);
    FailedServers fs = new FailedServers(new Configuration());
    InetSocketAddress ia = InetSocketAddress.createUnresolved("bad", 12);
    // same server as ia
    InetSocketAddress ia2 = InetSocketAddress.createUnresolved("bad", 12);
    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));
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) InetSocketAddress(java.net.InetSocketAddress) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Example 10 with ManualEnvironmentEdge

use of org.apache.hadoop.hbase.util.ManualEnvironmentEdge in project hbase by apache.

the class TestHCM method testConnectionIdle.

/**
   * 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));
    // Don't retry: retry = test failed
    c2.setInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1);
    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);
    // we need to wait a little for the connection to be seen as idle.
    Thread.sleep(1500);
    // 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);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Configuration(org.apache.hadoop.conf.Configuration) ManualEnvironmentEdge(org.apache.hadoop.hbase.util.ManualEnvironmentEdge) Test(org.junit.Test)

Aggregations

ManualEnvironmentEdge (org.apache.hadoop.hbase.util.ManualEnvironmentEdge)18 Test (org.junit.Test)14 Cell (org.apache.hadoop.hbase.Cell)4 Get (org.apache.hadoop.hbase.client.Get)4 Result (org.apache.hadoop.hbase.client.Result)4 Configuration (org.apache.hadoop.conf.Configuration)2 ScheduledChore (org.apache.hadoop.hbase.ScheduledChore)2 Stoppable (org.apache.hadoop.hbase.Stoppable)2 Put (org.apache.hadoop.hbase.client.Put)2 BinaryComparator (org.apache.hadoop.hbase.filter.BinaryComparator)2 StoreFile (org.apache.hadoop.hbase.regionserver.StoreFile)2 StripeInformationProvider (org.apache.hadoop.hbase.regionserver.compactions.StripeCompactionPolicy.StripeInformationProvider)2 BeforeClass (org.junit.BeforeClass)2 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 ServerName (org.apache.hadoop.hbase.ServerName)1 TableName (org.apache.hadoop.hbase.TableName)1 Append (org.apache.hadoop.hbase.client.Append)1 Increment (org.apache.hadoop.hbase.client.Increment)1 RowMutations (org.apache.hadoop.hbase.client.RowMutations)1