Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -36,40 +36,35 @@
import org.apache.hadoop.hbase.client.Table;
import org.apache.hadoop.hbase.client.TableDescriptor;
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.MediumTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.AfterAll;

/**
* By using this class as the super class of a set of tests you will have a HBase testing cluster
* available that is very suitable for writing tests for scanning and filtering against.
*/
@Category({ FilterTests.class, MediumTests.class })
public class FilterTestingCluster {
private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();
private static Admin admin = null;
private static List<TableName> createdTables = new ArrayList<>();

protected static void createTable(TableName tableName, String columnFamilyName) {
assertNotNull("HBaseAdmin is not initialized successfully.", admin);
assertNotNull(admin, "HBaseAdmin is not initialized successfully.");
TableDescriptor tableDescriptor = TableDescriptorBuilder.newBuilder(tableName)
.setColumnFamily(ColumnFamilyDescriptorBuilder.of(Bytes.toBytes(columnFamilyName))).build();

try {
admin.createTable(tableDescriptor);
createdTables.add(tableName);
assertTrue("Fail to create the table", admin.tableExists(tableName));
assertTrue(admin.tableExists(tableName), "Fail to create the table");
} catch (IOException e) {
assertNull("Exception found while creating table", e);
assertNull(e, "Exception found while creating table");
}
}

protected static Table openTable(TableName tableName) throws IOException {
Table table = TEST_UTIL.getConnection().getTable(tableName);
assertTrue("Fail to create the table", admin.tableExists(tableName));
assertTrue(admin.tableExists(tableName), "Fail to create the table");
return table;
}

Expand All @@ -82,7 +77,7 @@ private static void deleteTables() {
admin.deleteTable(tableName);
}
} catch (IOException e) {
assertNull("Exception found deleting the table", e);
assertNull(e, "Exception found deleting the table");
}
}
}
Expand All @@ -94,21 +89,20 @@ private static void initialize(Configuration conf) {
try {
admin = TEST_UTIL.getAdmin();
} catch (MasterNotRunningException e) {
assertNull("Master is not running", e);
assertNull(e, "Master is not running");
} catch (ZooKeeperConnectionException e) {
assertNull("Cannot connect to ZooKeeper", e);
assertNull(e, "Cannot connect to ZooKeeper");
} catch (IOException e) {
assertNull("IOException", e);
assertNull(e, "IOException");
}
}

@BeforeClass
public static void setUp() throws Exception {
TEST_UTIL.startMiniCluster(1);
initialize(TEST_UTIL.getConfiguration());
}

