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.example; 019 020import static org.junit.Assert.assertEquals; 021import static org.junit.Assert.assertNotEquals; 022 023import org.apache.hadoop.hbase.HBaseClassTestRule; 024import org.apache.hadoop.hbase.HBaseTestingUtility; 025import org.apache.hadoop.hbase.TableName; 026import org.apache.hadoop.hbase.client.Table; 027import org.apache.hadoop.hbase.testclassification.ClientTests; 028import org.apache.hadoop.hbase.testclassification.MediumTests; 029import org.apache.hadoop.hbase.util.Bytes; 030import org.junit.AfterClass; 031import org.junit.BeforeClass; 032import org.junit.ClassRule; 033import org.junit.Test; 034import org.junit.experimental.categories.Category; 035 036@Category({ ClientTests.class, MediumTests.class }) 037public class TestMultiThreadedClientExample { 038 039 private final static HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); 040 private static String tableName = "test_mt_table"; 041 private static Table table; 042 static final TableName MY_TABLE_NAME = TableName.valueOf(tableName); 043 private static byte[] familyName = Bytes.toBytes("d"); 044 private static byte[] columnName = Bytes.toBytes("col"); 045 046 @ClassRule 047 public static final HBaseClassTestRule CLASS_RULE = 048 HBaseClassTestRule.forClass(TestMultiThreadedClientExample.class); 049 050 @BeforeClass 051 public static void setup() throws Exception { 052 TEST_UTIL.startMiniCluster(1); 053 table = TEST_UTIL.createTable(MY_TABLE_NAME, familyName); 054 } 055 056 @AfterClass 057 public static void tearDown() throws Exception { 058 TEST_UTIL.deleteTable(MY_TABLE_NAME); 059 TEST_UTIL.shutdownMiniCluster(); 060 } 061 062 @Test 063 public void testMultiThreadedClientExample() throws Exception { 064 MultiThreadedClientExample example = new MultiThreadedClientExample(); 065 example.setConf(TEST_UTIL.getConfiguration()); 066 String[] args = { tableName, "200" }; 067 // Define assertions to check the returned data here 068 assertEquals(0, example.run(args)); 069 // Define assertions to check the row count of the table 070 int rows = TEST_UTIL.countRows(table); 071 assertNotEquals(0, rows); 072 } 073}