Fix for JIRA ONOS-4620. Whenever networkconfiguration is deleted even the queued will be removed

Change-Id: I8d7f1a873af90cf86ea34f1a2b1585ef4c3e46e4
diff --git a/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java b/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
index 87148a8..7a812c9 100644
--- a/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
+++ b/core/store/dist/src/main/java/org/onosproject/store/config/impl/DistributedNetworkConfigStore.java
@@ -284,6 +284,24 @@
         configs.remove(key(subject, configKey));
     }
 
+    @Override
+    public <S> void clearConfig(S subject) {
+        ImmutableSet.copyOf(configs.keySet()).forEach(k -> {
+            if (Objects.equals(subject, k.subject) && delegate != null) {
+                configs.remove(k);
+            }
+        });
+    }
+
+    @Override
+    public <S> void clearConfig() {
+        ImmutableSet.copyOf(configs.keySet()).forEach(k -> {
+            if (delegate != null) {
+                configs.remove(k);
+            }
+        });
+    }
+
     /**
      * Produces a config from the specified subject, config class and raw JSON.
      *
diff --git a/core/store/dist/src/test/java/org/onosproject/store/config/impl/DistributedNetworkConfigStoreTest.java b/core/store/dist/src/test/java/org/onosproject/store/config/impl/DistributedNetworkConfigStoreTest.java
index 8b32b67..c10e2f2 100644
--- a/core/store/dist/src/test/java/org/onosproject/store/config/impl/DistributedNetworkConfigStoreTest.java
+++ b/core/store/dist/src/test/java/org/onosproject/store/config/impl/DistributedNetworkConfigStoreTest.java
@@ -31,6 +31,9 @@
 import static org.hamcrest.Matchers.nullValue;
 import static org.junit.Assert.assertThat;
 
+import java.util.Set;
+
+
 public class DistributedNetworkConfigStoreTest {
     private DistributedNetworkConfigStore configStore;
 
@@ -203,4 +206,33 @@
         assertThat(configStore.getSubjects(Integer.class, BasicIntConfig.class), hasSize(1));
         assertThat(configStore.getSubjects(Integer.class), hasSize(1));
     }
+
+    /**
+     * Tests  removal of config including queued.
+     */
+    @Test
+    public void testRemoveConfig() {
+
+        configStore.addConfigFactory(new MockConfigFactory(BasicConfig.class, "config1"));
+        configStore.queueConfig("subject", "config2", new ObjectMapper().createObjectNode());
+        configStore.queueConfig(123, "config2", new ObjectMapper().createObjectNode());
+        configStore.applyConfig("subject1", BasicConfig.class, new ObjectMapper().createObjectNode());
+
+        configStore.clearConfig();
+
+        Set<String> subjects = configStore.getSubjects(String.class);
+        assertThat(subjects.size(), is(0));
+
+        configStore.addConfigFactory(new MockConfigFactory(BasicConfig.class, "config1"));
+        configStore.queueConfig("subject", "config3", new ObjectMapper().createObjectNode());
+        configStore.queueConfig(123, "config3", new ObjectMapper().createObjectNode());
+        configStore.applyConfig("subject1", BasicConfig.class, new ObjectMapper().createObjectNode());
+
+        Set<String> configs = configStore.getSubjects(String.class);
+
+        configs.forEach(c -> configStore.clearConfig(c));
+        Set<String> newConfig1 = configStore.getSubjects(String.class);
+
+        assertThat(newConfig1, notNullValue());
+    }
 }