@AfterClass
@AfterAll
public static void tearDown() throws Exception {
deleteTables();
TEST_UTIL.shutdownMiniCluster();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,46 +17,45 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.math.BigDecimal;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Assert;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

@Category({ FilterTests.class, SmallTests.class })
@Tag(FilterTests.TAG)
@Tag(SmallTests.TAG)
public class TestBigDecimalComparator {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBigDecimalComparator.class);

@Test
public void testObjectEquals() {
BigDecimal bd = new BigDecimal(Double.MIN_VALUE);
// Check that equals returns true for identical objects
final BigDecimalComparator bdc = new BigDecimalComparator(bd);
Assert.assertTrue(bdc.equals(bdc));
Assert.assertEquals(bdc.hashCode(), bdc.hashCode());
assertTrue(bdc.equals(bdc));
assertEquals(bdc.hashCode(), bdc.hashCode());

// Check that equals returns true for the same object
final BigDecimalComparator bdc1 = new BigDecimalComparator(bd);
final BigDecimalComparator bdc2 = new BigDecimalComparator(bd);
Assert.assertTrue(bdc1.equals(bdc2));
Assert.assertEquals(bdc1.hashCode(), bdc2.hashCode());
assertTrue(bdc1.equals(bdc2));
assertEquals(bdc1.hashCode(), bdc2.hashCode());

// Check that equals returns false for different objects
final BigDecimalComparator bdc3 = new BigDecimalComparator(bd);
final BigDecimalComparator bdc4 = new BigDecimalComparator(new BigDecimal(Long.MIN_VALUE));
Assert.assertFalse(bdc3.equals(bdc4));
Assert.assertNotEquals(bdc3.hashCode(), bdc4.hashCode());
assertFalse(bdc3.equals(bdc4));
assertNotEquals(bdc3.hashCode(), bdc4.hashCode());

// Check that equals returns false for a different type
final BigDecimalComparator bdc5 = new BigDecimalComparator(bd);
Assert.assertFalse(bdc5.equals(0));
assertFalse(bdc5.equals(0));
}

@Test
Expand All @@ -74,8 +73,8 @@ public void testEqualsValue() {
int comp2 = comparator2.compareTo(value2);

// then
Assert.assertEquals(0, comp1);
Assert.assertEquals(0, comp2);
assertEquals(0, comp1);
assertEquals(0, comp2);
}

@Test
Expand All @@ -93,9 +92,9 @@ public void testGreaterThanValue() {
int comp3 = comparator.compareTo(val3);

// then
Assert.assertEquals(1, comp1);
Assert.assertEquals(1, comp2);
Assert.assertEquals(1, comp3);
assertEquals(1, comp1);
assertEquals(1, comp2);
assertEquals(1, comp3);
}

@Test
Expand All @@ -113,9 +112,9 @@ public void testLessThanValue() {
int comp3 = comparator.compareTo(val3);

// then
Assert.assertEquals(-1, comp1);
Assert.assertEquals(-1, comp2);
Assert.assertEquals(-1, comp3);
assertEquals(-1, comp1);
assertEquals(-1, comp2);
assertEquals(-1, comp3);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,21 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.nio.ByteBuffer;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

/**
* Tests for the bit comparator
*/
@Category({ FilterTests.class, SmallTests.class })
@Tag(FilterTests.TAG)
@Tag(SmallTests.TAG)
public class TestBitComparator {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestBitComparator.class);

private static byte[] zeros = new byte[] { 0, 0, 0, 0, 0, 0 };
private static ByteBuffer zeros_bb = ByteBuffer.wrap(zeros);
private static byte[] ones = new byte[] { 1, 1, 1, 1, 1, 1 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;

import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
import org.apache.hadoop.hbase.shaded.protobuf.generated.FilterProtos;
Expand All @@ -37,13 +35,10 @@
* filter. More test functionality can be found within
* {@link org.apache.hadoop.hbase.filter.TestFilter#testColumnPaginationFilter()}
*/
@Category({ FilterTests.class, SmallTests.class })
@Tag(FilterTests.TAG)
@Tag(SmallTests.TAG)
public class TestColumnPaginationFilter {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestColumnPaginationFilter.class);

private static final byte[] ROW = Bytes.toBytes("row_1_test");
private static final byte[] COLUMN_FAMILY = Bytes.toBytes("test");
private static final byte[] VAL_1 = Bytes.toBytes("a");
Expand All @@ -52,7 +47,7 @@ public class TestColumnPaginationFilter {
private Filter columnPaginationFilterOffset;
private Filter columnPaginationFilter;

@Before
@BeforeEach
public void setUp() throws Exception {
columnPaginationFilter = getColumnPaginationFilter();
columnPaginationFilterOffset = getColumnPaginationFilterOffset();
Expand All @@ -79,7 +74,7 @@ private Filter serializationTest(Filter filter) throws Exception {
*/
private void basicFilterTests(ColumnPaginationFilter filter) throws Exception {
KeyValue c = new KeyValue(ROW, COLUMN_FAMILY, COLUMN_QUALIFIER, VAL_1);
assertTrue("basicFilter1", filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL);
assertTrue(filter.filterCell(c) == Filter.ReturnCode.INCLUDE_AND_NEXT_COL, "basicFilter1");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
*/
package org.apache.hadoop.hbase.filter;

import static org.junit.Assert.assertEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -27,7 +27,6 @@
import java.util.Map;
import java.util.Set;
import org.apache.hadoop.hbase.Cell;
import org.apache.hadoop.hbase.HBaseClassTestRule;
import org.apache.hadoop.hbase.HBaseTestingUtil;
import org.apache.hadoop.hbase.KeyValue;
import org.apache.hadoop.hbase.KeyValueTestUtil;
Expand All @@ -46,29 +45,21 @@
import org.apache.hadoop.hbase.testclassification.FilterTests;
import org.apache.hadoop.hbase.testclassification.SmallTests;
import org.apache.hadoop.hbase.util.Bytes;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.rules.TestName;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInfo;

@Category({ FilterTests.class, SmallTests.class })
@Tag(FilterTests.TAG)
@Tag(SmallTests.TAG)
public class TestColumnPrefixFilter {

@ClassRule
public static final HBaseClassTestRule CLASS_RULE =
HBaseClassTestRule.forClass(TestColumnPrefixFilter.class);

private final static HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil();

@Rule
public TestName name = new TestName();

@Test
public void testColumnPrefixFilter() throws IOException {
public void testColumnPrefixFilter(TestInfo testInfo) throws IOException {
String family = "Family";
TableDescriptorBuilder tableDescriptorBuilder =
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder
.newBuilder(TableName.valueOf(testInfo.getTestMethod().get().getName()));
ColumnFamilyDescriptor columnFamilyDescriptor =
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).setMaxVersions(3).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
Expand Down Expand Up @@ -130,10 +121,10 @@ public void testColumnPrefixFilter() throws IOException {
}

@Test
public void testColumnPrefixFilterWithFilterList() throws IOException {
public void testColumnPrefixFilterWithFilterList(TestInfo testInfo) throws IOException {
String family = "Family";
TableDescriptorBuilder tableDescriptorBuilder =
TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName()));
TableDescriptorBuilder tableDescriptorBuilder = TableDescriptorBuilder
.newBuilder(TableName.valueOf(testInfo.getTestMethod().get().getName()));
ColumnFamilyDescriptor columnFamilyDescriptor =
ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes(family)).setMaxVersions(3).build();
tableDescriptorBuilder.setColumnFamily(columnFamilyDescriptor);
Expand Down
Loading