celix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bpe...@apache.org
Subject celix git commit: CELIX-293: add import/export test, minor bugfix
Date Tue, 17 Nov 2015 05:17:19 GMT
Repository: celix
Updated Branches:
  refs/heads/develop 437da02bc -> d2593f233


CELIX-293: add import/export test, minor bugfix


Project: http://git-wip-us.apache.org/repos/asf/celix/repo
Commit: http://git-wip-us.apache.org/repos/asf/celix/commit/d2593f23
Tree: http://git-wip-us.apache.org/repos/asf/celix/tree/d2593f23
Diff: http://git-wip-us.apache.org/repos/asf/celix/diff/d2593f23

Branch: refs/heads/develop
Commit: d2593f233f2f80c5ceace4096bd2631827ee4fee
Parents: 437da02
Author: Bjoern Petri <bpetri@apache.org>
Authored: Tue Nov 17 06:16:37 2015 +0100
Committer: Bjoern Petri <bpetri@apache.org>
Committed: Tue Nov 17 06:16:37 2015 +0100

----------------------------------------------------------------------
 .../discovery/private/src/discovery.c           |   2 +-
 .../discovery_shm/private/src/discovery_impl.c  |   4 +-
 .../private/src/remote_service_admin_impl.c     |   7 +-
 .../private/test/rsa_client_server_tests.cpp    | 368 ++++++++++++++++---
 4 files changed, 325 insertions(+), 56 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/celix/blob/d2593f23/remote_services/discovery/private/src/discovery.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery/private/src/discovery.c b/remote_services/discovery/private/src/discovery.c
index ee3c293..e2415b4 100644
--- a/remote_services/discovery/private/src/discovery.c
+++ b/remote_services/discovery/private/src/discovery.c
@@ -225,7 +225,7 @@ celix_status_t discovery_removeDiscoveredEndpoint(discovery_pt discovery,
endpoi
         status = celixThreadMutex_unlock(&discovery->discoveredServicesMutex);
 
         if (oldValue) {
-            status = discovery_informEndpointListeners(discovery, endpoint, false /* addingService
*/);
+            status = discovery_informEndpointListeners(discovery, endpoint, false /* removeService
*/);
         }
     }
 

http://git-wip-us.apache.org/repos/asf/celix/blob/d2593f23/remote_services/discovery_shm/private/src/discovery_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/discovery_shm/private/src/discovery_impl.c b/remote_services/discovery_shm/private/src/discovery_impl.c
index 2befad3..2604595 100644
--- a/remote_services/discovery_shm/private/src/discovery_impl.c
+++ b/remote_services/discovery_shm/private/src/discovery_impl.c
@@ -134,9 +134,7 @@ celix_status_t discovery_stop(discovery_pt discovery) {
         status = endpointDiscoveryServer_destroy(discovery->server);
     }
 
-	if (status == CELIX_SUCCESS) {
-	    status = endpointDiscoveryPoller_destroy(discovery->poller);
-	}
+	endpointDiscoveryPoller_destroy(discovery->poller);
 
 	if (status == CELIX_SUCCESS) {
         hash_map_iterator_pt iter;

http://git-wip-us.apache.org/repos/asf/celix/blob/d2593f23/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
index 92d4594..c9771b0 100644
--- a/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
+++ b/remote_services/remote_service_admin_shm/private/src/remote_service_admin_impl.c
@@ -838,9 +838,12 @@ celix_status_t remoteServiceAdmin_importService(remote_service_admin_pt
admin, e
 }
 
 celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt admin, import_registration_pt
registration) {
-    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+    celix_status_t status = CELIX_SUCCESS;
 
     if (registration != NULL) {
+
+        celixThreadMutex_lock(&admin->importedServicesLock);
+
         ipc_segment_pt ipc = NULL;
         endpoint_description_pt endpointDescription = (endpoint_description_pt) registration->endpointDescription;
         import_registration_factory_pt registration_factory = (import_registration_factory_pt)
hashMap_get(admin->importedServices, endpointDescription->service);
@@ -871,6 +874,8 @@ celix_status_t remoteServiceAdmin_removeImportedService(remote_service_admin_pt
                 importRegistrationFactory_destroy(&registration_factory);
             }
         }
+
+        celixThreadMutex_unlock(&admin->importedServicesLock);
     }
 
     return status;

