mirror of
https://github.com/opennetworkinglab/onos.git
synced 2026-05-05 12:16:13 +02:00
Fix testUninstallAndInstallNonDisruptive test
Change-Id: Id5f8cd5a3b270231ccadfcde5ad4934c5ee407e0 (cherry picked from commit 9f832343ebd760246928e54c86080227a1ebfdf4)
This commit is contained in:
parent
57ba38eb10
commit
68c025bda8
@ -31,6 +31,7 @@ import org.onosproject.net.flow.DefaultFlowRule;
|
||||
import org.onosproject.net.flow.DefaultTrafficSelector;
|
||||
import org.onosproject.net.flow.DefaultTrafficTreatment;
|
||||
import org.onosproject.net.flow.FlowRule;
|
||||
import org.onosproject.net.flow.FlowRuleOperation;
|
||||
import org.onosproject.net.flow.FlowRuleOperations;
|
||||
import org.onosproject.net.flow.FlowRuleServiceAdapter;
|
||||
import org.onosproject.net.flow.TrafficSelector;
|
||||
@ -54,6 +55,8 @@ import java.util.stream.Collectors;
|
||||
import static org.easymock.EasyMock.mock;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.onosproject.net.flow.FlowRuleOperation.Type.ADD;
|
||||
import static org.onosproject.net.flow.FlowRuleOperation.Type.REMOVE;
|
||||
|
||||
/**
|
||||
* Tests for flow rule Intent installer.
|
||||
@ -61,14 +64,14 @@ import static org.junit.Assert.assertTrue;
|
||||
public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
|
||||
private TestFlowRuleService flowRuleService;
|
||||
private TestFlowRuleServiceNonDisruptive flowRuleServiceNonDisruptive;
|
||||
private final TestFlowRuleServiceNonDisruptive flowRuleServiceNonDisruptive =
|
||||
new TestFlowRuleServiceNonDisruptive();
|
||||
private FlowRuleIntentInstaller installer;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
super.setup();
|
||||
flowRuleService = new TestFlowRuleService();
|
||||
flowRuleServiceNonDisruptive = new TestFlowRuleServiceNonDisruptive();
|
||||
installer = new FlowRuleIntentInstaller();
|
||||
installer.flowRuleService = flowRuleService;
|
||||
installer.store = new SimpleIntentStore();
|
||||
@ -381,6 +384,14 @@ public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
.makePermanent()
|
||||
.build();
|
||||
|
||||
// We need to wait a bit in order to avoid
|
||||
// race conditions and failing builds
|
||||
synchronized (flowRuleServiceNonDisruptive) {
|
||||
while (!verifyFlowRule(ADD, firstStageInstalledRule)) {
|
||||
flowRuleServiceNonDisruptive.wait();
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(flowRuleServiceNonDisruptive.flowRulesAdd.contains(firstStageInstalledRule));
|
||||
|
||||
selector = DefaultTrafficSelector.builder()
|
||||
@ -399,6 +410,12 @@ public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
.makePermanent()
|
||||
.build();
|
||||
|
||||
synchronized (flowRuleServiceNonDisruptive) {
|
||||
while (!verifyFlowRule(REMOVE, secondStageUninstalledRule)) {
|
||||
flowRuleServiceNonDisruptive.wait();
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(flowRuleServiceNonDisruptive.flowRulesRemove.contains(secondStageUninstalledRule));
|
||||
|
||||
selector = DefaultTrafficSelector.builder()
|
||||
@ -417,6 +434,12 @@ public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
.makePermanent()
|
||||
.build();
|
||||
|
||||
synchronized (flowRuleServiceNonDisruptive) {
|
||||
while (!verifyFlowRule(ADD, thirdStageInstalledRule)) {
|
||||
flowRuleServiceNonDisruptive.wait();
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(flowRuleServiceNonDisruptive.flowRulesAdd.contains(thirdStageInstalledRule));
|
||||
|
||||
selector = DefaultTrafficSelector.builder()
|
||||
@ -435,12 +458,23 @@ public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
.makePermanent()
|
||||
.build();
|
||||
|
||||
synchronized (flowRuleServiceNonDisruptive) {
|
||||
while (!verifyFlowRule(REMOVE, lastStageUninstalledRule)) {
|
||||
flowRuleServiceNonDisruptive.wait();
|
||||
}
|
||||
}
|
||||
|
||||
assertTrue(flowRuleServiceNonDisruptive.flowRulesRemove.contains(lastStageUninstalledRule));
|
||||
|
||||
IntentOperationContext successContext = intentInstallCoordinator.successContext;
|
||||
assertEquals(successContext, operationContext);
|
||||
}
|
||||
|
||||
private boolean verifyFlowRule(FlowRuleOperation.Type type, FlowRule flowRule) {
|
||||
return type == ADD ? flowRuleServiceNonDisruptive.flowRulesAdd.contains(flowRule) :
|
||||
flowRuleServiceNonDisruptive.flowRulesRemove.contains(flowRule);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates FlowRuleIntents for test.
|
||||
*
|
||||
@ -734,6 +768,9 @@ public class FlowRuleIntentInstallerTest extends AbstractIntentInstallerTest {
|
||||
public void apply(FlowRuleOperations ops) {
|
||||
record(ops);
|
||||
ops.callback().onSuccess(ops);
|
||||
synchronized (this) {
|
||||
this.notify();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user