apex-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From csi...@apache.org
Subject [1/2] apex-malhar git commit: APEXMALHAR-2171 #resolve #comment Added method call to set maxCacheSize when building cache.
Date Fri, 29 Jul 2016 19:22:10 GMT
Repository: apex-malhar
Updated Branches:
  refs/heads/master a185fef04 -> 8bfaf7896


APEXMALHAR-2171 #resolve #comment Added method call to set maxCacheSize when building cache.


Project: http://git-wip-us.apache.org/repos/asf/apex-malhar/repo
Commit: http://git-wip-us.apache.org/repos/asf/apex-malhar/commit/8a41342f
Tree: http://git-wip-us.apache.org/repos/asf/apex-malhar/tree/8a41342f
Diff: http://git-wip-us.apache.org/repos/asf/apex-malhar/diff/8a41342f

Branch: refs/heads/master
Commit: 8a41342f5acd25c977c51ded079600476b0b925c
Parents: a185fef
Author: Shunxin <lushunxin@hotmail.com>
Authored: Thu Jul 28 22:23:15 2016 -0700
Committer: Shunxin <lushunxin@hotmail.com>
Committed: Thu Jul 28 22:23:15 2016 -0700

----------------------------------------------------------------------
 .../datatorrent/lib/db/cache/CacheStore.java    |  1 +
 .../lib/db/cache/CacheStoreTest.java            | 58 ++++++++++++++++++++
 2 files changed, 59 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/8a41342f/library/src/main/java/com/datatorrent/lib/db/cache/CacheStore.java
----------------------------------------------------------------------
diff --git a/library/src/main/java/com/datatorrent/lib/db/cache/CacheStore.java b/library/src/main/java/com/datatorrent/lib/db/cache/CacheStore.java
index 72063ee..d356ee8 100644
--- a/library/src/main/java/com/datatorrent/lib/db/cache/CacheStore.java
+++ b/library/src/main/java/com/datatorrent/lib/db/cache/CacheStore.java
@@ -112,6 +112,7 @@ public class CacheStore implements CacheManager.Primary
     open = true;
 
     CacheBuilder<Object, Object> cacheBuilder = CacheBuilder.newBuilder();
+    cacheBuilder.maximumSize(maxCacheSize);
     if (entryExpiryStrategy == ExpiryType.EXPIRE_AFTER_ACCESS) {
       cacheBuilder.expireAfterAccess(entryExpiryDurationInMillis, TimeUnit.MILLISECONDS);
     } else if (entryExpiryStrategy == ExpiryType.EXPIRE_AFTER_WRITE) {

http://git-wip-us.apache.org/repos/asf/apex-malhar/blob/8a41342f/library/src/test/java/com/datatorrent/lib/db/cache/CacheStoreTest.java
----------------------------------------------------------------------
diff --git a/library/src/test/java/com/datatorrent/lib/db/cache/CacheStoreTest.java b/library/src/test/java/com/datatorrent/lib/db/cache/CacheStoreTest.java
new file mode 100644
index 0000000..335418a
--- /dev/null
+++ b/library/src/test/java/com/datatorrent/lib/db/cache/CacheStoreTest.java
@@ -0,0 +1,58 @@
+/**
+ * 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 com.datatorrent.lib.db.cache;
+
+import java.io.IOException;
+import java.util.Map;
+import org.junit.Assert;
+import org.junit.Test;
+import com.google.common.collect.Maps;
+
+/**
+ * Test fot {@link CacheStore}.
+ */
+public class CacheStoreTest
+{
+  @Test
+  public void CacheStoreTest()
+  {
+    final Map<Object, Object> backupMap = Maps.newHashMap();
+    
+    backupMap.put(1, "one");
+    backupMap.put(2, "two");
+    backupMap.put(3, "three");
+    backupMap.put(4, "four");
+    backupMap.put(5, "five");
+    backupMap.put(6, "six");
+    backupMap.put(7, "seven");
+    backupMap.put(8, "eight");
+    backupMap.put(9, "nine");
+    backupMap.put(10, "ten");
+  
+    CacheStore cs = new CacheStore();
+    cs.setMaxCacheSize(5);
+    try {
+      cs.connect();
+      cs.putAll(backupMap);
+      Assert.assertEquals(5, cs.getKeys().size());
+    } catch (IOException e) {
+      e.printStackTrace();
+    }
+  }
+}


Mime
View raw message