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 byte [] got) {
49 if (!org.apache.hadoop.hbase.util.Bytes.equals(expected, got)) {
50 throw new AssertionError("Expected " +
51 org.apache.hadoop.hbase.util.Bytes.toString(expected) +
52 " but got " + org.apache.hadoop.hbase.util.Bytes.toString(got));
53 }
54 }
55
56 public static void concurrentReads(final Runnable r) {
57 final int count = 1;
58 long now = System.currentTimeMillis();
59 List<Thread> threads = new ArrayList<Thread>(count);
60 for (int i = 0; i < count; i++) {
61 Thread t = new Thread(r);
62 t.setName("" + i);
63 threads.add(t);
64 }
65 for (Thread t: threads) {
66 t.start();
67 }
68 for (Thread t: threads) {
69 try {
70 t.join();
71 } catch (InterruptedException e) {
72 e.printStackTrace();
73 }
74 }
75 LOG.info("Test took " + (System.currentTimeMillis() - now));
76 }
77 }