use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingServiceTest method getMappingTest.
/**
* Tests {@link MappingService#getMapping} method.
*/
@Test
public void getMappingTest() throws ExecutionException, InterruptedException {
// input
final GetMappingInput getMappingInput = new GetMappingInputBuilder().setEid(IPV4_EID).build();
final MappingData mappingData = getDefaultMappingData();
final MappingRecord nonBinaryMappingRecord = getDefaultMappingRecordBuilder().setEid(LispAddressUtil.toEid(new Ipv4Address(IPV4_STRING), null)).build();
Mockito.when(mappingSystem.getMapping(getMappingInput.getEid())).thenReturn(mappingData);
final RpcResult<GetMappingOutput> rpc = RpcResultBuilder.success(new GetMappingOutputBuilder().setMappingRecord(nonBinaryMappingRecord)).build();
// result
final Future<RpcResult<GetMappingOutput>> result = mappingService.getMapping(getMappingInput);
final RpcResult<GetMappingOutput> rpcResult = result.get();
assertEquals(rpc.getResult(), rpcResult.getResult());
assertEquals(rpc.getErrors(), rpcResult.getErrors());
assertEquals(rpc.isSuccessful(), rpcResult.isSuccessful());
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingDataListenerTest method onDataTreeChangedTest_subtreeModified_NB.
/**
* Tests {@link MappingDataListener#onDataTreeChanged} method with SUBTREE_MODIFIED modification type from
* northbound.
*/
@Test
@Ignore
@SuppressWarnings("unchecked")
public void onDataTreeChangedTest_subtreeModified_NB() throws InterruptedException {
final List<DataTreeModification<Mapping>> changes = Lists.newArrayList(change_subtreeModified);
final MappingChanged mapChanged = MSNotificationInputUtil.toMappingChanged(MAPPING_EID_2_NB.getMappingRecord(), null, null, null, MappingChange.Updated);
Mockito.when(mod_subtreeModified.getDataAfter()).thenReturn(MAPPING_EID_2_NB);
mappingDataListener.onDataTreeChanged(changes);
final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
Mockito.verify(iMappingSystemMock).addMapping(Mockito.eq(MappingOrigin.Northbound), Mockito.eq(IPV4_EID_2), captor.capture());
assertEquals(captor.getValue().getRecord(), MAPPING_EID_2_NB.getMappingRecord());
Mockito.verify(notificationPublishServiceMock).putNotification(mapChanged);
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class MappingDataListenerTest method onDataTreeChangedTest_write_NB.
/**
* Tests {@link MappingDataListener#onDataTreeChanged} method with WRITE modification type from northbound.
*/
@Test
@Ignore
@SuppressWarnings("unchecked")
public void onDataTreeChangedTest_write_NB() throws InterruptedException {
final List<DataTreeModification<Mapping>> changes = Lists.newArrayList(change_write);
final MappingChanged mapChanged = MSNotificationInputUtil.toMappingChanged(MAPPING_EID_3_NB.getMappingRecord(), null, null, null, MappingChange.Created);
Mockito.when(mod_write.getDataAfter()).thenReturn(MAPPING_EID_3_NB);
mappingDataListener.onDataTreeChanged(changes);
final ArgumentCaptor<MappingData> captor = ArgumentCaptor.forClass(MappingData.class);
Mockito.verify(iMappingSystemMock).addMapping(Mockito.eq(MappingOrigin.Northbound), Mockito.eq(IPV4_EID_3), captor.capture());
assertEquals(captor.getValue().getRecord(), MAPPING_EID_3_NB.getMappingRecord());
Mockito.verify(notificationPublishServiceMock).putNotification(mapChanged);
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class TimeBucketWheelUnitTest method mappingRefreshedProperlyTest.
/**
* Tests {@link TimeBucketWheel#refreshMappping(Eid, MappingData, long, int)} method.
* {@link ClassCastException} can be thrown.
*/
@Test
public void mappingRefreshedProperlyTest() {
PowerMockito.mockStatic(System.class);
long frozenTimeStamp = System.currentTimeMillis();
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
TimeBucketWheel timeBucketWheel = getDefaultTimeBucketWheel();
final int bucketId1 = timeBucketWheel.add(IPV4_EID_1, getDefaultMappingData(IPV4_EID_1), System.currentTimeMillis());
frozenTimeStamp += 2000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
MappingData newMappingData = getDefaultMappingData(IPV4_EID_1);
int currentBucketId = timeBucketWheel.refreshMappping(IPV4_EID_1, newMappingData, System.currentTimeMillis(), bucketId1);
List<TimeBucket> bucketList = extractBucketList(timeBucketWheel);
TimeBucket pastTimeBucket = bucketList.get(bucketId1);
MappingData oldStoredMappingData = getMappingDataFromTimeBucket(pastTimeBucket, IPV4_EID_1);
Assert.assertNull(oldStoredMappingData);
TimeBucket presentTimeBucket = bucketList.get(currentBucketId);
MappingData newStoredMappingData = getMappingDataFromTimeBucket(presentTimeBucket, IPV4_EID_1);
Assert.assertEquals(newMappingData, newStoredMappingData);
}
use of org.opendaylight.lispflowmapping.lisp.type.MappingData in project lispflowmapping by opendaylight.
the class TimeBucketWheelUnitTest method checkOlderThanCurrentCase.
private void checkOlderThanCurrentCase(TimeBucketWheel timeBucketWheel) {
long frozenTimeStamp = System.currentTimeMillis();
int bucketId1 = timeBucketWheel.add(IPV4_EID_1, getDefaultMappingData(IPV4_EID_1), frozenTimeStamp);
MappingData toBeExpiredMappingData = getDefaultMappingData(IPV4_EID_2);
int bucketId2 = timeBucketWheel.add(IPV4_EID_2, toBeExpiredMappingData, frozenTimeStamp - 1000);
Assert.assertEquals((bucketId1 + 1) % NUMBER_OF_BUCKETS, bucketId2);
// expired at proper time
frozenTimeStamp = frozenTimeStamp + 3000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
timeBucketWheel.clearExpiredMappingAndRotate();
Mockito.verify(mappingSystem).handleSbExpiredMapping(IPV4_EID_2, null, toBeExpiredMappingData);
}
Aggregations