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