Skip to content
Snippets Groups Projects
Commit 4ecd6792 authored by Kanzhe Jiang's avatar Kanzhe Jiang
Browse files

change unit test from sleep to a wait loop with timeout

minor toString fix in Device
parent 250d4b6d
No related branches found
No related tags found
No related merge requests found
......@@ -366,7 +366,7 @@ public class Device {
return "Device [dataLayerAddress=" +
dlAddrString +
", attachmentPoints=" + attachmentPoints + ", networkAddresses="
+ IPv4.fromIPv4AddressCollection(networkAddresses.keySet()) + "]";
+ "[" + IPv4.fromIPv4AddressCollection(networkAddresses.keySet()) + "]";
}
public Date getLastSeenInStorage() {
......
......@@ -333,9 +333,13 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
assertEquals(2, rdevice.getAttachmentPoints().size());
assertEquals(2, rdevice.getNetworkAddresses().size());
// Sleep to make sure the aging thread has run
Thread.sleep(Math.max(DeviceManagerImpl.DEVICE_NA_MAX_AGE, DeviceManagerImpl.DEVICE_AP_MAX_AGE)*1000);
deviceManager.removeAgedDevices(new Date());
// Wait until device's network address expired.
Date boundaryTime = new Date(new Date().getTime() + DeviceManagerImpl.DEVICE_MAX_AGE*1000);
while (deviceManager.getDeviceByDataLayerAddress(dataLayerSource).getNetworkAddresses().size() != 0) {
Date curTime = new Date();
assertFalse(curTime.after(boundaryTime));
deviceManager.removeAgedDevices(curTime);
}
rdevice = deviceManager.getDeviceByDataLayerAddress(dataLayerSource);
assertEquals(0, rdevice.getNetworkAddresses().size());
......@@ -346,13 +350,14 @@ public class DeviceManagerImplTest extends FloodlightTestCase {
assertEquals(0, rdevice.getAttachmentPoints().size());
assertEquals(0, rdevice.getNetworkAddresses().size());
// Sleep a bit longer seconds to allow device age
Thread.sleep((DeviceManagerImpl.DEVICE_MAX_AGE -
Math.max(DeviceManagerImpl.DEVICE_NA_MAX_AGE, DeviceManagerImpl.DEVICE_AP_MAX_AGE))*1000);
deviceManager.removeAgedDevices(new Date());
assertNull(deviceManager.getDeviceByDataLayerAddress(dataLayerSource));
// Wait until device expired.
boundaryTime = new Date(new Date().getTime() + DeviceManagerImpl.DEVICE_MAX_AGE*1000);
while (deviceManager.getDeviceByDataLayerAddress(dataLayerSource) != null) {
Date curTime = new Date();
assertFalse(curTime.after(boundaryTime));
deviceManager.removeAgedDevices(curTime);
}
// Make sure the device's AP and NA were removed from storage
deviceManager.readAllDeviceStateFromStorage();
assertNull(deviceManager.getDeviceByDataLayerAddress(dataLayerSource));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment