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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
;
21 import java
.nio
.ByteBuffer
;
22 import java
.util
.ArrayList
;
23 import java
.util
.List
;
25 import org
.slf4j
.Logger
;
26 import org
.slf4j
.LoggerFactory
;
30 * Code shared by PE tests.
32 public class PerformanceEvaluationCommons
{
33 private static final Logger LOG
=
34 LoggerFactory
.getLogger(PerformanceEvaluationCommons
.class.getName());
36 public static void assertValueSize(final int expectedSize
, final int got
) {
37 if (got
!= expectedSize
) {
38 throw new AssertionError("Expected " + expectedSize
+ " but got " + got
);
42 public static void assertKey(final byte [] expected
, final ByteBuffer got
) {
43 byte [] b
= new byte[got
.limit()];
44 got
.get(b
, 0, got
.limit());
45 assertKey(expected
, b
);
48 public static void assertKey(final byte [] expected
, final Cell c
) {
49 assertKey(expected
, c
.getRowArray(), c
.getRowOffset(), c
.getRowLength());
52 public static void assertKey(final byte [] expected
, final byte [] got
) {
53 assertKey(expected
, got
, 0, got
.length
);
56 public static void assertKey(final byte [] expected
, final byte [] gotArray
,
57 final int gotArrayOffset
, final int gotArrayLength
) {
58 if (!org
.apache
.hadoop
.hbase
.util
.Bytes
.equals(expected
, 0, expected
.length
,
59 gotArray
, gotArrayOffset
, gotArrayLength
)) {
60 throw new AssertionError("Expected " +
61 org
.apache
.hadoop
.hbase
.util
.Bytes
.toString(expected
) +
63 org
.apache
.hadoop
.hbase
.util
.Bytes
.toString(gotArray
, gotArrayOffset
, gotArrayLength
));
67 public static void concurrentReads(final Runnable r
) {
69 long now
= System
.currentTimeMillis();
70 List
<Thread
> threads
= new ArrayList
<>(count
);
71 for (int i
= 0; i
< count
; i
++) {
72 threads
.add(new Thread(r
, "concurrentRead-" + i
));
74 for (Thread t
: threads
) {
77 for (Thread t
: threads
) {
80 } catch (InterruptedException e
) {
84 LOG
.info("Test took " + (System
.currentTimeMillis() - now
));