}
}
- private Object getMappingExactSD(Eid srcEid, Eid dstEid, ILispDAO mappingsDb) {
- Map<String, ?> daoEntry = mappingsDb.get(dstEid);
- if (daoEntry != null) {
- // try SrcDst eid lookup
- ILispDAO srcDstDao = (ILispDAO) daoEntry.get(SubKeys.LCAF_SRCDST);
- if (srcEid != null && srcDstDao != null) {
- return srcDstDao.getSpecific(srcEid, SubKeys.RECORD);
- }
- // if lookup fails, return whatever is found for dst eid
- return daoEntry.get(SubKeys.RECORD);
- }
- return null;
- }
-
// Returns the mapping corresponding to the longest prefix match for eid.
// eid must be a simple (maskable or not) address
private Object getMappingLpmEid(Eid eid, ILispDAO mappingsDb) {
}
if (shouldMerge) {
- List<XtrId> expiredMappings = new ArrayList<XtrId>();
- Set<IpAddressBinary> sourceRlocs = new HashSet<IpAddressBinary>();
+ List<XtrId> expiredMappings = new ArrayList<>();
+ Set<IpAddressBinary> sourceRlocs = new HashSet<>();
MappingRecord mergedEntry = MappingMergeUtil.mergeXtrIdMappings(getXtrIdMappingList(xtrIdDao),
expiredMappings, sourceRlocs);
removeExpiredXtrIdTableEntries(xtrIdDao, expiredMappings);
// Returns the list of mappings stored in an xTR-ID DAO
private List<Object> getXtrIdMappingList(ILispDAO dao) {
if (dao != null) {
- final List<Object> records = new ArrayList<Object>();
+ final List<Object> records = new ArrayList<>();
dao.getAll(new IRowVisitor() {
public void visitRow(Object keyId, String valueKey, Object value) {
if (valueKey.equals(SubKeys.RECORD)) {
}
return null;
}
-/*
- private SimpleImmutableEntry<byte[], Long> getXtrIdMinTimeStamp(ILispDAO dao) {
- if (dao != null) {
- // We don't actually need a list here, but the external variable we modify inside the IRowVisitor
- // implementation has to be final. So we use a List, and it's methods, to modify contents
- final List<SimpleImmutableEntry<byte[], Long>> entries =
- new ArrayList<SimpleImmutableEntry<byte[], Long>>();
- entries.set(0, new SimpleImmutableEntry<byte[], Long>(null, System.currentTimeMillis()));
- dao.getAll(new IRowVisitor() {
- public void visitRow(Object keyId, String valueKey, Object value) {
- if (valueKey.equals(SubKeys.RECORD)) {
- byte[] currentXtrId = ((MappingRecord) value).getXtrId();
- long currentTimestamp = ((MappingRecord) value).getTimestamp();
- // If one of the timestamps is expired, we signal it to the caller by setting the returned
- // timestamp to null. The caller will then have to remove that xTR-ID, and do a full merge
- // (or decrement)
- if (MappingMergeUtil.timestampIsExpired(currentTimestamp)) {
- SimpleImmutableEntry<byte[], Long> entry =
- new SimpleImmutableEntry<byte[], Long>(currentXtrId, null);
- entries.set(0, entry);
- return;
- }
- if (entries.get(0).getValue() > currentTimestamp) {
- SimpleImmutableEntry<byte[], Long> entry =
- new SimpleImmutableEntry<byte[], Long>(currentXtrId, currentTimestamp);
- entries.set(0, entry);
- }
- }
- }
- });
- return entries.get(0);
- }
- return null;
- }
-*/
// Returns the mapping corresponding to the longest prefix match for eid. eid must be a simple (maskable or not)
// address
private Object getMappingLpmEid(Eid eid, byte[] xtrId, ILispDAO dao) {
import static org.mockito.Mockito.when;
import com.google.common.collect.Maps;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
import java.util.Date;
import java.util.Map;
import org.junit.Before;
Mockito.verifyZeroInteractions(tableDaoMock);
}
- /**
- * Tests {@link MultiTableMapCache#getMappingExactSD} method.
- */
- @Test
- public void getMappingExactSDTest() throws NoSuchMethodException, InvocationTargetException,
- IllegalAccessException {
- Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
- ILispDAO.class);
- getMappingExactSD.setAccessible(true);
-
- when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
- when(srcDstDaoMock.getSpecific(EID_IPV4_PREFIX_SRC, SubKeys.RECORD)).thenReturn(DUMMY_OBJECT);
-
- Object result = getMappingExactSD.invoke(
- multiTableMapCache, EID_IPV4_PREFIX_SRC, EID_IPV4_PREFIX_DST, tableDaoMock);
- assertEquals(DUMMY_OBJECT, result);
- }
-
- /**
- * Tests {@link MultiTableMapCache#getMappingExactSD} method with null src eid.
- */
- @Test
- public void getMappingExactSDTest_withNullSrcEid() throws NoSuchMethodException, InvocationTargetException,
- IllegalAccessException {
- Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
- ILispDAO.class);
- getMappingExactSD.setAccessible(true);
-
- when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(getEntry1());
-
- Object result = getMappingExactSD.invoke(
- multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
- assertEquals(DUMMY_OBJECT, result);
- }
-
- /**
- * Tests {@link MultiTableMapCache#getMappingExactSD} method with null entry.
- */
- @Test
- public void getMappingExactSDTest_withNullEntry() throws NoSuchMethodException, InvocationTargetException,
- IllegalAccessException {
- Method getMappingExactSD = MultiTableMapCache.class.getDeclaredMethod("getMappingExactSD", Eid.class, Eid.class,
- ILispDAO.class);
- getMappingExactSD.setAccessible(true);
-
- when(tableDaoMock.get(EID_IPV4_PREFIX_DST)).thenReturn(null);
-
- Object result = getMappingExactSD.invoke(
- multiTableMapCache, null, EID_IPV4_PREFIX_DST, tableDaoMock);
- assertNull(result);
- }
-
/**
* The following test is for coverage-increase purpose only.
*/