1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase;
20
21 import java.nio.ByteBuffer;
22 import java.util.ArrayList;
23 import java.util.List;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27
28
29
30
31
32 public class PerformanceEvaluationCommons {
33 static final Log LOG =
34 LogFactory.getLog(PerformanceEvaluationCommons.class.getName());
35
36 public static void assertValueSize(final int expectedSize, final int got) {
37 if (got != expectedSize) {
38 throw new AssertionError("Expected " + expectedSize + " but got " + got);
39 }
40 }
41
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);
46 }
47
48 public static void assertKey(final byte [] expected, final Cell c) {
49 assertKey(expected, c.getRowArray(), c.getRowOffset(), c.getRowLength());
50 }
51
52 public static void assertKey(final byte [] expected, final byte [] got) {
53 assertKey(expected, got, 0, got.length);
54 }
55
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) +
62 " but got " +
63 org.apache.hadoop.hbase.util.Bytes.toString(gotArray, gotArrayOffset, gotArrayLength));
64 }
65 }
66
67 public static void concurrentReads(final Runnable r) {
68 final int count = 1;
69 long now = System.currentTimeMillis();
70 List<Thread> threads = new ArrayList<Thread>(count);
71 for (int i = 0; i < count; i++) {
72 Thread t = new Thread(r);
73 t.setName("" + i);
74 threads.add(t);
75 }
76 for (Thread t: threads) {
77 t.start();
78 }
79 for (Thread t: threads) {
80 try {
81 t.join();
82 } catch (InterruptedException e) {
83 e.printStackTrace();
84 }
85 }
86 LOG.info("Test took " + (System.currentTimeMillis() - now));
87 }
88 }