[SDFAB-359] Allow purging flows, groups and meters by device and application ID
Change-Id: I5e507d230789979ac997dbc99697fa0483363f70
diff --git a/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java
index 4cddf54..0527755 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/meter/impl/DistributedMeterStoreTest.java
@@ -54,6 +54,7 @@
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.*;
import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.APP_ID_2;
import static org.onosproject.net.NetTestTools.did;
/**
@@ -79,6 +80,7 @@
// Meter ids used during the tests
private MeterId mid1 = MeterId.meterId(1);
private MeterId mid2 = MeterId.meterId(2);
+ private MeterId mid3 = MeterId.meterId(3);
private MeterId mid10 = MeterId.meterId(10);
// Bands used during the tests
@@ -96,6 +98,22 @@
.withBands(Collections.singletonList(b1))
.build();
+ private Meter m2 = DefaultMeter.builder()
+ .forDevice(did1)
+ .fromApp(APP_ID_2)
+ .withCellId(mid2)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+
+ private Meter m3 = DefaultMeter.builder()
+ .forDevice(did2)
+ .fromApp(APP_ID_2)
+ .withCellId(mid3)
+ .withUnit(Meter.Unit.KB_PER_SEC)
+ .withBands(Collections.singletonList(b1))
+ .build();
+
// Meter features used during the tests
private MeterFeatures mef1 = DefaultMeterFeatures.builder().forDevice(did1)
.withMaxMeters(3L)
@@ -417,6 +435,31 @@
}
/**
+ * Test purge meter given device and application.
+ */
+ @Test
+ public void testPurgeMeterDeviceAndApp() {
+ // Init the store
+ initMeterStore();
+ // add the meters
+ ((DefaultMeter) m1).setState(MeterState.PENDING_ADD);
+ ((DefaultMeter) m2).setState(MeterState.PENDING_ADD);
+ ((DefaultMeter) m3).setState(MeterState.PENDING_ADD);
+ meterStore.storeMeter(m1);
+ meterStore.storeMeter(m2);
+ meterStore.storeMeter(m3);
+ assertThat(3, is(meterStore.getAllMeters().size()));
+
+ meterStore.purgeMeters(did1, APP_ID_2);
+ // Verify delete
+ MeterKey keyTwo = MeterKey.key(did1, mid2);
+ assertThat(2, is(meterStore.getAllMeters().size()));
+ assertThat(1, is(meterStore.getAllMeters(did1).size()));
+ assertThat(1, is(meterStore.getAllMeters(did2).size()));
+ assertNull(meterStore.getMeter(keyTwo));
+ }
+
+ /**
* Test getMeters API immutability.
*/
@Test