Repository: telstra/open-kilda
Issue: Switch sync unable to handle misconfigured rules with the same cookie

Steps to reproduce:
1. Create two rules with the same cookie. One correct and one misconfigured.
2. Run switch sync on the switch.

Actual result:
Misconfigured rule is still on the switch.

Expected result:
No misconfigured rules on the switch.

Changed files:
src-java/swmanager-topology/swmanager-storm-topology/src/main/java/org/openkilda/wfm/topology/switchmanager/fsm/SwitchSyncFsm.java

diff --git a/src-java/swmanager-topology/swmanager-storm-topology/src/main/java/org/openkilda/wfm/topology/switchmanager/fsm/SwitchSyncFsm.java b/src-java/swmanager-topology/swmanager-storm-topology/src/main/java/org/openkilda/wfm/topology/switchmanager/fsm/SwitchSyncFsm.java
index c77cbea48..3c04b53c0 100644
--- a/src-java/swmanager-topology/swmanager-storm-topology/src/main/java/org/openkilda/wfm/topology/switchmanager/fsm/SwitchSyncFsm.java
+++ b/src-java/swmanager-topology/swmanager-storm-topology/src/main/java/org/openkilda/wfm/topology/switchmanager/fsm/SwitchSyncFsm.java
@@ -87,6 +87,7 @@ import java.util.Optional;
 import java.util.Set;
 import java.util.UUID;
 import java.util.stream.Collectors;
+import java.util.stream.Stream;
 
 @Slf4j
 public class SwitchSyncFsm extends AbstractBaseFsm<SwitchSyncFsm, SwitchSyncState, SwitchSyncEvent, Object> {
@@ -261,7 +262,7 @@ public class SwitchSyncFsm extends AbstractBaseFsm<SwitchSyncFsm, SwitchSyncStat
             log.info("Compute reinstall rules (switch={}, key={})", switchId, key);
             try {
                 List<FlowSpeakerData> misconfiguredRulesToRemove = reinstalledRulesCookies.stream()
-                        .map(this::findActualFlowByCookie)
+                        .flatMap(this::findActualFlowsByCookie)
                         .collect(Collectors.toList());
                 toRemove.addAll(misconfiguredRulesToRemove);
                 List<FlowSpeakerData> misconfiguredRulesToInstall = validationResult.getExpectedEntries().stream()
@@ -284,7 +285,7 @@ public class SwitchSyncFsm extends AbstractBaseFsm<SwitchSyncFsm, SwitchSyncStat
             log.info("Compute remove rules (switch={}, key={})", switchId, key);
             try {
                 List<FlowSpeakerData> excessRules = removedFlowRulesCookies.stream()
-                        .map(this::findActualFlowByCookie)
+                        .flatMap(this::findActualFlowsByCookie)
                         .collect(Collectors.toList());
                 toRemove.addAll(excessRules);
             } catch (Exception e) {
@@ -357,12 +358,11 @@ public class SwitchSyncFsm extends AbstractBaseFsm<SwitchSyncFsm, SwitchSyncStat
         }
     }
 
-    private FlowSpeakerData findActualFlowByCookie(long cookie) {
+    private Stream<FlowSpeakerData> findActualFlowsByCookie(long cookie) {
         return validationResult.getActualFlows().stream()
                 .filter(flowSpeakerData -> flowSpeakerData.getCookie().getValue() == cookie)
-                .findFirst()
-                .orElseThrow(() -> new IllegalStateException(
-                        format("Actual rule with cookie %s not found", cookie)));
+                .collect(Collectors.toList())
+                .stream();
     }
 
     private MeterSpeakerData findActualMeterById(long meterId) {