ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tbeerbo...@apache.org
Subject ambari git commit: AMBARI-9715 - PSQLException (duplicate key value) thrown from persist API call. (tbeerbower)
Date Thu, 19 Feb 2015 20:09:50 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk 6b64cfec9 -> 114e9a490


AMBARI-9715 - PSQLException (duplicate key value) thrown from persist API call. (tbeerbower)


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

Branch: refs/heads/trunk
Commit: 114e9a490e1fa9bb4494e1f198751825ec3bd64e
Parents: 6b64cfe
Author: tbeerbower <tbeerbower@hortonworks.com>
Authored: Thu Feb 19 15:09:23 2015 -0500
Committer: tbeerbower <tbeerbower@hortonworks.com>
Committed: Thu Feb 19 15:09:31 2015 -0500

----------------------------------------------------------------------
 .../api/services/PersistKeyValueImpl.java       |  1 -
 .../api/services/PersistKeyValueImplTest.java   | 32 ++++++++++++++++++++
 2 files changed, 32 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/114e9a49/ambari-server/src/main/java/org/apache/ambari/server/api/services/PersistKeyValueImpl.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/main/java/org/apache/ambari/server/api/services/PersistKeyValueImpl.java
b/ambari-server/src/main/java/org/apache/ambari/server/api/services/PersistKeyValueImpl.java
index 1bcf67e..3a6cd88 100644
--- a/ambari-server/src/main/java/org/apache/ambari/server/api/services/PersistKeyValueImpl.java
+++ b/ambari-server/src/main/java/org/apache/ambari/server/api/services/PersistKeyValueImpl.java
@@ -60,7 +60,6 @@ public class PersistKeyValueImpl {
     return key;
   }
 
-  @Transactional
   public synchronized void put(String key, String value) {
     KeyValueEntity keyValueEntity = keyValueDAO.findByKey(key);
     if (keyValueEntity != null) {

http://git-wip-us.apache.org/repos/asf/ambari/blob/114e9a49/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
----------------------------------------------------------------------
diff --git a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
index b36285d..6045ec0 100644
--- a/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
+++ b/ambari-server/src/test/java/org/apache/ambari/server/api/services/PersistKeyValueImplTest.java
@@ -32,6 +32,9 @@ import java.util.Map;
 
 
 public class PersistKeyValueImplTest extends Assert {
+
+  public static final int NUMB_THREADS = 1000;
+
   private Injector injector;
 
   @Before
@@ -75,4 +78,33 @@ public class PersistKeyValueImplTest extends Assert {
     assertEquals(largeValue, impl.getValue("key3"));
 
   }
+
+  @Test
+  public void testMultiThreaded() throws Exception {
+    final PersistKeyValueImpl impl = injector.getInstance(PersistKeyValueImpl.class);
+    Thread[] threads = new Thread[NUMB_THREADS];
+
+    for ( int i = 0; i < NUMB_THREADS; ++i ) {
+      threads[i] = new Thread() {
+        @Override
+        public void run() {
+
+          for (int i = 0; i < 100; ++i) {
+            impl.put("key1", "value1");
+            impl.put("key2", "value2");
+            impl.put("key3", "value3");
+            impl.put("key4", "value4");
+          }
+        }
+      };
+    }
+
+    for ( int i = 0; i < NUMB_THREADS; ++i ) {
+      threads[i].start();
+    }
+
+    for ( int i = 0; i < NUMB_THREADS; ++i ) {
+      threads[i].join();
+    }
+  }
 }


Mime
View raw message