Search in sources :

Example 1 with HBaseThriftTestingUtility

use of org.apache.hadoop.hbase.thrift.HBaseThriftTestingUtility in project hbase by apache.

the class TestThriftHBaseServiceHandler method testSlowLogResponses.

@Test
public void testSlowLogResponses() throws Exception {
    // start a thrift server
    HBaseThriftTestingUtility THRIFT_TEST_UTIL = new HBaseThriftTestingUtility();
    Configuration configuration = UTIL.getConfiguration();
    configuration.setBoolean("hbase.regionserver.slowlog.buffer.enabled", true);
    THRIFT_TEST_UTIL.startThriftServer(configuration, ThriftServerType.ONE);
    ThriftHBaseServiceHandler thriftHBaseServiceHandler = new ThriftHBaseServiceHandler(configuration, UserProvider.instantiate(configuration));
    Collection<ServerName> serverNames = UTIL.getAdmin().getRegionServers();
    Set<TServerName> tServerNames = ThriftUtilities.getServerNamesFromHBase(new HashSet<>(serverNames));
    List<Boolean> clearedResponses = thriftHBaseServiceHandler.clearSlowLogResponses(tServerNames);
    clearedResponses.forEach(Assert::assertTrue);
    TLogQueryFilter tLogQueryFilter = new TLogQueryFilter();
    tLogQueryFilter.setLimit(15);
    Assert.assertEquals(tLogQueryFilter.getFilterByOperator(), TFilterByOperator.OR);
    LogQueryFilter logQueryFilter = ThriftUtilities.getSlowLogQueryFromThrift(tLogQueryFilter);
    Assert.assertEquals(logQueryFilter.getFilterByOperator(), LogQueryFilter.FilterByOperator.OR);
    tLogQueryFilter.setFilterByOperator(TFilterByOperator.AND);
    logQueryFilter = ThriftUtilities.getSlowLogQueryFromThrift(tLogQueryFilter);
    Assert.assertEquals(logQueryFilter.getFilterByOperator(), LogQueryFilter.FilterByOperator.AND);
    List<TOnlineLogRecord> tLogRecords = thriftHBaseServiceHandler.getSlowLogResponses(tServerNames, tLogQueryFilter);
    assertEquals(tLogRecords.size(), 0);
}
Also used : TLogQueryFilter(org.apache.hadoop.hbase.thrift2.generated.TLogQueryFilter) Configuration(org.apache.hadoop.conf.Configuration) TServerName(org.apache.hadoop.hbase.thrift2.generated.TServerName) TLogQueryFilter(org.apache.hadoop.hbase.thrift2.generated.TLogQueryFilter) LogQueryFilter(org.apache.hadoop.hbase.client.LogQueryFilter) TOnlineLogRecord(org.apache.hadoop.hbase.thrift2.generated.TOnlineLogRecord) Assert(org.junit.Assert) ServerName(org.apache.hadoop.hbase.ServerName) TServerName(org.apache.hadoop.hbase.thrift2.generated.TServerName) HBaseThriftTestingUtility(org.apache.hadoop.hbase.thrift.HBaseThriftTestingUtility) Test(org.junit.Test)

Example 2 with HBaseThriftTestingUtility

use of org.apache.hadoop.hbase.thrift.HBaseThriftTestingUtility in project hbase by apache.

the class TestThriftHBaseServiceHandler method testGetThriftServerOneType.

/**
 * Verify that thrift2 client calling thrift server can get the thrift server type correctly.
 */
@Test
public void testGetThriftServerOneType() throws Exception {
    // start a thrift server
    HBaseThriftTestingUtility THRIFT_TEST_UTIL = new HBaseThriftTestingUtility();
    LOG.info("Starting HBase Thrift server One");
    THRIFT_TEST_UTIL.startThriftServer(UTIL.getConfiguration(), ThriftServerType.ONE);
    try (TTransport transport = new TSocket(InetAddress.getLocalHost().getHostName(), THRIFT_TEST_UTIL.getServerPort())) {
        TProtocol protocol = new TBinaryProtocol(transport);
        // This is our thrift2 client.
        THBaseService.Iface client = new THBaseService.Client(protocol);
        // open the transport
        transport.open();
        assertEquals(TThriftServerType.ONE.name(), client.getThriftServerType().name());
    } finally {
        THRIFT_TEST_UTIL.stopThriftServer();
    }
}
Also used : TBinaryProtocol(org.apache.thrift.protocol.TBinaryProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) HBaseThriftTestingUtility(org.apache.hadoop.hbase.thrift.HBaseThriftTestingUtility) TTransport(org.apache.thrift.transport.TTransport) AccessControlClient(org.apache.hadoop.hbase.security.access.AccessControlClient) TSocket(org.apache.thrift.transport.TSocket) THBaseService(org.apache.hadoop.hbase.thrift2.generated.THBaseService) Test(org.junit.Test)

Aggregations

HBaseThriftTestingUtility (org.apache.hadoop.hbase.thrift.HBaseThriftTestingUtility)2 Test (org.junit.Test)2 Configuration (org.apache.hadoop.conf.Configuration)1 ServerName (org.apache.hadoop.hbase.ServerName)1 LogQueryFilter (org.apache.hadoop.hbase.client.LogQueryFilter)1 AccessControlClient (org.apache.hadoop.hbase.security.access.AccessControlClient)1 THBaseService (org.apache.hadoop.hbase.thrift2.generated.THBaseService)1 TLogQueryFilter (org.apache.hadoop.hbase.thrift2.generated.TLogQueryFilter)1 TOnlineLogRecord (org.apache.hadoop.hbase.thrift2.generated.TOnlineLogRecord)1 TServerName (org.apache.hadoop.hbase.thrift2.generated.TServerName)1 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)1 TProtocol (org.apache.thrift.protocol.TProtocol)1 TSocket (org.apache.thrift.transport.TSocket)1 TTransport (org.apache.thrift.transport.TTransport)1 Assert (org.junit.Assert)1