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