phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jamestay...@apache.org
Subject phoenix git commit: PHOENIX-2256 Test failure in PMetaDataImplTest (James Heather)
Date Tue, 06 Oct 2015 04:29:47 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.5-HBase-1.1 cbe78b5ba -> 77ed6b621


PHOENIX-2256 Test failure in PMetaDataImplTest (James Heather)


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

Branch: refs/heads/4.5-HBase-1.1
Commit: 77ed6b621ac7d3bad152c1847d08e1e908330048
Parents: cbe78b5
Author: James Taylor <jamestaylor@apache.org>
Authored: Mon Oct 5 18:42:23 2015 -0700
Committer: James Taylor <jtaylor@salesforce.com>
Committed: Mon Oct 5 21:27:52 2015 -0700

----------------------------------------------------------------------
 .../apache/phoenix/schema/PMetaDataImpl.java    |  2 +-
 .../phoenix/schema/PMetaDataImplTest.java       | 72 ++++++++++++++++++--
 2 files changed, 66 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/77ed6b62/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
index c4e3674..8d1c96a 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/schema/PMetaDataImpl.java
@@ -160,7 +160,7 @@ public class PMetaDataImpl implements PMetaData {
                     newCache.put(tableRef.table.getKey(), new PTableRef(tableRef));
                     toRemove.add(tableRef);
                     toRemoveBytes += tableRef.estSize;
-                    if (toRemoveBytes - toRemove.peekLast().estSize > overage) {
+                    while (toRemoveBytes - toRemove.peekLast().estSize >= overage) {
                         PTableRef removedRef = toRemove.removeLast();
                         toRemoveBytes -= removedRef.estSize;
                     }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/77ed6b62/phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java b/phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java
index 9379ef3..e4ac5d3 100644
--- a/phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java
+++ b/phoenix-core/src/test/java/org/apache/phoenix/schema/PMetaDataImplTest.java
@@ -17,16 +17,15 @@
  */
 package org.apache.phoenix.schema;
 
-import static org.junit.Assert.assertEquals;
-
-import java.sql.SQLException;
-import java.util.Set;
-
+import com.google.common.collect.Sets;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.phoenix.util.TimeKeeper;
 import org.junit.Test;
 
-import com.google.common.collect.Sets;
+import java.sql.SQLException;
+import java.util.Set;
+
+import static org.junit.Assert.assertEquals;
 
 public class PMetaDataImplTest {
     
@@ -104,7 +103,66 @@ public class PMetaDataImplTest {
         assertEquals(2, metaData.size());
         assertNames(metaData, "d","e");
     }
-    
+
+    @Test
+    public void shouldNotEvictMoreEntriesThanNecessary() throws Exception {
+        long maxSize = 5;
+        PMetaData metaData = new PMetaDataImpl(5, maxSize, new TestTimeKeeper());
+        metaData = addToTable(metaData, "a", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "b", 1);
+        assertEquals(2, metaData.size());
+        assertNames(metaData, "a", "b");
+        metaData = addToTable(metaData, "c", 3);
+        assertEquals(3, metaData.size());
+        assertNames(metaData, "a", "b", "c");
+        getFromTable(metaData, "a");
+        getFromTable(metaData, "b");
+        metaData = addToTable(metaData, "d", 3);
+        assertEquals(3, metaData.size());
+        assertNames(metaData, "a", "b", "d");
+    }
+
+    @Test
+    public void shouldAlwaysKeepAtLeastOneEntryEvenIfTooLarge() throws Exception {
+        long maxSize = 5;
+        PMetaData metaData = new PMetaDataImpl(5, maxSize, new TestTimeKeeper());
+        metaData = addToTable(metaData, "a", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "b", 1);
+        assertEquals(2, metaData.size());
+        metaData = addToTable(metaData, "c", 5);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "d", 20);
+        assertEquals(1, metaData.size());
+        assertNames(metaData, "d");
+        metaData = addToTable(metaData, "e", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "f", 2);
+        assertEquals(2, metaData.size());
+        assertNames(metaData, "e", "f");
+    }
+
+    @Test
+    public void shouldAlwaysKeepOneEntryIfMaxSizeIsZero() throws Exception {
+        long maxSize = 0;
+        PMetaData metaData = new PMetaDataImpl(0, maxSize, new TestTimeKeeper());
+        metaData = addToTable(metaData, "a", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "b", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "c", 5);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "d", 20);
+        assertEquals(1, metaData.size());
+        assertNames(metaData, "d");
+        metaData = addToTable(metaData, "e", 1);
+        assertEquals(1, metaData.size());
+        metaData = addToTable(metaData, "f", 2);
+        assertEquals(1, metaData.size());
+        assertNames(metaData, "f");
+    }
+
     private static class PSizedTable extends PTableImpl {
         private final int size;
         private final PTableKey key;


Mime
View raw message