cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject [1/7] git commit: updated refs/heads/master to 535ab51
Date Tue, 27 Oct 2015 18:27:35 GMT
Repository: cloudstack
Updated Branches:
  refs/heads/master fb4e6ed6b -> 535ab51b9


CLOUDSTACK-8816: some of the events do not have resource uuids

the key for an entity is sometimes an object a String with value
object.toString() due to serialization and deserialization of them.
Addressed this in the getter of CallContext to check for key.toString
if an object is not found with key.


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

Branch: refs/heads/master
Commit: 863931a992434a3bd736383882f9cc65a376d63e
Parents: 7d73e9b
Author: Rajani Karuturi <rajani.karuturi@citrix.com>
Authored: Fri Sep 18 14:53:11 2015 +0530
Committer: Rajani Karuturi <rajani.karuturi@citrix.com>
Committed: Mon Oct 26 09:15:31 2015 +0530

----------------------------------------------------------------------
 .../apache/cloudstack/context/CallContext.java  | 13 ++-
 .../cloudstack/context/CallContextTest.java     | 83 ++++++++++++++++++++
 2 files changed, 95 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/863931a9/api/src/org/apache/cloudstack/context/CallContext.java
----------------------------------------------------------------------
diff --git a/api/src/org/apache/cloudstack/context/CallContext.java b/api/src/org/apache/cloudstack/context/CallContext.java
index 2619f4a..fb83f86 100644
--- a/api/src/org/apache/cloudstack/context/CallContext.java
+++ b/api/src/org/apache/cloudstack/context/CallContext.java
@@ -89,8 +89,19 @@ public class CallContext {
         context.put(key, value);
     }
 
+    /**
+     * @param key any not null key object
+     * @return the value of the key from context map
+     * @throws NullPointerException if the specified key is nul
+     */
     public Object getContextParameter(Object key) {
-        return context.get(key);
+        Object value = context.get(key);
+        //check if the value is present in the toString value of the key
+        //due to a bug in the way we update the key by serializing and deserializing, it
sometimes gets toString value of the key. @see com.cloud.api.ApiAsyncJobDispatcher#runJob
+        if(value == null ) {
+            value = context.get(key.toString());
+        }
+        return value;
     }
 
     public long getCallingUserId() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/863931a9/api/test/org/apache/cloudstack/context/CallContextTest.java
----------------------------------------------------------------------
diff --git a/api/test/org/apache/cloudstack/context/CallContextTest.java b/api/test/org/apache/cloudstack/context/CallContextTest.java
new file mode 100644
index 0000000..2b953a0
--- /dev/null
+++ b/api/test/org/apache/cloudstack/context/CallContextTest.java
@@ -0,0 +1,83 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.cloudstack.context;
+
+import java.util.UUID;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.runners.MockitoJUnitRunner;
+
+import com.cloud.user.Account;
+import com.cloud.user.User;
+import com.cloud.utils.db.EntityManager;
+
+@RunWith(MockitoJUnitRunner.class)
+public class CallContextTest {
+
+    @Mock
+    EntityManager entityMgr;
+
+    @Before
+    public void setUp() {
+        CallContext.init(entityMgr);
+        CallContext.register(Mockito.mock(User.class), Mockito.mock(Account.class));
+    }
+
+    @After
+    public void tearDown() throws Exception {
+        CallContext.unregisterAll();
+    }
+
+    @Test
+    public void testGetContextParameter() {
+        CallContext currentContext = CallContext.current();
+
+        Assert.assertEquals("There is nothing in the context. It should return null", null,
currentContext.getContextParameter("key"));
+        Assert.assertTrue("There is nothing in the context. The map should be empty", currentContext.getContextParameters().isEmpty());
+
+        UUID objectUUID = UUID.randomUUID();
+        UUID stringUUID = UUID.randomUUID();
+
+        //Case1: when an entry with the object class is present
+        currentContext.putContextParameter(User.class, objectUUID);
+        Assert.assertEquals("it should return objectUUID: " + objectUUID, objectUUID, currentContext.getContextParameter(User.class));
+        Assert.assertEquals("current context map should have exactly one entry", 1, currentContext.getContextParameters().size());
+
+        //Case2: when an entry with the object class name as String is present
+        currentContext.putContextParameter(Account.class.toString(), stringUUID);
+        //object is put with key as Account.class.toString but get with key as Account.class
+        Assert.assertEquals("it should return stringUUID: " + stringUUID, stringUUID, currentContext.getContextParameter(Account.class));
+        Assert.assertEquals("current context map should have exactly two entries", 2, currentContext.getContextParameters().size());
+
+        //Case3: when an entry with both object class and object class name as String is
present
+        //put an entry of account class object in the context
+        currentContext.putContextParameter(Account.class, objectUUID);
+        //since both object and string a present in the current context, it should return
object value
+        Assert.assertEquals("it should return objectUUID: " + objectUUID, objectUUID, currentContext.getContextParameter(Account.class));
+        Assert.assertEquals("current context map should have exactly three entries", 3, currentContext.getContextParameters().size());
+    }
+
+}
\ No newline at end of file


Mime
View raw message