import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
import java.math.BigInteger;
import java.util.Collections;
import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
+import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.genius.mdsalutil.FlowEntity;
import org.opendaylight.genius.mdsalutil.NwConstants;
import org.opendaylight.genius.mdsalutil.NxMatchFieldType;
@Mock AclserviceConfig config;
@Mock IdManagerService idManager;
- MethodInvocationParamSaver<Void> installFlowValueSaver = null;
- MethodInvocationParamSaver<Void> removeFlowValueSaver = null;
+ MethodInvocationParamSaver<CheckedFuture<Void, TransactionCommitFailedException>> installFlowValueSaver = null;
+ MethodInvocationParamSaver<CheckedFuture<Void, TransactionCommitFailedException>> removeFlowValueSaver = null;
@Before
public void setUp() {
doReturn(Futures.immediateCheckedFuture(null)).when(mockWriteTx).submit();
doReturn(mockReadTx).when(dataBroker).newReadOnlyTransaction();
doReturn(mockWriteTx).when(dataBroker).newWriteOnlyTransaction();
- installFlowValueSaver = new MethodInvocationParamSaver<>(null);
- doAnswer(installFlowValueSaver).when(mdsalManager).installFlow(any(FlowEntity.class));
- removeFlowValueSaver = new MethodInvocationParamSaver<>(null);
- doAnswer(removeFlowValueSaver).when(mdsalManager).removeFlow(any(FlowEntity.class));
+ installFlowValueSaver = new MethodInvocationParamSaver<>(Futures.immediateCheckedFuture(null));
+ removeFlowValueSaver = new MethodInvocationParamSaver<>(Futures.immediateCheckedFuture(null));
+ doAnswer(removeFlowValueSaver).when(mdsalManager).removeFlow(any(BigInteger.class), any(FlowEntity.class));
+ doAnswer(installFlowValueSaver).when(mdsalManager).installFlow(any(BigInteger.class), any(FlowEntity.class));
}
@Test
Uuid sgUuid = new Uuid("12345678-1234-1234-1234-123456789012");
AclInterface ai = stubTcpAclInterface(sgUuid, "if_name", "1.1.1.1/32", 80, 80);
assertEquals(true, testedService.applyAcl(ai));
+ Thread.sleep(1000);
assertEquals(10, installFlowValueSaver.getNumOfInvocations());
- FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(0);
+ FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(1);
AclServiceTestUtils.verifyMatchInfo(firstRangeFlow.getMatchInfoList(),
NxMatchFieldType.nx_tcp_dst_with_mask, "80", "65535");
assertTrue(firstRangeFlow.getMatchInfoList().contains(new MatchTcpFlags(2)));
AclServiceTestUtils.verifyActionInfo(firstRangeFlow.getInstructionInfoList().get(0),
new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
-
}
@Test
Uuid sgUuid = new Uuid("12345678-1234-1234-1234-123456789012");
AclInterface ai = stubAllowAllInterface(sgUuid, "if_name");
assertEquals(true, testedService.applyAcl(ai));
+ Thread.sleep(1000);
assertEquals(10, installFlowValueSaver.getNumOfInvocations());
- FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(0);
+ FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(1);
AclServiceTestUtils.verifyActionInfo(firstRangeFlow.getInstructionInfoList().get(0),
new ActionNxResubmit(NwConstants.LPORT_DISPATCHER_TABLE));
}
Uuid sgUuid = new Uuid("12345678-1234-1234-1234-123456789012");
AclInterface ai = stubTcpAclInterface(sgUuid, "if_name", "1.1.1.1/32", 80, 84);
assertEquals(true, testedService.applyAcl(ai));
+ Thread.sleep(1000);
assertEquals(11, installFlowValueSaver.getNumOfInvocations());
- FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(0);
+ FlowEntity firstRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(9).get(1);
AclServiceTestUtils.verifyMatchInfo(firstRangeFlow.getMatchInfoList(),
NxMatchFieldType.nx_tcp_dst_with_mask, "80", "65532");
assertTrue(firstRangeFlow.getMatchInfoList().contains(new MatchTcpFlags(2)));
- FlowEntity secondRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(10).get(0);
+ FlowEntity secondRangeFlow = (FlowEntity) installFlowValueSaver.getInvocationParams(10).get(1);
AclServiceTestUtils.verifyMatchInfo(secondRangeFlow.getMatchInfoList(),
NxMatchFieldType.nx_tcp_dst_with_mask, "84", "65535");
assertTrue(secondRangeFlow.getMatchInfoList().contains(new MatchTcpFlags(2)));
Uuid sgUuid = new Uuid("12345678-1234-1234-1234-123456789012");
AclInterface ai = stubUdpAclInterface(sgUuid, "if_name", "1.1.1.1/32", 80, 80);
assertEquals(true, testedService.applyAcl(ai));
+ Thread.sleep(1000);
assertEquals(9, installFlowValueSaver.getNumOfInvocations());
}
Uuid sgUuid = new Uuid("12345678-1234-1234-1234-123456789012");
AclInterface ai = stubTcpAclInterface(sgUuid, "if_name", "1.1.1.1/32", 80, 80);
assertEquals(true, testedService.removeAcl(ai));
+ Thread.sleep(1000);
+
assertEquals(10, removeFlowValueSaver.getNumOfInvocations());
- FlowEntity firstRangeFlow = (FlowEntity) removeFlowValueSaver.getInvocationParams(9).get(0);
+ FlowEntity firstRangeFlow = (FlowEntity) removeFlowValueSaver.getInvocationParams(9).get(1);
assertTrue(firstRangeFlow.getMatchInfoList().contains(new MatchTcpFlags(2)));
AclServiceTestUtils.verifyMatchInfo(firstRangeFlow.getMatchInfoList(),
NxMatchFieldType.nx_tcp_dst_with_mask, "80", "65535");