use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentManagerTest method testCorruptRetry.
/**
* Test failure to install an intent, and verify retries.
*/
@Test
public void testCorruptRetry() {
IntentCleanup cleanup = new IntentCleanup();
cleanup.service = manager;
cleanup.store = manager.store;
cleanup.cfgService = new ComponentConfigAdapter();
cleanup.period = 1_000_000;
cleanup.retryThreshold = 3;
try {
cleanup.activate();
final TestIntentCompilerMultipleFlows errorCompiler = new TestIntentCompilerMultipleFlows();
extensionService.registerCompiler(MockIntent.class, errorCompiler);
List<Intent> intents;
flowRuleService.setFuture(false);
intents = Lists.newArrayList(service.getIntents());
assertThat(intents, hasSize(0));
final MockIntent intent1 = new MockIntent(MockIntent.nextId());
listener.setLatch(1, Type.INSTALL_REQ);
listener.setLatch(cleanup.retryThreshold, Type.CORRUPT);
listener.setLatch(1, Type.INSTALLED);
service.submit(intent1);
listener.await(Type.INSTALL_REQ);
listener.await(Type.CORRUPT);
assertEquals(CORRUPT, manager.getIntentState(intent1.key()));
assertThat(listener.getCounts(Type.CORRUPT), is(cleanup.retryThreshold));
} finally {
cleanup.deactivate();
}
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentDataTest method setUp.
@Override
@Before
public void setUp() {
super.setUp();
timestamp1 = new MockTimestamp(1);
timestamp2 = new MockTimestamp(2);
timestamp3 = new MockTimestamp(3);
intent1 = new MockIntent(1L);
intent2 = new MockIntent(2L);
intent3 = new MockIntent(3L);
data1 = new IntentData(intent1, IntentState.INSTALLED, timestamp1);
data1Copy = new IntentData(intent1, IntentState.INSTALLED, timestamp1);
data2 = new IntentData(intent2, IntentState.INSTALLED, timestamp2);
data2Copy = new IntentData(intent2, IntentState.INSTALLED, timestamp2);
data3 = new IntentData(intent3, IntentState.INSTALLED, timestamp3);
data3Copy = new IntentData(intent3, IntentState.INSTALLED, timestamp3);
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testIntentsArray.
/**
* Tests the result of the rest api GET when intents are defined.
*/
@Test
public void testIntentsArray() {
replay(mockIntentService);
final Intent intent1 = new MockIntent(1L, Collections.emptyList());
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent2 = new MockIntent(2L, resources);
intents.add(intent1);
intents.add(intent2);
final WebTarget wt = target();
final String response = wt.path("intents").request().get(String.class);
assertThat(response, containsString("{\"intents\":["));
final JsonObject result = Json.parse(response).asObject();
assertThat(result, notNullValue());
assertThat(result.names(), hasSize(1));
assertThat(result.names().get(0), is("intents"));
final JsonArray jsonIntents = result.get("intents").asArray();
assertThat(jsonIntents, notNullValue());
assertThat(jsonIntents, hasIntent(intent1, false));
assertThat(jsonIntents, hasIntent(intent2, false));
}
use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.
the class IntentsResourceTest method testRemove.
/**
* Tests removing an intent with DELETE.
*/
@Test
public void testRemove() {
final HashSet<NetworkResource> resources = new HashSet<>();
resources.add(new MockResource(1));
resources.add(new MockResource(2));
resources.add(new MockResource(3));
final Intent intent = new MockIntent(3L, resources);
final ApplicationId appId = new DefaultApplicationId(2, "app");
IntentService fakeManager = new FakeIntentManager();
expect(mockCoreService.getAppId("app")).andReturn(appId).once();
replay(mockCoreService);
mockIntentService.withdraw(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
expect(mockIntentService.getIntent(Key.of(2, appId))).andReturn(intent).once();
expect(mockIntentService.getIntent(Key.of("0x2", appId))).andReturn(null).once();
mockIntentService.addListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
mockIntentService.removeListener(anyObject());
expectLastCall().andDelegateTo(fakeManager).once();
replay(mockIntentService);
WebTarget wt = target();
Response response = wt.path("intents/app/0x2").request(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN).delete();
assertThat(response.getStatus(), is(HttpURLConnection.HTTP_NO_CONTENT));
}
Aggregations