use of org.opendaylight.lispflowmapping.implementation.timebucket.containers.TimeBucketWheel 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.implementation.timebucket.containers.TimeBucketWheel in project lispflowmapping by opendaylight.
the class TimeBucketWheelUnitTest method mappingAddedInTheProperBucketAddInMiddleTest.
/**
* Tests {@link TimeBucketWheel#add(Eid, MappingData, long)} method for add in some bucket in the middle.
*/
@Test
public void mappingAddedInTheProperBucketAddInMiddleTest() throws Exception {
PowerMockito.mockStatic(System.class);
long frozenTimeStamp = System.currentTimeMillis();
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
TimeBucketWheel timeBucketWheel = getDefaultTimeBucketWheel();
checkTooOldMappingCase(timeBucketWheel);
checkOlderThanCurrentCase(timeBucketWheel);
}
use of org.opendaylight.lispflowmapping.implementation.timebucket.containers.TimeBucketWheel in project lispflowmapping by opendaylight.
the class TimeBucketWheelUnitTest method expiredMappingClearedProperlyTest.
/**
* Tests {@link TimeBucketWheel#clearExpiredMappingAndRotate(long)} method.
* {@link ClassCastException} can be thrown.
*/
@Test
public void expiredMappingClearedProperlyTest() {
PowerMockito.mockStatic(System.class);
long frozenTimeStamp = System.currentTimeMillis();
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
TimeBucketWheel timeBucketWheel = getDefaultTimeBucketWheel();
MappingData mappingData = getDefaultMappingData(IPV4_EID_1);
timeBucketWheel.add(IPV4_EID_1, mappingData, System.currentTimeMillis());
frozenTimeStamp = System.currentTimeMillis() + 4000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
timeBucketWheel.clearExpiredMappingAndRotate(frozenTimeStamp);
Mockito.verify(mappingSystem).handleSbExpiredMapping(IPV4_EID_1, null, mappingData);
}
use of org.opendaylight.lispflowmapping.implementation.timebucket.containers.TimeBucketWheel in project lispflowmapping by opendaylight.
the class TimeBucketWheelUnitTest method mappingAddedInTheProperBucketGeneralTest.
/**
* Tests {@link TimeBucketWheel#add(Eid, MappingData, long)} method for general case.
*/
@Test
public void mappingAddedInTheProperBucketGeneralTest() {
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 += 1000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
final int bucketId2 = timeBucketWheel.add(IPV4_EID_2, getDefaultMappingData(IPV4_EID_2), System.currentTimeMillis());
frozenTimeStamp += 1000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
final int bucketId3 = timeBucketWheel.add(IPV4_EID_3, getDefaultMappingData(IPV4_EID_3), System.currentTimeMillis());
frozenTimeStamp += 1000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
final int bucketId4 = timeBucketWheel.add(IPV4_EID_4, getDefaultMappingData(IPV4_EID_4), System.currentTimeMillis());
frozenTimeStamp += 1000;
PowerMockito.when(System.currentTimeMillis()).thenReturn(frozenTimeStamp);
final int bucketId5 = timeBucketWheel.add(IPV4_EID_5, getDefaultMappingData(IPV4_EID_5), System.currentTimeMillis());
Assert.assertEquals((bucketId1 - 1 + NUMBER_OF_BUCKETS) % NUMBER_OF_BUCKETS, bucketId2);
Assert.assertEquals((bucketId2 - 1 + NUMBER_OF_BUCKETS) % NUMBER_OF_BUCKETS, bucketId3);
Assert.assertEquals((bucketId3 - 1 + NUMBER_OF_BUCKETS) % NUMBER_OF_BUCKETS, bucketId4);
Assert.assertEquals((bucketId4 - 1 + NUMBER_OF_BUCKETS) % NUMBER_OF_BUCKETS, bucketId5);
}
Aggregations