Search in sources :

Example 31 with MockIntent

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();
    }
}
Also used : ComponentConfigAdapter(org.onosproject.cfg.ComponentConfigAdapter) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) Test(org.junit.Test)

Example 32 with MockIntent

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);
}
Also used : MockTimestamp(org.onosproject.net.intent.IntentTestsMocks.MockTimestamp) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) Before(org.junit.Before)

Example 33 with MockIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) JsonArray(com.eclipsesource.json.JsonArray) JsonObject(com.eclipsesource.json.JsonObject) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 34 with MockIntent

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));
}
Also used : NetworkResource(org.onosproject.net.NetworkResource) Response(javax.ws.rs.core.Response) IntentService(org.onosproject.net.intent.IntentService) FakeIntentManager(org.onosproject.net.intent.FakeIntentManager) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) WebTarget(javax.ws.rs.client.WebTarget) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) ApplicationId(org.onosproject.core.ApplicationId) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) DefaultApplicationId(org.onosproject.core.DefaultApplicationId) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

MockIntent (org.onosproject.net.intent.IntentTestsMocks.MockIntent)34 Test (org.junit.Test)32 Intent (org.onosproject.net.intent.Intent)28 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)16 PathIntent (org.onosproject.net.intent.PathIntent)16 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)12 IntentData (org.onosproject.net.intent.IntentData)12 IntentEvent (org.onosproject.net.intent.IntentEvent)12 IntentStoreDelegate (org.onosproject.net.intent.IntentStoreDelegate)12 Timestamp (org.onosproject.store.Timestamp)8 SystemClockTimestamp (org.onosproject.store.trivial.SystemClockTimestamp)8 WebTarget (javax.ws.rs.client.WebTarget)6 NetworkResource (org.onosproject.net.NetworkResource)6 ConnectivityIntent (org.onosproject.net.intent.ConnectivityIntent)6 HostToHostIntent (org.onosproject.net.intent.HostToHostIntent)6 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)6 JsonObject (com.eclipsesource.json.JsonObject)5 HashSet (java.util.HashSet)5 Ignore (org.junit.Ignore)5 Before (org.junit.Before)2