Example usage for java.util NavigableMap navigableKeySet

List of usage examples for java.util NavigableMap navigableKeySet

Introduction

In this page you can find the example usage for java.util NavigableMap navigableKeySet.

Prototype

NavigableSet<K> navigableKeySet();

Source Link

Document

Returns a NavigableSet view of the keys contained in this map.

Usage

From source file:org.apache.hadoop.hbase.coprocessor.TestCoprocessorEndpoint.java

@Test
public void testCoprocessorServiceNullResponse() throws Throwable {
    HTable table = new HTable(util.getConfiguration(), TEST_TABLE);
    NavigableMap<HRegionInfo, ServerName> regions = table.getRegionLocations();

    final TestProtos.EchoRequestProto request = TestProtos.EchoRequestProto.newBuilder().setMessage("hello")
            .build();//from  w  w w.  ja v  a 2 s .  co m
    try {
        // scan: for all regions
        final RpcController controller = new ServerRpcController();
        // test that null results are supported
        Map<byte[], String> results = table.coprocessorService(TestRpcServiceProtos.TestProtobufRpcProto.class,
                ROWS[0], ROWS[ROWS.length - 1],
                new Batch.Call<TestRpcServiceProtos.TestProtobufRpcProto, String>() {
                    public String call(TestRpcServiceProtos.TestProtobufRpcProto instance) throws IOException {
                        BlockingRpcCallback<TestProtos.EchoResponseProto> callback = new BlockingRpcCallback<TestProtos.EchoResponseProto>();
                        instance.echo(controller, request, callback);
                        TestProtos.EchoResponseProto response = callback.get();
                        LOG.debug("Batch.Call got result " + response);
                        return null;
                    }
                });
        for (Map.Entry<byte[], String> e : results.entrySet()) {
            LOG.info("Got value " + e.getValue() + " for region " + Bytes.toStringBinary(e.getKey()));
        }
        assertEquals(3, results.size());
        for (HRegionInfo info : regions.navigableKeySet()) {
            LOG.info("Region info is " + info.getRegionNameAsString());
            assertTrue(results.containsKey(info.getRegionName()));
            assertNull(results.get(info.getRegionName()));
        }
    } finally {
        table.close();
    }
}