Search in sources :

Example 6 with MockIntent

use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.

the class IntentManagerTest method testIntentFetching.

/**
 * Tests that the intent fetching methods are correct.
 */
@Test
public void testIntentFetching() {
    List<Intent> intents;
    flowRuleService.setFuture(true);
    intents = Lists.newArrayList(service.getIntents());
    assertThat(intents, hasSize(0));
    final MockIntent intent1 = new MockIntent(MockIntent.nextId(), NetTestTools.APP_ID);
    final MockIntent intent2 = new MockIntent(MockIntent.nextId(), NetTestTools.APP_ID_2);
    listener.setLatch(2, Type.INSTALL_REQ);
    listener.setLatch(2, Type.INSTALLED);
    service.submit(intent1);
    service.submit(intent2);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.INSTALLED);
    listener.await(Type.INSTALLED);
    intents = Lists.newArrayList(service.getIntents());
    assertThat(intents, hasSize(2));
    assertThat(intents, hasIntentWithId(intent1.id()));
    assertThat(intents, hasIntentWithId(intent2.id()));
    verifyState();
    List<Intent> intentsAppId = Lists.newArrayList(service.getIntentsByAppId(NetTestTools.APP_ID));
    assertThat(intentsAppId, hasSize(1));
    assertThat(intentsAppId, hasIntentWithId(intent1.id()));
    List<Intent> intentsAppId2 = Lists.newArrayList(service.getIntentsByAppId(NetTestTools.APP_ID_2));
    assertThat(intentsAppId2, hasSize(1));
    assertThat(intentsAppId2, hasIntentWithId(intent2.id()));
    verifyState();
}
Also used : 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 7 with MockIntent

use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.

the class IntentManagerTest method testCorruptCleanup.

/**
 * Test failure to install an intent, then succeed on retry via IntentCleanup.
 */
@Test
public void testCorruptCleanup() {
    IntentCleanup cleanup = new IntentCleanup();
    cleanup.service = manager;
    cleanup.store = manager.store;
    cleanup.cfgService = new ComponentConfigAdapter();
    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(1, Type.CORRUPT);
        listener.setLatch(1, Type.INSTALLED);
        service.submit(intent1);
        listener.await(Type.INSTALL_REQ);
        listener.await(Type.CORRUPT);
        flowRuleService.setFuture(true);
        listener.await(Type.INSTALLED);
        assertThat(listener.getCounts(Type.CORRUPT), is(1));
        assertThat(listener.getCounts(Type.INSTALLED), is(1));
        assertEquals(INSTALLED, manager.getIntentState(intent1.key()));
        assertThat(flowRuleService.getFlowRuleCount(), is(5));
    } 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 8 with MockIntent

use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.

the class IntentManagerTest method errorIntentInstallNeverTrue.

/**
 * Tests handling a future that contains an unresolvable error as a result of
 * installing an intent.
 */
@Test
public void errorIntentInstallNeverTrue() {
    final Long id = MockIntent.nextId();
    flowRuleService.setFuture(false);
    MockIntent intent = new MockIntent(id);
    listener.setLatch(1, Type.CORRUPT);
    listener.setLatch(1, Type.INSTALL_REQ);
    service.submit(intent);
    listener.await(Type.INSTALL_REQ);
    // The delay here forces the retry loop in the intent manager to time out
    delay(100);
    flowRuleService.setFuture(false);
    service.withdraw(intent);
    listener.await(Type.CORRUPT);
    verifyState();
}
Also used : MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) Test(org.junit.Test)

Example 9 with MockIntent

use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.

the class IntentManagerTest method stressSubmitWithdrawUnique.

@Test
@Ignore("This is disabled because we are seeing intermittent failures on Jenkins")
public void stressSubmitWithdrawUnique() {
    flowRuleService.setFuture(true);
    int count = 500;
    Intent[] intents = new Intent[count];
    listener.setLatch(count, Type.WITHDRAWN);
    for (int i = 0; i < count; i++) {
        intents[i] = new MockIntent(MockIntent.nextId());
        service.submit(intents[i]);
    }
    for (int i = 0; i < count; i++) {
        service.withdraw(intents[i]);
    }
    listener.await(Type.WITHDRAWN);
    assertEquals(0L, flowRuleService.getFlowRuleCount());
    verifyState();
}
Also used : 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) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with MockIntent

use of org.onosproject.net.intent.IntentTestsMocks.MockIntent in project onos by opennetworkinglab.

the class IntentManagerTest method withdrawIntent.

@Test
public void withdrawIntent() {
    flowRuleService.setFuture(true);
    listener.setLatch(1, Type.INSTALLED);
    Intent intent = new MockIntent(MockIntent.nextId());
    service.submit(intent);
    listener.await(Type.INSTALLED);
    assertEquals(1L, service.getIntentCount());
    assertEquals(1L, flowRuleService.getFlowRuleCount());
    listener.setLatch(1, Type.WITHDRAWN);
    service.withdraw(intent);
    listener.await(Type.WITHDRAWN);
    assertEquals(0L, flowRuleService.getFlowRuleCount());
    verifyState();
}
Also used : 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)

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