View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  package org.apache.hadoop.hbase.mapred;
20  
21  import static org.mockito.Mockito.mock;
22  import static org.mockito.Mockito.times;
23  import static org.mockito.Mockito.verify;
24  
25  import java.io.IOException;
26  
27  import org.apache.hadoop.hbase.testclassification.SmallTests;
28  import org.apache.hadoop.hbase.client.Result;
29  import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
30  import org.apache.hadoop.mapred.OutputCollector;
31  import org.apache.hadoop.mapred.Reporter;
32  import org.junit.Test;
33  import org.junit.experimental.categories.Category;
34  import org.mockito.Mockito;
35  
36  @Category(SmallTests.class)
37  public class TestIdentityTableMap {
38  
39    @Test
40    @SuppressWarnings({ "deprecation", "unchecked" })
41    public void shouldCollectPredefinedTimes() throws IOException {
42      int recordNumber = 999;
43      Result resultMock = mock(Result.class);
44      IdentityTableMap identityTableMap = null;
45      try {
46        Reporter reporterMock = mock(Reporter.class);
47        identityTableMap = new IdentityTableMap();
48        ImmutableBytesWritable bytesWritableMock = mock(ImmutableBytesWritable.class);
49        OutputCollector<ImmutableBytesWritable, Result> outputCollectorMock =
50            mock(OutputCollector.class);
51    
52        for (int i = 0; i < recordNumber; i++)
53          identityTableMap.map(bytesWritableMock, resultMock, outputCollectorMock,
54              reporterMock);
55    
56        verify(outputCollectorMock, times(recordNumber)).collect(
57            Mockito.any(ImmutableBytesWritable.class), Mockito.any(Result.class));
58      } finally {
59        if (identityTableMap != null)
60          identityTableMap.close();
61      }
62    }
63  }