You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by jg...@apache.org on 2009/09/03 01:23:53 UTC
svn commit: r810733 [2/2] - in /hadoop/hbase/trunk: ./
src/java/org/apache/hadoop/hbase/filter/ src/java/org/apache/hadoop/hbase/io/
src/java/org/apache/hadoop/hbase/regionserver/
src/test/org/apache/hadoop/hbase/filter/
Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestPageFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestPageFilter.java?rev=810733&r1=810732&r2=810733&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestPageFilter.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestPageFilter.java Wed Sep 2 23:23:52 2009
@@ -68,30 +68,26 @@
private void pageSizeTests(Filter f) throws Exception {
testFiltersBeyondPageSize(f, ROW_LIMIT);
- // Test reset works by going in again.
- f.reset();
- testFiltersBeyondPageSize(f, ROW_LIMIT);
}
private void testFiltersBeyondPageSize(final Filter f, final int pageSize) {
int count = 0;
for (int i = 0; i < (pageSize * 2); i++) {
- byte [] bytes = Bytes.toBytes(Integer.toString(i) + ":tail");
- KeyValue kv = new KeyValue(bytes, bytes);
- boolean filterOut =
- f.filterRowKey(kv.getBuffer(), kv.getRowOffset(), kv.getRowLength());
- if (!filterOut) {
- assertFalse("Disagrees with 'filter'", f.filterAllRemaining());
+ boolean filterOut = f.filterRow();
+
+ if(filterOut) {
+ break;
} else {
- // Once we have all for a page, calls to filterAllRemaining should
- // stay true.
- assertTrue("Disagrees with 'filter'", f.filterAllRemaining());
- assertTrue(i >= pageSize);
+ count++;
}
- if (Filter.ReturnCode.NEXT_ROW == f.filterKeyValue(kv)) {
- break;
+
+ // If at last row, should tell us to skip all remaining
+ if(count == pageSize) {
+ assertTrue(f.filterAllRemaining());
+ } else {
+ assertFalse(f.filterAllRemaining());
}
- count++;
+
}
assertEquals(pageSize, count);
}
Added: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java?rev=810733&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java (added)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestSingleColumnValueFilter.java Wed Sep 2 23:23:52 2009
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2007 The Apache Software Foundation
+ *
+ * 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.hadoop.hbase.filter;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.util.List;
+
+import org.apache.hadoop.hbase.KeyValue;
+import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
+import org.apache.hadoop.hbase.util.Bytes;
+
+import junit.framework.TestCase;
+
+/**
+ * Tests the value filter
+ */
+public class TestSingleColumnValueFilter extends TestCase {
+ private static final byte[] ROW = Bytes.toBytes("test");
+ private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
+ private static final byte [] COLUMN_QUALIFIER = Bytes.toBytes("foo");
+ private static final byte[] VAL_1 = Bytes.toBytes("a");
+ private static final byte[] VAL_2 = Bytes.toBytes("ab");
+ private static final byte[] VAL_3 = Bytes.toBytes("abc");
+ private static final byte[] VAL_4 = Bytes.toBytes("abcd");
+ private static final byte[] FULLSTRING_1 =
+ Bytes.toBytes("The quick brown fox jumps over the lazy dog.");
+ private static final byte[] FULLSTRING_2 =
+ Bytes.toBytes("The slow grey fox trips over the lazy dog.");
+ private static final String QUICK_SUBSTR = "quick";
+ private static final String QUICK_REGEX = ".+quick.+";
+
+ Filter basicFilter;
+ Filter substrFilter;
+ Filter regexFilter;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ basicFilter = basicFilterNew();
+ substrFilter = substrFilterNew();
+ regexFilter = regexFilterNew();
+ }
+
+ private Filter basicFilterNew() {
+ return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
+ CompareOp.GREATER_OR_EQUAL, VAL_2);
+ }
+
+ private Filter substrFilterNew() {
+ return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
+ CompareOp.EQUAL,
+ new SubstringComparator(QUICK_SUBSTR));
+ }
+
+ private Filter regexFilterNew() {
+ return new SingleColumnValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
+ CompareOp.EQUAL,
+ new RegexStringComparator(QUICK_REGEX));
+ }
+
+ private void basicFilterTests(Filter filter)
+ throws Exception {
+ KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1);
+ assertFalse("basicFilter1", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2);
+ assertTrue("basicFilter2", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_3);
+ assertTrue("basicFilter3", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_4);
+ assertTrue("basicFilter4", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ assertFalse("basicFilterAllRemaining", filter.filterAllRemaining());
+ assertFalse("basicFilterNotNull", filter.filterRow());
+ }
+
+ private void substrFilterTests(Filter filter)
+ throws Exception {
+ KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
+ FULLSTRING_1);
+ assertTrue("substrTrue",
+ filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
+ FULLSTRING_2);
+ assertFalse("substrFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ assertFalse("substrFilterAllRemaining", filter.filterAllRemaining());
+ assertFalse("substrFilterNotNull", filter.filterRow());
+ }
+
+ private void regexFilterTests(Filter filter)
+ throws Exception {
+ KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
+ FULLSTRING_1);
+ assertTrue("regexTrue",
+ filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
+ FULLSTRING_2);
+ assertFalse("regexFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
+ assertFalse("regexFilterAllRemaining", filter.filterAllRemaining());
+ assertFalse("regexFilterNotNull", filter.filterRow());
+ }
+
+ private Filter serializationTest(Filter filter)
+ throws Exception {
+ // Decompose filter to bytes.
+ ByteArrayOutputStream stream = new ByteArrayOutputStream();
+ DataOutputStream out = new DataOutputStream(stream);
+ filter.write(out);
+ out.close();
+ byte[] buffer = stream.toByteArray();
+
+ // Recompose filter.
+ DataInputStream in =
+ new DataInputStream(new ByteArrayInputStream(buffer));
+ Filter newFilter = new SingleColumnValueFilter();
+ newFilter.readFields(in);
+
+ return newFilter;
+ }
+
+ /**
+ * Tests identification of the stop row
+ * @throws Exception
+ */
+ public void testStop() throws Exception {
+ basicFilterTests(basicFilter);
+ substrFilterTests(substrFilter);
+ regexFilterTests(regexFilter);
+ }
+
+ /**
+ * Tests serialization
+ * @throws Exception
+ */
+ public void testSerialization() throws Exception {
+ Filter newFilter = serializationTest(basicFilter);
+ basicFilterTests(newFilter);
+ newFilter = serializationTest(substrFilter);
+ substrFilterTests(newFilter);
+ newFilter = serializationTest(regexFilter);
+ regexFilterTests(newFilter);
+ }
+}
\ No newline at end of file
Modified: hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestValueFilter.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestValueFilter.java?rev=810733&r1=810732&r2=810733&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestValueFilter.java (original)
+++ hadoop/hbase/trunk/src/test/org/apache/hadoop/hbase/filter/TestValueFilter.java Wed Sep 2 23:23:52 2009
@@ -1,160 +0,0 @@
-/**
- * Copyright 2007 The Apache Software Foundation
- *
- * 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.hadoop.hbase.filter;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.util.List;
-
-import org.apache.hadoop.hbase.KeyValue;
-import org.apache.hadoop.hbase.util.Bytes;
-
-import junit.framework.TestCase;
-
-/**
- * Tests the value filter
- */
-public class TestValueFilter extends TestCase {
- private static final byte[] ROW = Bytes.toBytes("test");
- private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
- private static final byte [] COLUMN_QUALIFIER = Bytes.toBytes("foo");
- private static final byte[] VAL_1 = Bytes.toBytes("a");
- private static final byte[] VAL_2 = Bytes.toBytes("ab");
- private static final byte[] VAL_3 = Bytes.toBytes("abc");
- private static final byte[] VAL_4 = Bytes.toBytes("abcd");
- private static final byte[] FULLSTRING_1 =
- Bytes.toBytes("The quick brown fox jumps over the lazy dog.");
- private static final byte[] FULLSTRING_2 =
- Bytes.toBytes("The slow grey fox trips over the lazy dog.");
- private static final String QUICK_SUBSTR = "quick";
- private static final String QUICK_REGEX = ".+quick.+";
-
- Filter basicFilter;
- Filter substrFilter;
- Filter regexFilter;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- basicFilter = basicFilterNew();
- substrFilter = substrFilterNew();
- regexFilter = regexFilterNew();
- }
-
- private Filter basicFilterNew() {
- return new ValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
- ValueFilter.CompareOp.GREATER_OR_EQUAL, VAL_2);
- }
-
- private Filter substrFilterNew() {
- return new ValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
- ValueFilter.CompareOp.EQUAL,
- new SubstringComparator(QUICK_SUBSTR));
- }
-
- private Filter regexFilterNew() {
- return new ValueFilter(COLUMN_FAMILY, COLUMN_QUALIFIER,
- ValueFilter.CompareOp.EQUAL,
- new RegexStringComparator(QUICK_REGEX));
- }
-
- private void basicFilterTests(Filter filter)
- throws Exception {
- KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1);
- assertFalse("basicFilter1", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_2);
- assertTrue("basicFilter2", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_3);
- assertTrue("basicFilter3", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_4);
- assertTrue("basicFilter4", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- assertFalse("basicFilterAllRemaining", filter.filterAllRemaining());
- assertTrue("basicFilterNotNull", filter.filterRow());
- }
-
- private void substrFilterTests(Filter filter)
- throws Exception {
- KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
- FULLSTRING_1);
- assertTrue("substrTrue",
- filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
- FULLSTRING_2);
- assertFalse("substrFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- assertFalse("substrFilterAllRemaining", filter.filterAllRemaining());
- assertTrue("substrFilterNotNull", filter.filterRow());
- }
-
- private void regexFilterTests(Filter filter)
- throws Exception {
- KeyValue kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
- FULLSTRING_1);
- assertTrue("regexTrue",
- filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- kv = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER,
- FULLSTRING_2);
- assertFalse("regexFalse", filter.filterKeyValue(kv) == Filter.ReturnCode.INCLUDE);
- assertFalse("regexFilterAllRemaining", filter.filterAllRemaining());
- assertTrue("regexFilterNotNull", filter.filterRow());
- }
-
- private Filter serializationTest(Filter filter)
- throws Exception {
- // Decompose filter to bytes.
- ByteArrayOutputStream stream = new ByteArrayOutputStream();
- DataOutputStream out = new DataOutputStream(stream);
- filter.write(out);
- out.close();
- byte[] buffer = stream.toByteArray();
-
- // Recompose filter.
- DataInputStream in =
- new DataInputStream(new ByteArrayInputStream(buffer));
- Filter newFilter = new ValueFilter();
- newFilter.readFields(in);
-
- return newFilter;
- }
-
- /**
- * Tests identification of the stop row
- * @throws Exception
- */
- public void testStop() throws Exception {
- basicFilterTests(basicFilter);
- substrFilterTests(substrFilter);
- regexFilterTests(regexFilter);
- }
-
- /**
- * Tests serialization
- * @throws Exception
- */
- public void testSerialization() throws Exception {
- Filter newFilter = serializationTest(basicFilter);
- basicFilterTests(newFilter);
- newFilter = serializationTest(substrFilter);
- substrFilterTests(newFilter);
- newFilter = serializationTest(regexFilter);
- regexFilterTests(newFilter);
- }
-}