celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pnol...@apache.org
Subject [celix] branch master updated: Feature/pubsub utils test fix (#256)
Date Thu, 11 Jun 2020 15:59:43 GMT
This is an automated email from the ASF dual-hosted git repository.

pnoltes pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/celix.git


The following commit(s) were added to refs/heads/master by this push:
     new 6c5ea5a  Feature/pubsub utils test fix (#256)
6c5ea5a is described below

commit 6c5ea5ac7254d416a0bae651244012ab03a223b2
Author: Pepijn Noltes <pepijnnoltes@gmail.com>
AuthorDate: Thu Jun 11 17:59:35 2020 +0200

    Feature/pubsub utils test fix (#256)
    
    * Adds "already added check" for pubsub serializerion provider.
---
 .../src/PubSubSerializationProviderTestSuite.cc    |  2 +-
 .../src/pubsub_serialization_provider.c            | 24 ++++++++++++++++++++++
 2 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/bundles/pubsub/pubsub_utils/gtest/src/PubSubSerializationProviderTestSuite.cc
b/bundles/pubsub/pubsub_utils/gtest/src/PubSubSerializationProviderTestSuite.cc
index 2522bbf..db39759 100644
--- a/bundles/pubsub/pubsub_utils/gtest/src/PubSubSerializationProviderTestSuite.cc
+++ b/bundles/pubsub/pubsub_utils/gtest/src/PubSubSerializationProviderTestSuite.cc
@@ -65,7 +65,7 @@ TEST_F(PubSubSerializationProviderTestSuite, FindSerializationServices)
{
     size_t nrEntries = pubsub_serializationProvider_nrOfEntries(provider);
     EXPECT_EQ(5, nrEntries);
     size_t nrOfInvalidEntries = pubsub_serializationProvider_nrOfInvalidEntries(provider);
-    EXPECT_EQ(3, nrOfInvalidEntries); //note 4 invalid, because garbage.descriptor is never
added (cannot extract msgFqn)
+    EXPECT_EQ(3, nrOfInvalidEntries); //note 3 invalid, because garbage.descriptor is never
added (cannot extract msgFqn)
 
     auto* services = celix_bundleContext_findServices(ctx.get(), PUBSUB_MESSAGE_SERIALIZATION_SERVICE_NAME);
     EXPECT_EQ(5, celix_arrayList_size(services)); //3 valid, 5 invalid
diff --git a/bundles/pubsub/pubsub_utils/src/pubsub_serialization_provider.c b/bundles/pubsub/pubsub_utils/src/pubsub_serialization_provider.c
index a0559e4..02902be 100644
--- a/bundles/pubsub/pubsub_utils/src/pubsub_serialization_provider.c
+++ b/bundles/pubsub/pubsub_utils/src/pubsub_serialization_provider.c
@@ -259,6 +259,21 @@ static dyn_message_type* pubsub_serializationProvider_parseDfiDescriptor(pubsub_
 //}
 
 /**
+ * Check if a pubsub serialization entry is already present (exact path)
+ *
+ * @return true if the entry is a already present
+ */
+static bool pubsub_serializationProvider_alreadyAddedEntry(pubsub_serialization_provider_t*
provider, pubsub_serialization_entry_t* entry) {
+    for (int i = 0; i < celix_arrayList_size(provider->serializationSvcEntries); ++i)
{
+        pubsub_serialization_entry_t *visit = celix_arrayList_get(provider->serializationSvcEntries,
i);
+        if (celix_utils_stringEquals(visit->readFromEntryPath, entry->readFromEntryPath))
{
+            return true;
+        }
+    }
+    return false;
+}
+
+/**
  * Validates an pubsub serialization entry and check if this is a new unique entry.
  *
  * Checks whether the entry is valid. Specifically checks:
@@ -407,6 +422,15 @@ static void pubsub_serializationProvider_parseDescriptors(pubsub_serialization_p
         serEntry->svc.freeDeserializedMsg = (void*)provider->freeDeserializeMsg;
         serEntry->svcId = -1L;
 
+        if (pubsub_serializationProvider_alreadyAddedEntry(provider, serEntry)) {
+            L_WARN("Skipping entry %s. Exact entry already present!. Double event triggered?",
serEntry->readFromEntryPath);
+            free(serEntry->descriptorContent);
+            free(serEntry->readFromEntryPath);
+            free(serEntry->msgVersionStr);
+            dynMessage_destroy(serEntry->msgType);
+            free(serEntry);
+            continue;
+        }
 
         bool unique = pubsub_serializationProvider_validateEntry(provider, serEntry);
         if (unique && serEntry->valid) { //note only register if unique and valid


Mime
View raw message