Merge "Further MusicCassaCore Testing"
authorThomas Nelson <nelson24@att.com>
Wed, 29 Jan 2020 19:48:03 +0000 (19:48 +0000)
committerGerrit Code Review <gerrit@onap.org>
Wed, 29 Jan 2020 19:48:03 +0000 (19:48 +0000)
1  2 
music-core/src/main/java/org/onap/music/service/impl/MusicCassaCore.java

@@@ -27,13 -27,12 +27,13 @@@ package org.onap.music.service.impl
  
  import java.io.StringWriter;
  import java.util.Collections;
 +import java.util.HashMap;
  import java.util.HashSet;
  import java.util.List;
  import java.util.Map;
  import java.util.Set;
  import java.util.StringTokenizer;
 -
 +import java.util.concurrent.atomic.AtomicInteger;
  import javax.ws.rs.core.MultivaluedMap;
  
  import org.onap.music.datastore.Condition;
@@@ -76,9 -75,7 +76,9 @@@ public class MusicCassaCore implements 
      private static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(MusicCassaCore.class);
      private static MusicCassaCore musicCassaCoreInstance = null;
      private static Set<String> set = Collections.synchronizedSet(new HashSet<String>());
 -
 +    HashMap<String, Integer> map = new HashMap<>();
 +    AtomicInteger wait = new AtomicInteger(0);
 +    
      private MusicCassaCore() {
          // not going to happen
      }
@@@ -87,7 -84,8 +87,8 @@@
          return mLockHandle;
      }
  
-     public static void setmLockHandle(CassaLockStore mLockHandle) {
+     //for unit testing purposes
+     static void setmLockHandle(CassaLockStore mLockHandle) {
          MusicCassaCore.mLockHandle = mLockHandle;
      }
      
      public String createLockReference(String fullyQualifiedKey, String owner) throws MusicLockingException {
          return createLockReference(fullyQualifiedKey, LockType.WRITE, owner);
      }
 -
 +    
 +    
      /**
       * This will be called for Atomic calls
 -     * 
 +     * it ensures that only one thread tries to create a lock on each key at a time
       */
      public String createLockReferenceAtomic(String fullyQualifiedKey, LockType locktype) throws MusicLockingException {
          String[] splitString = fullyQualifiedKey.split("\\.");
       * @return Boolean Indicates success or failure
       * @throws MusicServiceException
       *
-      *
       */
      public ResultType createTable(String keyspace, String table, PreparedQueryObject tableQueryObject,
              String consistency) throws MusicServiceException {
          try {
              // create shadow locking table
              result = getLockingServiceHandle().createLockQueue(keyspace, table);
-             if (result == false)
+             if (result == false) {
                  return ResultType.FAILURE;
+             }
              result = false;
  
              // create table to track unsynced_keys
              PreparedQueryObject queryObject = new PreparedQueryObject();
  
              queryObject.appendQueryString(tabQuery);
-             result = false;
              result = MusicDataStoreHandle.getDSHandle().executePut(queryObject, "eventual");
+             if (result == false) {
+                 return ResultType.FAILURE;
+             }
+             result = false;
  
              // create actual table
              result = MusicDataStoreHandle.getDSHandle().executePut(tableQueryObject, consistency);