HBASE-19809 Fix findbugs and error-prone warnings in hbase-procedure (branch-2)
[hbase.git] / hbase-native-client / src / async / mutations-test.cc
blobbe5898ec95d4917f3894fa1814b699e3fb7d6570
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <pthread.h>
22 #include "gtest/gtest.h"
23 #include "async/hbase_mutations.h"
24 #include "async/hbase_client.h"
26 pthread_cond_t cv;
27 pthread_mutex_t mutex;
29 bool sent = false;
31 TEST(ClientTest, EasyTest) {
32 EXPECT_EQ(1, 1);
35 void mutate_cb(int32_t status,
36 hb_client_t client, hb_mutation_t mutation,
37 hb_result_t result, void * extra) {
39 // Test Stuff.
40 EXPECT_EQ(status, 0);
41 EXPECT_TRUE(client != NULL);
42 EXPECT_TRUE(mutation != NULL);
44 pthread_mutex_lock(&mutex);
45 sent = true;
46 pthread_cond_signal(&cv);
47 pthread_mutex_unlock(&mutex);
50 void wait_send() {
51 pthread_mutex_lock(&mutex);
52 while (!sent) {
53 pthread_cond_wait(&cv, &mutex);
55 pthread_mutex_unlock(&mutex);
58 TEST(MutationTest, TestPut) {
59 char tn[] = "T1";
60 hb_byte_t row[] = "ROW";
61 char fam[] = "D";
62 hb_byte_t qual[] = "QUAL";
63 hb_byte_t data[] = "Z";
65 hb_client_t client = NULL;
66 hb_put_t put = NULL;
67 hb_cell_t cell;
69 cell.family = fam;
70 cell.family_length = 1;
72 cell.qual = qual;
73 cell.qual_length = 4;
75 cell.value = data;
76 cell.value_length = 1;
78 int32_t status = -1;
80 status = hb_client_create(&client, NULL);
81 EXPECT_EQ(0, status);
83 hb_put_create(&put);
84 hb_mutation_set_table((hb_mutation_t) put, tn, 2);
85 hb_mutation_set_row((hb_mutation_t) put, row, 3);
86 hb_put_add_cell(put, &cell);
88 pthread_cond_init(&cv, NULL);
89 pthread_mutex_init(&mutex, NULL);
91 status = hb_mutation_send(client, (hb_mutation_t) put, &mutate_cb, NULL);
92 EXPECT_EQ(0, status);
94 // Now wait a while for things to send.
95 wait_send();
96 EXPECT_EQ(true, sent);
98 hb_mutation_destroy((hb_mutation_t *) put);
99 hb_client_destroy(client, NULL, NULL);
101 EXPECT_EQ(0, status);