alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Foundation |
alshabib | ab98466 | 2014-12-04 18:56:18 -0800 | [diff] [blame] | 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.net.intent.impl; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 17 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 18 | import com.google.common.collect.HashMultimap; |
| 19 | import com.google.common.collect.Lists; |
| 20 | import com.google.common.collect.Maps; |
| 21 | import com.google.common.collect.Multimap; |
| 22 | import com.google.common.collect.Sets; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 23 | import org.hamcrest.Description; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 24 | import org.hamcrest.TypeSafeMatcher; |
| 25 | import org.junit.After; |
| 26 | import org.junit.Before; |
Jonathan Hart | 4fd4ebb | 2015-02-04 17:38:48 -0800 | [diff] [blame] | 27 | import org.junit.Ignore; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 28 | import org.junit.Test; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 29 | import org.onosproject.TestApplicationId; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 30 | import org.onosproject.cfg.ComponentConfigAdapter; |
Sho SHIMIZU | d5bf106 | 2016-02-25 10:26:02 -0800 | [diff] [blame] | 31 | import org.onosproject.cfg.ComponentConfigService; |
Thomas Vachuska | c46af20 | 2015-06-03 16:43:27 -0700 | [diff] [blame] | 32 | import org.onosproject.common.event.impl.TestEventDispatcher; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 33 | import org.onosproject.core.ApplicationId; |
| 34 | import org.onosproject.core.impl.TestCoreManager; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 35 | import org.onosproject.net.NetworkResource; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 36 | import org.onosproject.net.flow.FlowRuleOperations; |
| 37 | import org.onosproject.net.flow.FlowRuleOperationsContext; |
| 38 | import org.onosproject.net.flow.FlowRuleService; |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 39 | import org.onosproject.net.intent.FlowRuleIntent; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 40 | import org.onosproject.net.intent.Intent; |
Yuta HIGUCHI | d95d590 | 2016-06-27 00:18:45 -0700 | [diff] [blame] | 41 | import org.onosproject.net.intent.IntentCompilationException; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 42 | import org.onosproject.net.intent.IntentCompiler; |
Thomas Vachuska | c46af20 | 2015-06-03 16:43:27 -0700 | [diff] [blame] | 43 | import org.onosproject.net.intent.IntentData; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 44 | import org.onosproject.net.intent.IntentEvent; |
| 45 | import org.onosproject.net.intent.IntentEvent.Type; |
| 46 | import org.onosproject.net.intent.IntentExtensionService; |
| 47 | import org.onosproject.net.intent.IntentId; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 48 | import org.onosproject.net.intent.IntentInstallCoordinator; |
| 49 | import org.onosproject.net.intent.IntentInstaller; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 50 | import org.onosproject.net.intent.IntentListener; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 51 | import org.onosproject.net.intent.IntentOperationContext; |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 52 | import org.onosproject.net.intent.IntentService; |
| 53 | import org.onosproject.net.intent.IntentState; |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 54 | import org.onosproject.net.intent.Key; |
Yi Tseng | 24d9be7 | 2017-05-12 11:28:13 -0700 | [diff] [blame] | 55 | import org.onosproject.net.intent.ObjectiveTrackerService; |
Ray Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame^] | 56 | import org.onosproject.net.intent.PathIntent; |
Yi Tseng | 24d9be7 | 2017-05-12 11:28:13 -0700 | [diff] [blame] | 57 | import org.onosproject.net.intent.TopologyChangeDelegate; |
Thomas Vachuska | c97aa61 | 2015-06-23 16:00:18 -0700 | [diff] [blame] | 58 | import org.onosproject.store.trivial.SimpleIntentStore; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 59 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 60 | import java.util.Collection; |
| 61 | import java.util.Collections; |
| 62 | import java.util.List; |
| 63 | import java.util.Map; |
| 64 | import java.util.Set; |
| 65 | import java.util.concurrent.CountDownLatch; |
| 66 | import java.util.concurrent.TimeUnit; |
| 67 | import java.util.stream.Collectors; |
| 68 | import java.util.stream.IntStream; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 69 | |
Sho SHIMIZU | d5bf106 | 2016-02-25 10:26:02 -0800 | [diff] [blame] | 70 | import static org.easymock.EasyMock.mock; |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 71 | import static org.hamcrest.MatcherAssert.assertThat; |
| 72 | import static org.hamcrest.Matchers.hasSize; |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 73 | import static org.hamcrest.Matchers.is; |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 74 | import static org.junit.Assert.*; |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 75 | import static org.onlab.junit.TestTools.assertAfter; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 76 | import static org.onlab.util.Tools.delay; |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 77 | import static org.onosproject.net.NetTestTools.injectEventDispatcher; |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 78 | import static org.onosproject.net.intent.IntentState.*; |
Ray Milkey | 43a2822 | 2015-02-23 13:57:58 -0800 | [diff] [blame] | 79 | import static org.onosproject.net.intent.IntentTestsMocks.MockFlowRule; |
| 80 | import static org.onosproject.net.intent.IntentTestsMocks.MockIntent; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * Test intent manager and transitions. |
| 84 | * |
| 85 | * TODO implement the following tests: |
| 86 | * - {submit, withdraw, update, replace} intent |
Sho SHIMIZU | 3466096 | 2015-01-22 17:58:44 -0800 | [diff] [blame] | 87 | * - {submit, update, recompiling} intent with failed compilation |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 88 | * - failed reservation |
| 89 | * - push timeout recovery |
| 90 | * - failed items recovery |
| 91 | * |
| 92 | * in general, verify intents store, flow store, and work queue |
| 93 | */ |
Ray Milkey | 1c166dc | 2015-03-02 13:32:39 -0800 | [diff] [blame] | 94 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 95 | public class IntentManagerTest { |
| 96 | |
Pavlin Radoslavov | 35b4ecb | 2015-03-03 15:06:04 -0800 | [diff] [blame] | 97 | private static final int SUBMIT_TIMEOUT_MS = 1000; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 98 | private static final ApplicationId APPID = new TestApplicationId("manager-test"); |
| 99 | |
| 100 | private IntentManager manager; |
| 101 | private MockFlowRuleService flowRuleService; |
| 102 | |
| 103 | protected IntentService service; |
| 104 | protected IntentExtensionService extensionService; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 105 | protected IntentInstallCoordinator intentInstallCoordinator; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 106 | protected TestListener listener = new TestListener(); |
| 107 | protected TestIntentCompiler compiler = new TestIntentCompiler(); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 108 | protected TestIntentInstaller installer; |
| 109 | protected TestIntentTracker trackerService = new TestIntentTracker(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 110 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 111 | private static class TestListener implements IntentListener { |
| 112 | final Multimap<IntentEvent.Type, IntentEvent> events = HashMultimap.create(); |
| 113 | Map<IntentEvent.Type, CountDownLatch> latchMap = Maps.newHashMap(); |
| 114 | |
| 115 | @Override |
| 116 | public void event(IntentEvent event) { |
| 117 | events.put(event.type(), event); |
| 118 | if (latchMap.containsKey(event.type())) { |
| 119 | latchMap.get(event.type()).countDown(); |
| 120 | } |
| 121 | } |
| 122 | |
| 123 | public int getCounts(IntentEvent.Type type) { |
| 124 | return events.get(type).size(); |
| 125 | } |
| 126 | |
| 127 | public void setLatch(int count, IntentEvent.Type type) { |
| 128 | latchMap.put(type, new CountDownLatch(count)); |
| 129 | } |
| 130 | |
| 131 | public void await(IntentEvent.Type type) { |
| 132 | try { |
| 133 | assertTrue("Timed out waiting for: " + type, |
| 134 | latchMap.get(type).await(5, TimeUnit.SECONDS)); |
| 135 | } catch (InterruptedException e) { |
| 136 | e.printStackTrace(); |
| 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | private static class TestIntentTracker implements ObjectiveTrackerService { |
| 142 | private TopologyChangeDelegate delegate; |
| 143 | @Override |
| 144 | public void setDelegate(TopologyChangeDelegate delegate) { |
| 145 | this.delegate = delegate; |
| 146 | } |
| 147 | |
| 148 | @Override |
| 149 | public void unsetDelegate(TopologyChangeDelegate delegate) { |
| 150 | if (delegate.equals(this.delegate)) { |
| 151 | this.delegate = null; |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 156 | public void addTrackedResources(Key key, Collection<NetworkResource> resources) { |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 157 | //TODO |
| 158 | } |
| 159 | |
| 160 | @Override |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 161 | public void removeTrackedResources(Key key, Collection<NetworkResource> resources) { |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 162 | //TODO |
| 163 | } |
Thomas Vachuska | c46af20 | 2015-06-03 16:43:27 -0700 | [diff] [blame] | 164 | |
| 165 | @Override |
| 166 | public void trackIntent(IntentData intentData) { |
| 167 | //TODO |
| 168 | } |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 169 | } |
| 170 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 171 | private static class MockInstallableIntent extends FlowRuleIntent { |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 172 | |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 173 | public MockInstallableIntent() { |
Ray Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame^] | 174 | super(APPID, null, Collections.singletonList(new MockFlowRule(100)), Collections.emptyList(), |
| 175 | PathIntent.ProtectionType.PRIMARY, null); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 176 | } |
| 177 | } |
| 178 | |
| 179 | private static class TestIntentCompiler implements IntentCompiler<MockIntent> { |
| 180 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 181 | public List<Intent> compile(MockIntent intent, List<Intent> installable) { |
Sho SHIMIZU | ee2aa65 | 2015-02-25 18:56:43 -0800 | [diff] [blame] | 182 | return Lists.newArrayList(new MockInstallableIntent()); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 186 | private static class TestIntentCompilerMultipleFlows implements IntentCompiler<MockIntent> { |
| 187 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 188 | public List<Intent> compile(MockIntent intent, List<Intent> installable) { |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 189 | |
| 190 | return IntStream.rangeClosed(1, 5) |
| 191 | .mapToObj(mock -> (new MockInstallableIntent())) |
| 192 | .collect(Collectors.toList()); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 197 | private static class TestIntentCompilerError implements IntentCompiler<MockIntent> { |
| 198 | @Override |
Sho SHIMIZU | ec07ffd | 2016-02-22 20:45:21 -0800 | [diff] [blame] | 199 | public List<Intent> compile(MockIntent intent, List<Intent> installable) { |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 200 | throw new IntentCompilationException("Compilation always fails"); |
| 201 | } |
| 202 | } |
| 203 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 204 | /** |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 205 | * Hamcrest matcher to check that a collection of Intents contains an |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 206 | * Intent with the specified Intent Id. |
| 207 | */ |
| 208 | public static class EntryForIntentMatcher extends TypeSafeMatcher<Collection<Intent>> { |
| 209 | private final IntentId id; |
| 210 | |
| 211 | public EntryForIntentMatcher(IntentId idValue) { |
| 212 | id = idValue; |
| 213 | } |
| 214 | |
| 215 | @Override |
| 216 | public boolean matchesSafely(Collection<Intent> intents) { |
| 217 | for (Intent intent : intents) { |
| 218 | if (intent.id().equals(id)) { |
| 219 | return true; |
| 220 | } |
| 221 | } |
| 222 | return false; |
| 223 | } |
| 224 | |
| 225 | @Override |
| 226 | public void describeTo(Description description) { |
| 227 | description.appendText("an intent with id \" "). |
| 228 | appendText(id.toString()). |
| 229 | appendText("\""); |
| 230 | } |
| 231 | } |
| 232 | |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 233 | public static class TestIntentInstaller implements IntentInstaller<MockInstallableIntent> { |
| 234 | |
| 235 | protected IntentExtensionService intentExtensionService; |
| 236 | protected ObjectiveTrackerService trackerService; |
| 237 | protected IntentInstallCoordinator intentInstallCoordinator; |
| 238 | protected FlowRuleService flowRuleService; |
| 239 | |
| 240 | public TestIntentInstaller(IntentExtensionService intentExtensionService, |
| 241 | ObjectiveTrackerService trackerService, |
| 242 | IntentInstallCoordinator intentInstallCoordinator, |
| 243 | FlowRuleService flowRuleService) { |
| 244 | this.intentExtensionService = intentExtensionService; |
| 245 | this.trackerService = trackerService; |
| 246 | this.intentInstallCoordinator = intentInstallCoordinator; |
| 247 | this.flowRuleService = flowRuleService; |
| 248 | } |
| 249 | |
| 250 | @Override |
| 251 | public void apply(IntentOperationContext<MockInstallableIntent> context) { |
| 252 | List<MockInstallableIntent> uninstallIntents = context.intentsToUninstall(); |
| 253 | List<MockInstallableIntent> installIntents = context.intentsToInstall(); |
| 254 | |
| 255 | FlowRuleOperations.Builder builder = FlowRuleOperations.builder(); |
| 256 | |
| 257 | uninstallIntents.stream() |
| 258 | .map(FlowRuleIntent::flowRules) |
| 259 | .flatMap(Collection::stream) |
| 260 | .forEach(builder::remove); |
| 261 | |
| 262 | installIntents.stream() |
| 263 | .map(FlowRuleIntent::flowRules) |
| 264 | .flatMap(Collection::stream) |
| 265 | .forEach(builder::add); |
| 266 | |
| 267 | FlowRuleOperationsContext ctx = new FlowRuleOperationsContext() { |
| 268 | @Override |
| 269 | public void onSuccess(FlowRuleOperations ops) { |
| 270 | intentInstallCoordinator.intentInstallSuccess(context); |
| 271 | } |
| 272 | |
| 273 | @Override |
| 274 | public void onError(FlowRuleOperations ops) { |
| 275 | intentInstallCoordinator.intentInstallFailed(context); |
| 276 | } |
| 277 | }; |
| 278 | |
| 279 | flowRuleService.apply(builder.build(ctx)); |
| 280 | } |
| 281 | } |
| 282 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 283 | private static EntryForIntentMatcher hasIntentWithId(IntentId id) { |
| 284 | return new EntryForIntentMatcher(id); |
| 285 | } |
| 286 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 287 | @Before |
| 288 | public void setUp() { |
| 289 | manager = new IntentManager(); |
| 290 | flowRuleService = new MockFlowRuleService(); |
| 291 | manager.store = new SimpleIntentStore(); |
Thomas Vachuska | 42e8cce | 2015-07-29 19:25:18 -0700 | [diff] [blame] | 292 | injectEventDispatcher(manager, new TestEventDispatcher()); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 293 | manager.trackerService = trackerService; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 294 | manager.flowRuleService = flowRuleService; |
Brian O'Connor | 520c052 | 2014-11-23 23:50:47 -0800 | [diff] [blame] | 295 | manager.coreService = new TestCoreManager(); |
Sho SHIMIZU | d5bf106 | 2016-02-25 10:26:02 -0800 | [diff] [blame] | 296 | manager.configService = mock(ComponentConfigService.class); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 297 | service = manager; |
| 298 | extensionService = manager; |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 299 | intentInstallCoordinator = manager; |
| 300 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 301 | |
| 302 | manager.activate(); |
| 303 | service.addListener(listener); |
| 304 | extensionService.registerCompiler(MockIntent.class, compiler); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 305 | |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 306 | installer = new TestIntentInstaller(extensionService, trackerService, |
| 307 | intentInstallCoordinator, flowRuleService); |
| 308 | |
| 309 | extensionService.registerInstaller(MockInstallableIntent.class, installer); |
| 310 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 311 | assertTrue("store should be empty", |
| 312 | Sets.newHashSet(service.getIntents()).isEmpty()); |
| 313 | assertEquals(0L, flowRuleService.getFlowRuleCount()); |
| 314 | } |
| 315 | |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 316 | public void verifyState() { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 317 | // verify that all intents are parked and the batch operation is unblocked |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 318 | Set<IntentState> parked = Sets.newHashSet(INSTALLED, WITHDRAWN, FAILED, CORRUPT); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 319 | for (Intent i : service.getIntents()) { |
Ray Milkey | f9af43c | 2015-02-09 16:45:48 -0800 | [diff] [blame] | 320 | IntentState state = service.getIntentState(i.key()); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 321 | assertTrue("Intent " + i.id() + " is in invalid state " + state, |
| 322 | parked.contains(state)); |
| 323 | } |
| 324 | //the batch has not yet been removed when we receive the last event |
| 325 | // FIXME: this doesn't guarantee to avoid the race |
Brian O'Connor | b499b35 | 2015-02-03 16:46:15 -0800 | [diff] [blame] | 326 | |
| 327 | //FIXME |
| 328 | // for (int tries = 0; tries < 10; tries++) { |
| 329 | // if (manager.batchService.getPendingOperations().isEmpty()) { |
| 330 | // break; |
| 331 | // } |
| 332 | // delay(10); |
| 333 | // } |
| 334 | // assertTrue("There are still pending batch operations.", |
| 335 | // manager.batchService.getPendingOperations().isEmpty()); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 336 | |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | @After |
| 340 | public void tearDown() { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 341 | extensionService.unregisterCompiler(MockIntent.class); |
Yi Tseng | c927a06 | 2017-05-02 15:02:37 -0700 | [diff] [blame] | 342 | extensionService.unregisterInstaller(MockInstallableIntent.class); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 343 | service.removeListener(listener); |
| 344 | manager.deactivate(); |
| 345 | // TODO null the other refs? |
| 346 | } |
| 347 | |
| 348 | @Test |
| 349 | public void submitIntent() { |
| 350 | flowRuleService.setFuture(true); |
| 351 | |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 352 | listener.setLatch(1, Type.INSTALL_REQ); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 353 | listener.setLatch(1, Type.INSTALLED); |
| 354 | Intent intent = new MockIntent(MockIntent.nextId()); |
| 355 | service.submit(intent); |
Brian O'Connor | 7a71d5d | 2014-12-02 00:12:27 -0800 | [diff] [blame] | 356 | listener.await(Type.INSTALL_REQ); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 357 | listener.await(Type.INSTALLED); |
| 358 | assertEquals(1L, service.getIntentCount()); |
| 359 | assertEquals(1L, flowRuleService.getFlowRuleCount()); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 360 | verifyState(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | @Test |
| 364 | public void withdrawIntent() { |
| 365 | flowRuleService.setFuture(true); |
| 366 | |
| 367 | listener.setLatch(1, Type.INSTALLED); |
| 368 | Intent intent = new MockIntent(MockIntent.nextId()); |
| 369 | service.submit(intent); |
| 370 | listener.await(Type.INSTALLED); |
| 371 | assertEquals(1L, service.getIntentCount()); |
| 372 | assertEquals(1L, flowRuleService.getFlowRuleCount()); |
| 373 | |
| 374 | listener.setLatch(1, Type.WITHDRAWN); |
| 375 | service.withdraw(intent); |
| 376 | listener.await(Type.WITHDRAWN); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 377 | assertEquals(0L, flowRuleService.getFlowRuleCount()); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 378 | verifyState(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | @Test |
Ray Milkey | 0811bdd | 2015-03-11 10:21:55 -0700 | [diff] [blame] | 382 | @Ignore("This is disabled because we are seeing intermittent failures on Jenkins") |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 383 | public void stressSubmitWithdrawUnique() { |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 384 | flowRuleService.setFuture(true); |
| 385 | |
| 386 | int count = 500; |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 387 | Intent[] intents = new Intent[count]; |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 388 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 389 | listener.setLatch(count, Type.WITHDRAWN); |
| 390 | |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 391 | for (int i = 0; i < count; i++) { |
| 392 | intents[i] = new MockIntent(MockIntent.nextId()); |
| 393 | service.submit(intents[i]); |
| 394 | } |
| 395 | |
| 396 | for (int i = 0; i < count; i++) { |
| 397 | service.withdraw(intents[i]); |
| 398 | } |
| 399 | |
| 400 | listener.await(Type.WITHDRAWN); |
| 401 | assertEquals(0L, flowRuleService.getFlowRuleCount()); |
| 402 | verifyState(); |
| 403 | } |
| 404 | |
| 405 | @Test |
| 406 | public void stressSubmitWithdrawSame() { |
| 407 | flowRuleService.setFuture(true); |
| 408 | |
| 409 | int count = 50; |
| 410 | |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 411 | Intent intent = new MockIntent(MockIntent.nextId()); |
| 412 | for (int i = 0; i < count; i++) { |
| 413 | service.submit(intent); |
| 414 | service.withdraw(intent); |
| 415 | } |
| 416 | |
Pavlin Radoslavov | 35b4ecb | 2015-03-03 15:06:04 -0800 | [diff] [blame] | 417 | assertAfter(SUBMIT_TIMEOUT_MS, () -> { |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 418 | assertEquals(1L, service.getIntentCount()); |
| 419 | assertEquals(0L, flowRuleService.getFlowRuleCount()); |
| 420 | }); |
| 421 | verifyState(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 422 | } |
| 423 | |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 424 | |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 425 | /** |
| 426 | * Tests for proper behavior of installation of an intent that triggers |
| 427 | * a compilation error. |
| 428 | */ |
| 429 | @Test |
| 430 | public void errorIntentCompile() { |
| 431 | final TestIntentCompilerError errorCompiler = new TestIntentCompilerError(); |
| 432 | extensionService.registerCompiler(MockIntent.class, errorCompiler); |
| 433 | MockIntent intent = new MockIntent(MockIntent.nextId()); |
| 434 | listener.setLatch(1, Type.INSTALL_REQ); |
| 435 | listener.setLatch(1, Type.FAILED); |
| 436 | service.submit(intent); |
| 437 | listener.await(Type.INSTALL_REQ); |
| 438 | listener.await(Type.FAILED); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 439 | verifyState(); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 440 | } |
| 441 | |
| 442 | /** |
| 443 | * Tests handling a future that contains an error as a result of |
| 444 | * installing an intent. |
| 445 | */ |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 446 | @Ignore("skipping until we fix update ordering problem") |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 447 | @Test |
| 448 | public void errorIntentInstallFromFlows() { |
| 449 | final Long id = MockIntent.nextId(); |
Brian O'Connor | 5811ac2 | 2015-02-09 19:17:07 -0800 | [diff] [blame] | 450 | flowRuleService.setFuture(false); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 451 | MockIntent intent = new MockIntent(id); |
| 452 | listener.setLatch(1, Type.FAILED); |
| 453 | listener.setLatch(1, Type.INSTALL_REQ); |
| 454 | service.submit(intent); |
| 455 | listener.await(Type.INSTALL_REQ); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 456 | listener.await(Type.FAILED); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 457 | // FIXME the intent will be moved into INSTALLED immediately which overrides FAILED |
| 458 | // ... the updates come out of order |
| 459 | verifyState(); |
Ray Milkey | 93508c2 | 2014-12-02 11:35:56 -0800 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | /** |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 463 | * Tests handling a future that contains an unresolvable error as a result of |
| 464 | * installing an intent. |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 465 | */ |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 466 | @Test |
| 467 | public void errorIntentInstallNeverTrue() { |
| 468 | final Long id = MockIntent.nextId(); |
Brian O'Connor | 5811ac2 | 2015-02-09 19:17:07 -0800 | [diff] [blame] | 469 | flowRuleService.setFuture(false); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 470 | MockIntent intent = new MockIntent(id); |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 471 | listener.setLatch(1, Type.CORRUPT); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 472 | listener.setLatch(1, Type.INSTALL_REQ); |
| 473 | service.submit(intent); |
| 474 | listener.await(Type.INSTALL_REQ); |
| 475 | // The delay here forces the retry loop in the intent manager to time out |
| 476 | delay(100); |
Brian O'Connor | 5811ac2 | 2015-02-09 19:17:07 -0800 | [diff] [blame] | 477 | flowRuleService.setFuture(false); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 478 | service.withdraw(intent); |
Brian O'Connor | f0c5a05 | 2015-04-27 00:34:53 -0700 | [diff] [blame] | 479 | listener.await(Type.CORRUPT); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 480 | verifyState(); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 481 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 482 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 483 | /** |
| 484 | * Tests that a compiler for a subclass of an intent that already has a |
| 485 | * compiler is automatically added. |
| 486 | */ |
| 487 | @Test |
| 488 | public void intentSubclassCompile() { |
| 489 | class MockIntentSubclass extends MockIntent { |
| 490 | public MockIntentSubclass(Long number) { |
| 491 | super(number); |
| 492 | } |
| 493 | } |
| 494 | flowRuleService.setFuture(true); |
| 495 | |
| 496 | listener.setLatch(1, Type.INSTALL_REQ); |
| 497 | listener.setLatch(1, Type.INSTALLED); |
| 498 | Intent intent = new MockIntentSubclass(MockIntent.nextId()); |
| 499 | service.submit(intent); |
| 500 | listener.await(Type.INSTALL_REQ); |
| 501 | listener.await(Type.INSTALLED); |
| 502 | assertEquals(1L, service.getIntentCount()); |
| 503 | assertEquals(1L, flowRuleService.getFlowRuleCount()); |
| 504 | |
| 505 | final Map<Class<? extends Intent>, IntentCompiler<? extends Intent>> compilers = |
| 506 | extensionService.getCompilers(); |
| 507 | assertEquals(2, compilers.size()); |
| 508 | assertNotNull(compilers.get(MockIntentSubclass.class)); |
| 509 | assertNotNull(compilers.get(MockIntent.class)); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 510 | verifyState(); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 511 | } |
| 512 | |
| 513 | /** |
| 514 | * Tests an intent with no compiler. |
| 515 | */ |
| 516 | @Test |
| 517 | public void intentWithoutCompiler() { |
| 518 | class IntentNoCompiler extends Intent { |
| 519 | IntentNoCompiler() { |
Ray Milkey | ebc5d22 | 2015-03-18 15:45:36 -0700 | [diff] [blame] | 520 | super(APPID, null, Collections.emptyList(), |
Ray Milkey | 39f78b6 | 2018-01-05 15:17:37 -0800 | [diff] [blame^] | 521 | Intent.DEFAULT_INTENT_PRIORITY, null); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 522 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 523 | } |
| 524 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 525 | Intent intent = new IntentNoCompiler(); |
| 526 | listener.setLatch(1, Type.INSTALL_REQ); |
| 527 | listener.setLatch(1, Type.FAILED); |
| 528 | service.submit(intent); |
| 529 | listener.await(Type.INSTALL_REQ); |
| 530 | listener.await(Type.FAILED); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 531 | verifyState(); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 532 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 533 | |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 534 | /** |
| 535 | * Tests an intent with no installer. |
| 536 | */ |
| 537 | @Test |
| 538 | public void intentWithoutInstaller() { |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 539 | MockIntent intent = new MockIntent(MockIntent.nextId()); |
| 540 | listener.setLatch(1, Type.INSTALL_REQ); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 541 | listener.setLatch(1, Type.CORRUPT); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 542 | service.submit(intent); |
| 543 | listener.await(Type.INSTALL_REQ); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 544 | listener.await(Type.CORRUPT); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 545 | verifyState(); |
Ray Milkey | e9a3e22 | 2014-12-03 16:46:06 -0800 | [diff] [blame] | 546 | } |
| 547 | |
| 548 | /** |
| 549 | * Tests that the intent fetching methods are correct. |
| 550 | */ |
| 551 | @Test |
| 552 | public void testIntentFetching() { |
| 553 | List<Intent> intents; |
| 554 | |
| 555 | flowRuleService.setFuture(true); |
| 556 | |
| 557 | intents = Lists.newArrayList(service.getIntents()); |
| 558 | assertThat(intents, hasSize(0)); |
| 559 | |
| 560 | final MockIntent intent1 = new MockIntent(MockIntent.nextId()); |
| 561 | final MockIntent intent2 = new MockIntent(MockIntent.nextId()); |
| 562 | |
| 563 | listener.setLatch(2, Type.INSTALL_REQ); |
| 564 | listener.setLatch(2, Type.INSTALLED); |
| 565 | service.submit(intent1); |
| 566 | service.submit(intent2); |
| 567 | listener.await(Type.INSTALL_REQ); |
| 568 | listener.await(Type.INSTALL_REQ); |
| 569 | listener.await(Type.INSTALLED); |
| 570 | listener.await(Type.INSTALLED); |
| 571 | |
| 572 | intents = Lists.newArrayList(service.getIntents()); |
| 573 | assertThat(intents, hasSize(2)); |
| 574 | |
| 575 | assertThat(intents, hasIntentWithId(intent1.id())); |
| 576 | assertThat(intents, hasIntentWithId(intent2.id())); |
Ray Milkey | 9f74c08 | 2015-02-11 15:40:16 -0800 | [diff] [blame] | 577 | verifyState(); |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 578 | } |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 579 | |
| 580 | /** |
| 581 | * Tests that removing all intents results in no flows remaining. |
| 582 | */ |
| 583 | @Test |
| 584 | public void testFlowRemoval() { |
| 585 | List<Intent> intents; |
| 586 | |
| 587 | flowRuleService.setFuture(true); |
| 588 | |
| 589 | intents = Lists.newArrayList(service.getIntents()); |
| 590 | assertThat(intents, hasSize(0)); |
| 591 | |
| 592 | final MockIntent intent1 = new MockIntent(MockIntent.nextId()); |
| 593 | final MockIntent intent2 = new MockIntent(MockIntent.nextId()); |
| 594 | |
| 595 | listener.setLatch(1, Type.INSTALL_REQ); |
| 596 | listener.setLatch(1, Type.INSTALLED); |
| 597 | |
| 598 | service.submit(intent1); |
| 599 | listener.await(Type.INSTALL_REQ); |
| 600 | listener.await(Type.INSTALLED); |
| 601 | |
| 602 | |
| 603 | listener.setLatch(1, Type.INSTALL_REQ); |
| 604 | listener.setLatch(1, Type.INSTALLED); |
| 605 | |
| 606 | service.submit(intent2); |
| 607 | listener.await(Type.INSTALL_REQ); |
| 608 | listener.await(Type.INSTALLED); |
| 609 | |
| 610 | assertThat(listener.getCounts(Type.INSTALLED), is(2)); |
| 611 | assertThat(flowRuleService.getFlowRuleCount(), is(2)); |
| 612 | |
| 613 | listener.setLatch(1, Type.WITHDRAWN); |
| 614 | service.withdraw(intent1); |
| 615 | listener.await(Type.WITHDRAWN); |
| 616 | |
| 617 | listener.setLatch(1, Type.WITHDRAWN); |
| 618 | service.withdraw(intent2); |
| 619 | listener.await(Type.WITHDRAWN); |
| 620 | |
| 621 | assertThat(listener.getCounts(Type.WITHDRAWN), is(2)); |
| 622 | assertThat(flowRuleService.getFlowRuleCount(), is(0)); |
| 623 | } |
| 624 | |
| 625 | /** |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 626 | * Test failure to install an intent, then succeed on retry via IntentCleanup. |
| 627 | */ |
| 628 | @Test |
| 629 | public void testCorruptCleanup() { |
| 630 | IntentCleanup cleanup = new IntentCleanup(); |
| 631 | cleanup.service = manager; |
| 632 | cleanup.store = manager.store; |
| 633 | cleanup.cfgService = new ComponentConfigAdapter(); |
| 634 | |
| 635 | try { |
| 636 | cleanup.activate(); |
| 637 | |
| 638 | final TestIntentCompilerMultipleFlows errorCompiler = new TestIntentCompilerMultipleFlows(); |
| 639 | extensionService.registerCompiler(MockIntent.class, errorCompiler); |
| 640 | List<Intent> intents; |
| 641 | |
| 642 | flowRuleService.setFuture(false); |
| 643 | |
| 644 | intents = Lists.newArrayList(service.getIntents()); |
| 645 | assertThat(intents, hasSize(0)); |
| 646 | |
| 647 | final MockIntent intent1 = new MockIntent(MockIntent.nextId()); |
| 648 | |
| 649 | listener.setLatch(1, Type.INSTALL_REQ); |
| 650 | listener.setLatch(1, Type.CORRUPT); |
| 651 | listener.setLatch(1, Type.INSTALLED); |
| 652 | |
| 653 | service.submit(intent1); |
| 654 | |
| 655 | listener.await(Type.INSTALL_REQ); |
| 656 | listener.await(Type.CORRUPT); |
| 657 | |
| 658 | flowRuleService.setFuture(true); |
| 659 | |
| 660 | listener.await(Type.INSTALLED); |
| 661 | |
| 662 | assertThat(listener.getCounts(Type.CORRUPT), is(1)); |
| 663 | assertThat(listener.getCounts(Type.INSTALLED), is(1)); |
| 664 | assertEquals(INSTALLED, manager.getIntentState(intent1.key())); |
| 665 | assertThat(flowRuleService.getFlowRuleCount(), is(5)); |
| 666 | } finally { |
| 667 | cleanup.deactivate(); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | /** |
Brian O'Connor | eba4e34 | 2015-04-30 22:50:13 -0700 | [diff] [blame] | 672 | * Test failure to install an intent, and verify retries. |
| 673 | */ |
| 674 | @Test |
| 675 | public void testCorruptRetry() { |
| 676 | IntentCleanup cleanup = new IntentCleanup(); |
| 677 | cleanup.service = manager; |
| 678 | cleanup.store = manager.store; |
| 679 | cleanup.cfgService = new ComponentConfigAdapter(); |
| 680 | cleanup.period = 1_000_000; |
| 681 | cleanup.retryThreshold = 3; |
| 682 | |
| 683 | try { |
| 684 | cleanup.activate(); |
| 685 | |
| 686 | final TestIntentCompilerMultipleFlows errorCompiler = new TestIntentCompilerMultipleFlows(); |
| 687 | extensionService.registerCompiler(MockIntent.class, errorCompiler); |
| 688 | List<Intent> intents; |
| 689 | |
| 690 | flowRuleService.setFuture(false); |
| 691 | |
| 692 | intents = Lists.newArrayList(service.getIntents()); |
| 693 | assertThat(intents, hasSize(0)); |
| 694 | |
| 695 | final MockIntent intent1 = new MockIntent(MockIntent.nextId()); |
| 696 | |
| 697 | listener.setLatch(1, Type.INSTALL_REQ); |
| 698 | listener.setLatch(cleanup.retryThreshold, Type.CORRUPT); |
| 699 | listener.setLatch(1, Type.INSTALLED); |
| 700 | |
| 701 | service.submit(intent1); |
| 702 | |
| 703 | listener.await(Type.INSTALL_REQ); |
| 704 | listener.await(Type.CORRUPT); |
| 705 | assertEquals(CORRUPT, manager.getIntentState(intent1.key())); |
| 706 | assertThat(listener.getCounts(Type.CORRUPT), is(cleanup.retryThreshold)); |
| 707 | |
| 708 | } finally { |
| 709 | cleanup.deactivate(); |
| 710 | } |
| 711 | } |
| 712 | |
| 713 | /** |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 714 | * Tests that an intent that fails installation results in no flows remaining. |
| 715 | */ |
| 716 | @Test |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 717 | @Ignore("MockFlowRule numbering issue") //test works if run independently |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 718 | public void testFlowRemovalInstallError() { |
| 719 | final TestIntentCompilerMultipleFlows errorCompiler = new TestIntentCompilerMultipleFlows(); |
| 720 | extensionService.registerCompiler(MockIntent.class, errorCompiler); |
| 721 | List<Intent> intents; |
| 722 | |
| 723 | flowRuleService.setFuture(true); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 724 | //FIXME relying on "3" is brittle |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 725 | flowRuleService.setErrorFlow(3); |
| 726 | |
| 727 | intents = Lists.newArrayList(service.getIntents()); |
| 728 | assertThat(intents, hasSize(0)); |
| 729 | |
| 730 | final MockIntent intent1 = new MockIntent(MockIntent.nextId()); |
| 731 | |
| 732 | listener.setLatch(1, Type.INSTALL_REQ); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 733 | listener.setLatch(1, Type.CORRUPT); |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 734 | |
| 735 | service.submit(intent1); |
| 736 | listener.await(Type.INSTALL_REQ); |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 737 | listener.await(Type.CORRUPT); |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 738 | |
Brian O'Connor | 3c58e96 | 2015-04-28 23:21:51 -0700 | [diff] [blame] | 739 | assertThat(listener.getCounts(Type.CORRUPT), is(1)); |
| 740 | // in this test, there will still be flows abandoned on the data plane |
| 741 | //assertThat(flowRuleService.getFlowRuleCount(), is(0)); |
Ray Milkey | 77a455f | 2015-03-27 10:08:17 -0700 | [diff] [blame] | 742 | } |
Brian O'Connor | 427a176 | 2014-11-19 18:40:32 -0800 | [diff] [blame] | 743 | } |