stratos-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From im...@apache.org
Subject [1/2] stratos git commit: Fixing distributed lock object serialization issue and adding unit tests for verifying clustered mode
Date Tue, 02 Dec 2014 01:53:00 GMT
Repository: stratos
Updated Branches:
  refs/heads/master e29ce9d3e -> fdb84e7c1


Fixing distributed lock object serialization issue and adding unit tests for verifying clustered
mode


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

Branch: refs/heads/master
Commit: a2b64fa9421e71f007fbb8712bd066342cbb24a7
Parents: e29ce9d
Author: Imesh Gunaratne <imesh@apache.org>
Authored: Mon Dec 1 21:04:12 2014 +0530
Committer: Imesh Gunaratne <imesh@apache.org>
Committed: Tue Dec 2 07:20:42 2014 +0530

----------------------------------------------------------------------
 .../clustering/DistributedObjectProvider.java   | 24 ++++++---
 .../test/DistributedObjectProviderTest.java     | 57 ++++++++++++++++++--
 2 files changed, 69 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/stratos/blob/a2b64fa9/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/clustering/DistributedObjectProvider.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/clustering/DistributedObjectProvider.java
b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/clustering/DistributedObjectProvider.java
index 428d3da..328f67d 100644
--- a/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/clustering/DistributedObjectProvider.java
+++ b/components/org.apache.stratos.common/src/main/java/org/apache/stratos/common/clustering/DistributedObjectProvider.java
@@ -58,6 +58,10 @@ public class DistributedObjectProvider implements Serializable {
     }
 
     private void releaseDistributedLock(ILock lock) {
+        if(lock == null) {
+            return;
+        }
+
         if (log.isDebugEnabled()) {
             log.debug(String.format("Releasing distributed lock for %s...", lock.getKey()));
         }
@@ -105,8 +109,9 @@ public class DistributedObjectProvider implements Serializable {
          if(clustered) {
              ILock lock = null;
              try {
-                 lock = acquireDistributedLock(map);
-                 ((IMap)map).set(key, value);
+                 IMap imap = (IMap) map;
+                 lock = acquireDistributedLock(imap.getName());
+                 imap.set(key, value);
              } finally {
                  releaseDistributedLock(lock);
              }
@@ -124,8 +129,9 @@ public class DistributedObjectProvider implements Serializable {
         if(clustered) {
             ILock lock = null;
             try {
-                lock = acquireDistributedLock(map);
-                ((IMap)map).delete(key);
+                IMap imap = (IMap) map;
+                lock = acquireDistributedLock(imap.getName());
+                imap.delete(key);
             } finally {
                 releaseDistributedLock(lock);
             }
@@ -143,8 +149,9 @@ public class DistributedObjectProvider implements Serializable {
         if(clustered) {
             ILock lock = null;
             try {
-                lock = acquireDistributedLock(list);
-                ((IList)list).add(value);
+                IList ilist = (IList) list;
+                lock = acquireDistributedLock(ilist.getName());
+                ilist.add(value);
             } finally {
                 releaseDistributedLock(lock);
             }
@@ -162,8 +169,9 @@ public class DistributedObjectProvider implements Serializable {
         if(clustered) {
             ILock lock = null;
             try {
-                lock = acquireDistributedLock(list);
-                ((IList)list).remove(value);
+                IList ilist = (IList) list;
+                lock = acquireDistributedLock(ilist.getName());
+                ilist.remove(value);
             } finally {
                 releaseDistributedLock(lock);
             }

http://git-wip-us.apache.org/repos/asf/stratos/blob/a2b64fa9/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/DistributedObjectProviderTest.java
----------------------------------------------------------------------
diff --git a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/DistributedObjectProviderTest.java
b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/DistributedObjectProviderTest.java
index 048680d..9d31923 100644
--- a/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/DistributedObjectProviderTest.java
+++ b/components/org.apache.stratos.common/src/test/java/org/apache/stratos/common/test/DistributedObjectProviderTest.java
@@ -19,7 +19,10 @@
 
 package org.apache.stratos.common.test;
 
+import com.hazelcast.core.Hazelcast;
+import com.hazelcast.core.HazelcastInstance;
 import org.apache.stratos.common.clustering.DistributedObjectProvider;
+import org.junit.BeforeClass;
 import org.junit.Test;
 
 import java.util.List;
@@ -30,13 +33,32 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
 
+/**
+ * Distributed object provider unit tests.
+ */
 public class DistributedObjectProviderTest {
 
+    private static HazelcastInstance hazelcastInstance;
+
+    @BeforeClass
+    public static void setUpClass() {
+        hazelcastInstance = Hazelcast.newHazelcastInstance();
+    }
+
     @Test
     public void testPutToMapLocal() {
         DistributedObjectProvider provider = new DistributedObjectProvider(false, null);
-        Map<String, String> map = provider.getMap("MAP1");
+        testPutToMap(provider);
+    }
+
+    @Test
+    public void testPutToMapDistributed() {
+        DistributedObjectProvider provider = new DistributedObjectProvider(true, hazelcastInstance);
+        testPutToMap(provider);
+    }
 
+    private void testPutToMap(DistributedObjectProvider provider) {
+        Map<String, String> map = provider.getMap("MAP1");
         provider.putToMap(map, "key1", "value1");
         assertEquals(map.get("key1"), "value1");
     }
@@ -44,8 +66,17 @@ public class DistributedObjectProviderTest {
     @Test
     public void testRemoveFromMapLocal() {
         DistributedObjectProvider provider = new DistributedObjectProvider(false, null);
-        Map<String, String> map = provider.getMap("MAP1");
+        testRemoveFromMap(provider);
+    }
+
+    @Test
+    public void testRemoveFromMapDistributed() {
+        DistributedObjectProvider provider = new DistributedObjectProvider(true, hazelcastInstance);
+        testRemoveFromMap(provider);
+    }
 
+    private void testRemoveFromMap(DistributedObjectProvider provider) {
+        Map<String, String> map = provider.getMap("MAP1");
         provider.putToMap(map, "key1", "value1");
         assertEquals(map.get("key1"), "value1");
         provider.removeFromMap(map, "key1");
@@ -55,8 +86,17 @@ public class DistributedObjectProviderTest {
     @Test
     public void testAddToListLocal() {
         DistributedObjectProvider provider = new DistributedObjectProvider(false, null);
-        List list = provider.getList("LIST1");
+        testAddToList(provider);
+    }
+
+    @Test
+    public void testAddToListDistributed() {
+        DistributedObjectProvider provider = new DistributedObjectProvider(true, hazelcastInstance);
+        testAddToList(provider);
+    }
 
+    private void testAddToList(DistributedObjectProvider provider) {
+        List list = provider.getList("LIST1");
         String value1 = "value1";
         provider.addToList(list, value1);
         assertTrue(list.contains(value1));
@@ -65,8 +105,17 @@ public class DistributedObjectProviderTest {
     @Test
     public void testRemoveFromListLocal() {
         DistributedObjectProvider provider = new DistributedObjectProvider(false, null);
-        List list = provider.getList("LIST1");
+        testRemovalFromList(provider);
+    }
 
+    @Test
+    public void testRemoveFromListDistributed() {
+        DistributedObjectProvider provider = new DistributedObjectProvider(true, hazelcastInstance);
+        testRemovalFromList(provider);
+    }
+
+    private void testRemovalFromList(DistributedObjectProvider provider) {
+        List list = provider.getList("LIST1");
         String value1 = "value1";
         provider.addToList(list, value1);
         assertTrue(list.contains(value1));


Mime
View raw message