001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import org.apache.hadoop.hbase.HBaseClassTestRule; 021import org.apache.hadoop.hbase.testclassification.ClientTests; 022import org.apache.hadoop.hbase.testclassification.SmallTests; 023import org.apache.hadoop.hbase.util.Bytes; 024import org.junit.Assert; 025import org.junit.Before; 026import org.junit.ClassRule; 027import org.junit.Test; 028import org.junit.experimental.categories.Category; 029 030@Category({ClientTests.class, SmallTests.class}) 031/** 032 * Addresses HBASE-6047 033 * We test put.has call with all of its polymorphic magic 034 */ 035public class TestPutDotHas { 036 037 @ClassRule 038 public static final HBaseClassTestRule CLASS_RULE = 039 HBaseClassTestRule.forClass(TestPutDotHas.class); 040 041 public static final byte[] ROW_01 = Bytes.toBytes("row-01"); 042 public static final byte[] QUALIFIER_01 = Bytes.toBytes("qualifier-01"); 043 public static final byte[] VALUE_01 = Bytes.toBytes("value-01"); 044 public static final byte[] FAMILY_01 = Bytes.toBytes("family-01"); 045 public static final long TS = 1234567L; 046 public Put put = new Put(ROW_01); 047 048 @Before 049 public void setUp() { 050 put.addColumn(FAMILY_01, QUALIFIER_01, TS, VALUE_01); 051 } 052 053 @Test 054 public void testHasIgnoreValueIgnoreTS() { 055 Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01)); 056 Assert.assertFalse(put.has(QUALIFIER_01, FAMILY_01)); 057 } 058 059 @Test 060 public void testHasIgnoreValue() { 061 Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS)); 062 Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1)); 063 } 064 065 @Test 066 public void testHasIgnoreTS() { 067 Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, VALUE_01)); 068 Assert.assertFalse(put.has(FAMILY_01, VALUE_01, QUALIFIER_01)); 069 } 070 071 @Test 072 public void testHas() { 073 Assert.assertTrue(put.has(FAMILY_01, QUALIFIER_01, TS, VALUE_01)); 074 // Bad TS 075 Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS + 1, VALUE_01)); 076 // Bad Value 077 Assert.assertFalse(put.has(FAMILY_01, QUALIFIER_01, TS, QUALIFIER_01)); 078 // Bad Family 079 Assert.assertFalse(put.has(QUALIFIER_01, QUALIFIER_01, TS, VALUE_01)); 080 // Bad Qual 081 Assert.assertFalse(put.has(FAMILY_01, FAMILY_01, TS, VALUE_01)); 082 } 083}