16 package org.openkilda.floodlight.service.batch;
18 import static org.easymock.EasyMock.capture;
19 import static org.easymock.EasyMock.createMock;
20 import static org.easymock.EasyMock.expect;
21 import static org.easymock.EasyMock.newCapture;
22 import static org.easymock.EasyMock.replay;
23 import static org.easymock.EasyMock.verify;
28 import com.google.common.collect.ImmutableList;
29 import net.floodlightcontroller.core.IOFSwitch;
30 import org.easymock.Capture;
31 import org.easymock.CaptureType;
32 import org.junit.Assert;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.projectfloodlight.openflow.protocol.OFFactory;
36 import org.projectfloodlight.openflow.protocol.OFMessage;
37 import org.projectfloodlight.openflow.protocol.OFType;
38 import org.projectfloodlight.openflow.protocol.ver13.OFFactoryVer13;
39 import org.projectfloodlight.openflow.types.DatapathId;
41 import java.util.Iterator;
42 import java.util.List;
45 private OFMessage payload;
46 private IOFSwitch iofSwitch = createMock(IOFSwitch.class);
48 protected final DatapathId
switchId = DatapathId.of(0x00ff000001L);
51 public void setUp() throws Exception {
52 OFFactory ofFactory =
new OFFactoryVer13();
53 payload = ofFactory.buildFlowAdd()
56 expect(iofSwitch.getOFFactory()).andReturn(ofFactory).anyTimes();
62 BatchRecord batch =
new BatchRecord(switchUtils, ImmutableList.of(batchRecord));
67 Capture<OFMessage> captureSwitchWrite = newCapture(CaptureType.ALL);
69 expect(iofSwitch.getId()).andReturn(
switchId).anyTimes();
70 expect(iofSwitch.write(capture(captureSwitchWrite))).andReturn(
true).times(2);
76 throw new AssertionError(
"Batch write operation failed", e);
79 verify(switchUtils, iofSwitch);
81 List<OFMessage> switchWriteRecords = captureSwitchWrite.getValues();
83 Iterator<OFMessage> iter = switchWriteRecords.iterator();
84 Assert.assertEquals(payload, iter.next());
85 Assert.assertEquals(OFType.BARRIER_REQUEST, iter.next().getType());
IOFSwitch lookupSwitch(DatapathId dpId)
final DatapathId switchId