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.mapred; 019 020import static org.mockito.Mockito.mock; 021import static org.mockito.Mockito.times; 022import static org.mockito.Mockito.verify; 023 024import java.io.IOException; 025import org.apache.hadoop.hbase.HBaseClassTestRule; 026import org.apache.hadoop.hbase.client.Result; 027import org.apache.hadoop.hbase.io.ImmutableBytesWritable; 028import org.apache.hadoop.hbase.testclassification.MapReduceTests; 029import org.apache.hadoop.hbase.testclassification.SmallTests; 030import org.apache.hadoop.mapred.OutputCollector; 031import org.apache.hadoop.mapred.Reporter; 032import org.junit.ClassRule; 033import org.junit.Test; 034import org.junit.experimental.categories.Category; 035import org.mockito.Mockito; 036 037@Category({ MapReduceTests.class, SmallTests.class }) 038public class TestIdentityTableMap { 039 040 @ClassRule 041 public static final HBaseClassTestRule CLASS_RULE = 042 HBaseClassTestRule.forClass(TestIdentityTableMap.class); 043 044 @Test 045 @SuppressWarnings({ "deprecation", "unchecked" }) 046 public void shouldCollectPredefinedTimes() throws IOException { 047 int recordNumber = 999; 048 Result resultMock = mock(Result.class); 049 IdentityTableMap identityTableMap = null; 050 try { 051 Reporter reporterMock = mock(Reporter.class); 052 identityTableMap = new IdentityTableMap(); 053 ImmutableBytesWritable bytesWritableMock = mock(ImmutableBytesWritable.class); 054 OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock = 055 mock(OutputCollector.class); 056 057 for (int i = 0; i < recordNumber; i++) 058 identityTableMap.map(bytesWritableMock, resultMock, outputCollectorMock, reporterMock); 059 060 verify(outputCollectorMock, times(recordNumber)).collect(Mockito.any(), Mockito.any()); 061 } finally { 062 if (identityTableMap != null) identityTableMap.close(); 063 } 064 } 065}