Skip to content
Snippets Groups Projects
Commit 6e304b30 authored by Rob Adams's avatar Rob Adams
Browse files

Greatly shorten staticflowentrypusher test time

parent 527ec8f4
No related branches found
No related tags found
No related merge requests found
...@@ -68,7 +68,7 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL ...@@ -68,7 +68,7 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL
protected ArrayList<String> flowmodList; protected ArrayList<String> flowmodList;
protected ArrayList<IOFSwitch> activeSwitches; protected ArrayList<IOFSwitch> activeSwitches;
protected HashMap<Long, HashMap<String, OFFlowMod>> flowmods; protected HashMap<Long, HashMap<String, OFFlowMod>> flowmods;
protected int pushEntriesFrequency = 25; // seconds protected int pushEntriesFrequency = 25000; // milliseconds
protected Runnable pushEntriesTimer; protected Runnable pushEntriesTimer;
public StaticFlowEntryPusher() { public StaticFlowEntryPusher() {
...@@ -92,17 +92,17 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL ...@@ -92,17 +92,17 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL
/** /**
* Gets the static flow entry push interval * Gets the static flow entry push interval
* @return The push interval in seconds * @return The push interval in milliseconds
*/ */
public int getFlowPushTimeSeconds() { public int getFlowPushTime() {
return pushEntriesFrequency; return pushEntriesFrequency;
} }
/** /**
* Sets the static flow entry push interval * Sets the static flow entry push interval
* @param s The interval in seconds to set * @param s The interval in milliseconds to set
*/ */
public void setFlowPushTimeSeconds(int s) { public void setFlowPushTime(int s) {
pushEntriesFrequency = s; pushEntriesFrequency = s;
} }
...@@ -615,12 +615,14 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL ...@@ -615,12 +615,14 @@ public class StaticFlowEntryPusher implements IStaticFlowEntryPusher, IOFSwitchL
ScheduledExecutorService ses = ScheduledExecutorService ses =
floodlightProvider.getScheduledExecutor(); floodlightProvider.getScheduledExecutor();
ses.schedule(this, ses.schedule(this,
pushEntriesFrequency, TimeUnit.SECONDS); pushEntriesFrequency, TimeUnit.MILLISECONDS);
} }
} }
}; };
// Initially push entries in 1 second // Initially push entries
floodlightProvider.getScheduledExecutor().schedule(pushEntriesTimer, 1, TimeUnit.SECONDS); floodlightProvider.getScheduledExecutor().schedule(pushEntriesTimer,
pushEntriesFrequency,
TimeUnit.MILLISECONDS);
} }
/** /**
......
...@@ -50,12 +50,16 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase { ...@@ -50,12 +50,16 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase {
@Test @Test
public void testAddAndRemoveEntries() throws Exception { public void testAddAndRemoveEntries() throws Exception {
StaticFlowEntryPusher staticFlowEntryPusher = new StaticFlowEntryPusher(); StaticFlowEntryPusher staticFlowEntryPusher =
new StaticFlowEntryPusher();
staticFlowEntryPusher.setFlowPushTime(200);
IOFSwitch mockSwitch = createMock(IOFSwitch.class); IOFSwitch mockSwitch = createMock(IOFSwitch.class);
long dpid = HexString.toLong(TestSwitch1DPID); long dpid = HexString.toLong(TestSwitch1DPID);
Capture<OFMessage> writeCapture = new Capture<OFMessage>(CaptureType.ALL); Capture<OFMessage> writeCapture = new Capture<OFMessage>(CaptureType.ALL);
Capture<FloodlightContext> contextCapture = new Capture<FloodlightContext>(CaptureType.ALL); Capture<FloodlightContext> contextCapture =
Capture<List<OFMessage>> writeCaptureList = new Capture<List<OFMessage>>(CaptureType.ALL); new Capture<FloodlightContext>(CaptureType.ALL);
Capture<List<OFMessage>> writeCaptureList =
new Capture<List<OFMessage>>(CaptureType.ALL);
mockSwitch.write(capture(writeCapture), capture(contextCapture)); mockSwitch.write(capture(writeCapture), capture(contextCapture));
expectLastCall().anyTimes(); expectLastCall().anyTimes();
...@@ -67,8 +71,6 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase { ...@@ -67,8 +71,6 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase {
switchMap.put(dpid, mockSwitch); switchMap.put(dpid, mockSwitch);
mockFloodlightProvider.setSwitches(switchMap); mockFloodlightProvider.setSwitches(switchMap);
staticFlowEntryPusher.setFloodlightProvider(mockFloodlightProvider); staticFlowEntryPusher.setFloodlightProvider(mockFloodlightProvider);
staticFlowEntryPusher.setFlowPushTimeSeconds(2); // speed up push timer for faster testing
long timeSfpStart = System.currentTimeMillis();
staticFlowEntryPusher.startUp(); staticFlowEntryPusher.startUp();
// if someone calls getId(), return this dpid instead // if someone calls getId(), return this dpid instead
...@@ -86,21 +88,26 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase { ...@@ -86,21 +88,26 @@ public class StaticFlowEntryPusherTest extends FloodlightTestCase {
// Verify that the switch has gotten some flow_mods // Verify that the switch has gotten some flow_mods
assertEquals(true, writeCapture.getValues().size() == 2); assertEquals(true, writeCapture.getValues().size() == 2);
long timeNow = System.currentTimeMillis(); int count = 5;
// Sleep just long enough for static flow pusher to re-push entires while (count >= 0) {
long timeNeededToSleep = (staticFlowEntryPusher.getFlowPushTimeSeconds() * 1000) - (timeNow - timeSfpStart); Thread.sleep(staticFlowEntryPusher.getFlowPushTime());
if (timeNeededToSleep > 0)
Thread.sleep(timeNeededToSleep); if (writeCapture.getValues().size() >= 4)
break;
count -= 1;
}
int newsize = writeCapture.getValues().size();
// Make sure the entries were pushed again // Make sure the entries were pushed again
assertEquals(true, writeCapture.getValues().size() == 4); assertTrue(newsize >= 4);
// Remove entries // Remove entries
staticFlowEntryPusher.removeEntry(flowMod1); staticFlowEntryPusher.removeEntry(flowMod1);
staticFlowEntryPusher.removeEntry(flowMod2); staticFlowEntryPusher.removeEntry(flowMod2);
Thread.sleep(staticFlowEntryPusher.getFlowPushTimeSeconds() * 1000); Thread.sleep(staticFlowEntryPusher.getFlowPushTime());
// Make sure the entries were NOT pushed again // Make sure the entries were NOT pushed again
assertEquals(true, writeCapture.getValues().size() == 4); assertEquals(newsize, writeCapture.getValues().size());
} }
} }
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