Search in sources :

Example 26 with MockIntent

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

the class IntentCleanupTestMock method corruptEventThreshold.

/**
 * Intent should not be retried because threshold is reached.
 */
@Test
public void corruptEventThreshold() {
    IntentStoreDelegate mockDelegate = new IntentStoreDelegate() {

        @Override
        public void process(IntentData intentData) {
            intentData.setState(CORRUPT);
            intentData.setErrorCount(cleanup.retryThreshold);
            store.write(intentData);
        }

        @Override
        public void notify(IntentEvent event) {
            cleanup.event(event);
        }
    };
    store.setDelegate(mockDelegate);
    Intent intent = new MockIntent(1L);
    IntentData data = new IntentData(intent, INSTALL_REQ, null);
    replay(service);
    store.addPending(data);
    verify(service);
    reset(service);
}
Also used : IntentStoreDelegate(org.onosproject.net.intent.IntentStoreDelegate) IntentData(org.onosproject.net.intent.IntentData) Intent(org.onosproject.net.intent.Intent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) IntentEvent(org.onosproject.net.intent.IntentEvent) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 27 with MockIntent

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

the class IntentManagerTest method testFlowRemoval.

/**
 * Tests that removing all intents results in no flows remaining.
 */
@Test
public void testFlowRemoval() {
    List<Intent> intents;
    flowRuleService.setFuture(true);
    intents = Lists.newArrayList(service.getIntents());
    assertThat(intents, hasSize(0));
    final MockIntent intent1 = new MockIntent(MockIntent.nextId());
    final MockIntent intent2 = new MockIntent(MockIntent.nextId());
    listener.setLatch(1, Type.INSTALL_REQ);
    listener.setLatch(1, Type.INSTALLED);
    service.submit(intent1);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.INSTALLED);
    listener.setLatch(1, Type.INSTALL_REQ);
    listener.setLatch(1, Type.INSTALLED);
    service.submit(intent2);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.INSTALLED);
    assertThat(listener.getCounts(Type.INSTALLED), is(2));
    assertThat(flowRuleService.getFlowRuleCount(), is(2));
    listener.setLatch(1, Type.WITHDRAWN);
    service.withdraw(intent1);
    listener.await(Type.WITHDRAWN);
    listener.setLatch(1, Type.WITHDRAWN);
    service.withdraw(intent2);
    listener.await(Type.WITHDRAWN);
    assertThat(listener.getCounts(Type.WITHDRAWN), is(2));
    assertThat(flowRuleService.getFlowRuleCount(), is(0));
}
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 28 with MockIntent

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

the class IntentManagerTest method stressSubmitWithdrawSame.

@Test
public void stressSubmitWithdrawSame() {
    flowRuleService.setFuture(true);
    int count = 50;
    Intent intent = new MockIntent(MockIntent.nextId());
    for (int i = 0; i < count; i++) {
        service.submit(intent);
        service.withdraw(intent);
    }
    assertAfter(SUBMIT_TIMEOUT_MS, () -> {
        assertEquals(1L, service.getIntentCount());
        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)

Example 29 with MockIntent

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

the class IntentManagerTest method intentWithoutInstaller.

/**
 * Tests an intent with no installer.
 */
@Test
public void intentWithoutInstaller() {
    MockIntent intent = new MockIntent(MockIntent.nextId());
    listener.setLatch(1, Type.INSTALL_REQ);
    listener.setLatch(1, Type.CORRUPT);
    service.submit(intent);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.CORRUPT);
    verifyState();
}
Also used : MockIntent(org.onosproject.net.intent.IntentTestsMocks.MockIntent) Test(org.junit.Test)

Example 30 with MockIntent

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

the class IntentManagerTest method testFlowRemovalInstallError.

/**
 * Tests that an intent that fails installation results in no flows remaining.
 */
@Test
// test works if run independently
@Ignore("MockFlowRule numbering issue")
public void testFlowRemovalInstallError() {
    final TestIntentCompilerMultipleFlows errorCompiler = new TestIntentCompilerMultipleFlows();
    extensionService.registerCompiler(MockIntent.class, errorCompiler);
    List<Intent> intents;
    flowRuleService.setFuture(true);
    // FIXME relying on "3" is brittle
    flowRuleService.setErrorFlow(3);
    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);
    service.submit(intent1);
    listener.await(Type.INSTALL_REQ);
    listener.await(Type.CORRUPT);
    assertThat(listener.getCounts(Type.CORRUPT), is(1));
// in this test, there will still be flows abandoned on the data plane
// assertThat(flowRuleService.getFlowRuleCount(), is(0));
}
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)

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