本文整理汇总了Java中org.apache.hadoop.oncrpc.RpcCallCache.ClientRequest类的典型用法代码示例。如果您正苦于以下问题:Java ClientRequest类的具体用法?Java ClientRequest怎么用?Java ClientRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ClientRequest类属于org.apache.hadoop.oncrpc.RpcCallCache包,在下文中一共展示了ClientRequest类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCacheFunctionality
import org.apache.hadoop.oncrpc.RpcCallCache.ClientRequest; //导入依赖的package包/类
@Test
public void testCacheFunctionality() throws UnknownHostException {
RpcCallCache cache = new RpcCallCache("Test", 10);
// Add 20 entries to the cache and only last 10 should be retained
int size = 0;
for (int clientId = 0; clientId < 20; clientId++) {
InetAddress clientIp = InetAddress.getByName("1.1.1."+clientId);
System.out.println("Adding " + clientIp);
cache.checkOrAddToCache(clientIp, 0);
size = Math.min(++size, 10);
System.out.println("Cache size " + cache.size());
assertEquals(size, cache.size()); // Ensure the cache size is correct
// Ensure the cache entries are correct
int startEntry = Math.max(clientId - 10 + 1, 0);
Iterator<Entry<ClientRequest, CacheEntry>> iterator = cache.iterator();
for (int i = 0; i < size; i++) {
ClientRequest key = iterator.next().getKey();
System.out.println("Entry " + key.getClientId());
assertEquals(InetAddress.getByName("1.1.1." + (startEntry + i)),
key.getClientId());
}
// Ensure cache entries are returned as in progress.
for (int i = 0; i < size; i++) {
CacheEntry e = cache.checkOrAddToCache(
InetAddress.getByName("1.1.1." + (startEntry + i)), 0);
assertNotNull(e);
assertTrue(e.isInProgress());
assertFalse(e.isCompleted());
}
}
}