http://git-wip-us.apache.org/repos/asf/celix/blob/d2593f23/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
----------------------------------------------------------------------
diff --git a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
index 2ee5c6c..1c10c72 100644
--- a/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
+++ b/remote_services/remote_service_admin_shm/private/test/rsa_client_server_tests.cpp
@@ -35,83 +35,341 @@ extern "C" {
 #include "framework.h"
 #include "remote_service_admin.h"
 #include "calculator_service.h"
+#include "bundle.h"
 
-    static framework_pt serverFramework = NULL;
-    static bundle_context_pt serverContext = NULL;
+#define NUM_OF_BUNDLES          3
+#define DISCOVERY_CFG_NAME      "apache_celix_rsa_discovery_shm"
+#define RSA_HTTP_NAME           "apache_celix_remote_service_admin_shm"
+#define TOPOLOGY_MANAGER_NAME   "apache_celix_rs_topology_manager"
 
-    static framework_pt clientFramework = NULL;
-    static bundle_context_pt clientContext = NULL;
+static framework_pt serverFramework = NULL;
+static bundle_context_pt serverContext = NULL;
 
-    static void setupFm(void) {
-        int rc = 0;
+static framework_pt clientFramework = NULL;
+static bundle_context_pt clientContext = NULL;
+
+static void setupFm(void) {
+    int rc = 0;
+    bundle_pt bundle = NULL;
+
+    //server
+    rc = celixLauncher_launch("server.properties", &serverFramework);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    bundle = NULL;
+    rc = framework_getFrameworkBundle(serverFramework, &bundle);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    rc = bundle_getContext(bundle, &serverContext);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    //client
+    rc = celixLauncher_launch("client.properties", &clientFramework);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    bundle = NULL;
+    rc = framework_getFrameworkBundle(clientFramework, &bundle);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+
+    rc = bundle_getContext(bundle, &clientContext);
+    CHECK_EQUAL(CELIX_SUCCESS, rc);
+}
+
+static void teardownFm(void) {
+    celixLauncher_stop(serverFramework);
+    celixLauncher_waitForShutdown(serverFramework);
+    celixLauncher_destroy(serverFramework);
+
+    celixLauncher_stop(clientFramework);
+    celixLauncher_waitForShutdown(clientFramework);
+    celixLauncher_destroy(clientFramework);
+
+    serverContext = NULL;
+    serverFramework = NULL;
+    clientContext = NULL;
+    clientFramework = NULL;
+}
+
+static void test1(void) {
+    celix_status_t status = CELIX_BUNDLE_EXCEPTION;
+    service_reference_pt ref = NULL;
+    calculator_service_pt calcService = NULL;
+    int retries = 12;
+
+    while (ref == NULL && retries > 0) {
+    	printf("Waiting for service .. %d\n", retries);
+		status = bundleContext_getServiceReference(clientContext, (char *) CALCULATOR_SERVICE,
&ref);
+		usleep(1000000);
+		--retries;
+    }
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+    CHECK(ref != NULL);
+
+    status = bundleContext_getService(clientContext, ref, (void **) &calcService);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+    CHECK(calcService != NULL);
+
+    double result = 0;
+    status = calcService->add(calcService->calculator, 2.0, 5.0, &result);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+    CHECK_EQUAL(7.0, result);
+
+    bundleContext_ungetService(clientContext, ref, NULL);
+    bundleContext_ungetServiceReference(clientContext, ref);
+}
+
+static celix_status_t getPermutations(long bundleIds[], int from, int to, array_list_pt permutations)
{
+    celix_status_t status = CELIX_SUCCESS;
+    int i = 0;
+
+    if (from == to) {
+        long* permutation = (long*) calloc(to + 1, sizeof(bundleIds[0]));
+
+        if (!permutation) {
+            status = CELIX_ENOMEM;
+        } else {
+            for (; i <= to; i++) {
+                permutation[i] = bundleIds[i];
+            }
+
+            arrayList_add(permutations, permutation);
+        }
+    } else {
+        for (i = from; i <= to; i++) {
+            long fromOrg = bundleIds[from];
+            long iOrg = bundleIds[i];
+
+            bundleIds[from] = iOrg;
+            bundleIds[i] = fromOrg;
+
+            status = getPermutations(bundleIds, from + 1, to, permutations);
+
+            bundleIds[from] = fromOrg;
+            bundleIds[i] = iOrg;
+        }
+    }
+
+    return status;
+}
+
+static celix_status_t getRemoteServicesBundles(bundle_context_pt context, long rsaBundles[])
{
+    celix_status_t status;
+    array_list_pt bundles = NULL;
+
+    status = bundleContext_getBundles(clientContext, &bundles);
+
+    if (status == CELIX_SUCCESS) {
+        unsigned int size = arrayList_size(bundles);
+        unsigned int bundleCnt = 0;
+        unsigned int i;
+
+        for (i = 0; i < size; i++) {
+            module_pt module = NULL;
+            char *name = NULL;
+
+            bundle_pt bundle = (bundle_pt) arrayList_get(bundles, i);
+
+            status = bundle_getCurrentModule(bundle, &module);
+
+            if (status == CELIX_SUCCESS) {
+                status = module_getSymbolicName(module, &name);
+
+            }
+
+            if (status == CELIX_SUCCESS) {
+                if ((strcmp(name, DISCOVERY_CFG_NAME) == 0) || (strcmp(name, RSA_HTTP_NAME)
== 0) || (strcmp(name, TOPOLOGY_MANAGER_NAME) == 0)) {
+                    bundle_archive_pt bundleArchive = NULL;
+                    long bundleId = -1;
+
+                    status = bundle_getArchive(bundle, &bundleArchive);
+
+                    if (status == CELIX_SUCCESS) {
+                        status = bundleArchive_getId(bundleArchive, &bundleId);
+                    }
+
+                    if (status == CELIX_SUCCESS) {
+                        rsaBundles[bundleCnt] = bundleId;
+                        ++bundleCnt;
+                    }
+                }
+            }
+        }
+
+        arrayList_destroy(bundles);
+    }
+
+    return status;
+}
+
+static celix_status_t stopStartPermutation(bundle_context_pt context, long* permutation)
{
+    celix_status_t status = CELIX_SUCCESS;
+    int y = 0;
+
+    printf("Test stop/start permutation: ");
+
+    for (y = 0; (y < NUM_OF_BUNDLES) && (status == CELIX_SUCCESS); y++) {
         bundle_pt bundle = NULL;
 
-        //server
-        rc = celixLauncher_launch("server.properties", &serverFramework);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        status = bundleContext_getBundleById(context, permutation[y], &bundle);
+
+        if (status == CELIX_SUCCESS) {
+            module_pt module = NULL;
+            char *name = NULL;
 
-        bundle = NULL;
-        rc = framework_getFrameworkBundle(serverFramework, &bundle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+            status = bundle_getCurrentModule(bundle, &module);
 
-        rc = bundle_getContext(bundle, &serverContext);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+            if (status == CELIX_SUCCESS) {
+                status = module_getSymbolicName(module, &name);
+                printf("%s (%ld) ", name, permutation[y]);
+            }
+        }
+    }
+    printf("\n");
 
+    // stop all bundles
+    if (status == CELIX_SUCCESS) {
+        for (y = 0; (y < NUM_OF_BUNDLES) && (status == CELIX_SUCCESS); y++) {
+            bundle_pt bundle = NULL;
 
-        //client
-        rc = celixLauncher_launch("client.properties", &clientFramework);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+            status = bundleContext_getBundleById(context, permutation[y], &bundle);
 
-        bundle = NULL;
-        rc = framework_getFrameworkBundle(clientFramework, &bundle);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+            if (status == CELIX_SUCCESS) {
+                printf("stop bundle: %ld\n", permutation[y]);
+                status = bundle_stop(bundle);
+            }
 
-        rc = bundle_getContext(bundle, &clientContext);
-        CHECK_EQUAL(CELIX_SUCCESS, rc);
+        }
     }
 
-    static void teardownFm(void) {
-        celixLauncher_stop(serverFramework);
-        celixLauncher_waitForShutdown(serverFramework);
-        celixLauncher_destroy(serverFramework);
+    //usleep(10000000);
+    // verify stop state
+    if (status == CELIX_SUCCESS) {
+        for (y = 0; (y < NUM_OF_BUNDLES) && (status == CELIX_SUCCESS); y++) {
+            bundle_pt bundle = NULL;
+
+            status = bundleContext_getBundleById(context, permutation[y], &bundle);
+
+            if (status == CELIX_SUCCESS) {
+                bundle_state_e state;
+                status = bundle_getState(bundle, &state);
+                module_pt module = NULL;
+                char *name = NULL;
 
-        celixLauncher_stop(clientFramework);
-        celixLauncher_waitForShutdown(clientFramework);
-        celixLauncher_destroy(clientFramework);
+                status = bundle_getCurrentModule(bundle, &module);
 
-        serverContext = NULL;
-        serverFramework = NULL;
-        clientContext = NULL;
-        clientFramework = NULL;
+                status = module_getSymbolicName(module, &name);
+
+                printf("bundle %s (%ld) has state %d (should be %d) \n", name, permutation[y],
state, OSGI_FRAMEWORK_BUNDLE_RESOLVED);
+
+                if (state != OSGI_FRAMEWORK_BUNDLE_RESOLVED) {
+                    printf("bundle %ld has state %d (should be %d) \n", permutation[y], state,
OSGI_FRAMEWORK_BUNDLE_RESOLVED);
+                    status = CELIX_ILLEGAL_STATE;
+                }
+            }
+
+        }
     }
 
-    static void test1(void) {
-        celix_status_t status;
-        service_reference_pt ref = NULL;
-        calculator_service_pt calcService = NULL;
-        usleep(2000000); //TODO use tracker
+    // start all bundles
+    if (status == CELIX_SUCCESS) {
 
-        status = bundleContext_getServiceReference(clientContext, (char *)CALCULATOR_SERVICE,
&ref);
-        CHECK_EQUAL(CELIX_SUCCESS, status);
-        CHECK(ref != NULL);
+        for (y = 0; (y < NUM_OF_BUNDLES) && (status == CELIX_SUCCESS); y++) {
+            bundle_pt bundle = NULL;
+
+            status = bundleContext_getBundleById(context, permutation[y], &bundle);
+
+            if (status == CELIX_SUCCESS) {
+                printf("start bundle: %ld\n", permutation[y]);
+                status = bundle_start(bundle);
+            }
+
+        }
+    }
+
+    // verify started state
+    if (status == CELIX_SUCCESS) {
+        for (y = 0; (y < NUM_OF_BUNDLES) && (status == CELIX_SUCCESS); y++) {
+            bundle_pt bundle = NULL;
+
+            status = bundleContext_getBundleById(context, permutation[y], &bundle);
+
+            if (status == CELIX_SUCCESS) {
+                bundle_state_e state;
+                status = bundle_getState(bundle, &state);
+
+                if (state != OSGI_FRAMEWORK_BUNDLE_ACTIVE) {
+                    printf("bundle %ld has state %d (should be %d) \n", permutation[y], state,
OSGI_FRAMEWORK_BUNDLE_ACTIVE);
+                    status = CELIX_ILLEGAL_STATE;
+                }
+            }
+
+        }
+    }
+
+    return status;
+}
 
-        status = bundleContext_getService(clientContext, ref, (void **)&calcService);
-        CHECK_EQUAL(CELIX_SUCCESS, status);
-        CHECK(calcService != NULL);
 
-        double result = 0;
-        status = calcService->add(calcService->calculator, 2.0, 5.0, &result);
+static void testImport(void) {
+    celix_status_t status;
+    array_list_pt bundlePermutations = NULL;
+    long rsaBundles[NUM_OF_BUNDLES];
+    unsigned int i;
+
+    arrayList_create(&bundlePermutations);
+
+    status = getRemoteServicesBundles(clientContext, rsaBundles);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+
+    status = getPermutations(rsaBundles, 0, NUM_OF_BUNDLES - 1, bundlePermutations);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+
+    for (i = 0; i < arrayList_size(bundlePermutations); ++i) {
+        long* singlePermutation = (long*) arrayList_get(bundlePermutations, i);
+
+        status = stopStartPermutation(clientContext, singlePermutation);
         CHECK_EQUAL(CELIX_SUCCESS, status);
-        CHECK_EQUAL(7.0, result);
 
-        bundleContext_ungetService(clientContext, ref, NULL);
-        bundleContext_ungetServiceReference(clientContext, ref);
+        // check whether calc service is available
+        test1();
+
+        free(singlePermutation);
     }
 
+    arrayList_destroy(bundlePermutations);
 }
 
+static void testExport(void) {
+    celix_status_t status;
+    array_list_pt bundlePermutations = NULL;
+    long rsaBundles[NUM_OF_BUNDLES];
+    unsigned int i;
+
+    arrayList_create(&bundlePermutations);
+
+    status = getRemoteServicesBundles(serverContext, rsaBundles);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+
+    status = getPermutations(rsaBundles, 0, NUM_OF_BUNDLES - 1, bundlePermutations);
+    CHECK_EQUAL(CELIX_SUCCESS, status);
+
+    for (i = 0; i < arrayList_size(bundlePermutations); ++i) {
+        long* singlePermutation = (long*) arrayList_get(bundlePermutations, i);
+
+        status = stopStartPermutation(serverContext, singlePermutation);
+        CHECK_EQUAL(CELIX_SUCCESS, status);
+
+        // check whether calc service is available
+        test1();
+
+        free(singlePermutation);
+    }
 
-TEST_GROUP(RsaHttpClientServerTests) {
+    arrayList_destroy(bundlePermutations);
+}
+}
+
+TEST_GROUP(RsaShmClientServerTests) {
     void setup() {
         setupFm();
     }
@@ -121,6 +379,14 @@ TEST_GROUP(RsaHttpClientServerTests) {
     }
 };
 
-TEST(RsaHttpClientServerTests, Test1) {
+TEST(RsaShmClientServerTests, Test1) {
     test1();
 }
+
+TEST(RsaShmClientServerTests, TestImport) {
+    testImport();
+}
+
+TEST(RsaShmClientServerTests, TestExport) {
+    testExport();
+}


Mime
View raw message