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