use of org.apache.hadoop.oncrpc.RpcCallCache.CacheEntry in project hadoop by apache.
the class TestRpcCallCache method testCacheFunctionality.
@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());
// Ensure the cache size is correct
assertEquals(size, cache.size());
// 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());
}
}
}
use of org.apache.hadoop.oncrpc.RpcCallCache.CacheEntry in project hadoop by apache.
the class TestRpcCallCache method testCacheEntry.
@Test
public void testCacheEntry() {
CacheEntry c = new CacheEntry();
validateInprogressCacheEntry(c);
assertTrue(c.isInProgress());
assertFalse(c.isCompleted());
assertNull(c.getResponse());
RpcResponse response = mock(RpcResponse.class);
c.setResponse(response);
validateCompletedCacheEntry(c, response);
}
use of org.apache.hadoop.oncrpc.RpcCallCache.CacheEntry in project hadoop by apache.
the class TestRpcCallCache method testAddRemoveEntries.
@Test
public void testAddRemoveEntries() throws UnknownHostException {
RpcCallCache cache = new RpcCallCache("test", 100);
InetAddress clientIp = InetAddress.getByName("1.1.1.1");
int xid = 100;
// Ensure null is returned when there is no entry in the cache
// An entry is added to indicate the request is in progress
CacheEntry e = cache.checkOrAddToCache(clientIp, xid);
assertNull(e);
e = cache.checkOrAddToCache(clientIp, xid);
validateInprogressCacheEntry(e);
// Set call as completed
RpcResponse response = mock(RpcResponse.class);
cache.callCompleted(clientIp, xid, response);
e = cache.checkOrAddToCache(clientIp, xid);
validateCompletedCacheEntry(e, response);
}
Aggregations