-
Notifications
You must be signed in to change notification settings - Fork 177
/
RegressionSuiteUtil.java
188 lines (169 loc) · 7.41 KB
/
RegressionSuiteUtil.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
package org.voltdb.regressionsuites;
import java.io.IOException;
import java.util.Random;
import junit.framework.TestCase;
import org.voltdb.CatalogContext;
import org.voltdb.SysProcSelector;
import org.voltdb.VoltSystemProcedure;
import org.voltdb.VoltTable;
import org.voltdb.VoltType;
import org.voltdb.benchmark.tpcc.TPCCConstants;
import org.voltdb.benchmark.tpcc.TPCCLoader;
import org.voltdb.benchmark.tpcc.TPCCSimulation;
import org.voltdb.catalog.Column;
import org.voltdb.catalog.Table;
import org.voltdb.client.Client;
import org.voltdb.client.ClientResponse;
import org.voltdb.client.ProcCallException;
import org.voltdb.sysprocs.LoadMultipartitionTable;
import org.voltdb.sysprocs.SetConfiguration;
import org.voltdb.sysprocs.Statistics;
import org.voltdb.types.TimestampType;
import org.voltdb.utils.VoltTypeUtil;
import edu.brown.benchmark.tm1.TM1Loader;
import edu.brown.catalog.CatalogUtil;
import edu.brown.hstore.Hstoreservice.Status;
import edu.brown.hstore.conf.HStoreConf;
import edu.brown.rand.DefaultRandomGenerator;
public abstract class RegressionSuiteUtil {
static final double SCALEFACTOR = 0.0001;
private static final DefaultRandomGenerator rng = new DefaultRandomGenerator(0);
public static ClientResponse setHStoreConf(Client client, String paramName, Object paramValue) throws Exception {
assert(HStoreConf.isConfParameter(paramName)) :
"Invalid HStoreConf parameter '" + paramName + "'";
String procName = VoltSystemProcedure.procCallName(SetConfiguration.class);
String confParams[] = {paramName};
String confValues[] = {paramValue.toString()};
ClientResponse cresponse = client.callProcedure(procName, confParams, confValues);
assert(cresponse.getStatus() == Status.OK) : cresponse.toString();
return (cresponse);
}
public static ClientResponse getStats(Client client, SysProcSelector statsType) throws Exception {
String procName = VoltSystemProcedure.procCallName(Statistics.class);
Object params[] = { statsType.name(), 0 };
ClientResponse cresponse = client.callProcedure(procName, params);
assert(cresponse.getStatus() == Status.OK) : cresponse.toString();
return (cresponse);
}
public static long getRowCount(Client client, String tableName) throws Exception {
ClientResponse cresponse = getStats(client, SysProcSelector.TABLE);
VoltTable result = cresponse.getResults()[0];
long count = 0;
boolean found = false;
while (result.advanceRow()) {
if (tableName.equalsIgnoreCase(result.getString("TABLE_NAME"))) {
found = true;
count += result.getLong("TUPLE_COUNT");
}
} // WHILE
if (found == false) {
throw new IllegalArgumentException("Invalid table '" + tableName + "'");
}
return (count);
}
/**
* Populate the given table with a bunch of random tuples
* @param client
* @param catalog_tbl
* @param rand
* @param num_tuples
* @throws IOException
* @throws ProcCallException
*/
public static void loadRandomData(Client client, Table catalog_tbl, Random rand, int num_tuples) throws IOException, ProcCallException {
VoltTable vt = CatalogUtil.getVoltTable(catalog_tbl);
int num_cols = catalog_tbl.getColumns().size();
VoltType types[] = new VoltType[num_cols];
int maxSizes[] = new int[num_cols];
for (Column catalog_col : catalog_tbl.getColumns()) {
int idx = catalog_col.getIndex();
types[idx] = VoltType.get(catalog_col.getType());
if (types[idx] == VoltType.STRING) {
maxSizes[idx] = catalog_col.getSize();
}
} // FOR
for (int i = 0; i < num_tuples; i++) {
Object row[] = new Object[num_cols];
for (int col = 0; col < num_cols; col++) {
row[col] = VoltTypeUtil.getRandomValue(types[col], rand);
if (types[col] == VoltType.STRING) {
if (row[col].toString().length() >= maxSizes[col]) {
row[col] = row[col].toString().substring(0, maxSizes[col]-1);
}
}
} // FOR (col)
vt.addRow(row);
} // FOR (row)
// System.err.printf("Loading %d rows for %s\n%s\n\n", vt.getRowCount(), catalog_tbl, vt.toString());
String procName = VoltSystemProcedure.procCallName(LoadMultipartitionTable.class);
ClientResponse cr = client.callProcedure(procName, catalog_tbl.getName(), vt);
TestCase.assertEquals(Status.OK, cr.getStatus());
}
public static final void initializeTPCCDatabase(final CatalogContext catalogContext, final Client client) throws Exception {
String args[] = {
"NOCONNECTIONS=true",
"BENCHMARK.WAREHOUSE_PER_PARTITION=true",
"BENCHMARK.NUM_LOADTHREADS=1",
};
TPCCLoader loader = new TPCCLoader(args) {
{
this.setCatalogContext(catalogContext);
this.setClientHandle(client);
}
@Override
public CatalogContext getCatalogContext() {
return (catalogContext);
}
};
loader.load();
}
public static final void initializeTM1Database(final CatalogContext catalogContext, final Client client) throws Exception {
String args[] = { "NOCONNECTIONS=true", };
TM1Loader loader = new TM1Loader(args) {
{
this.setCatalogContext(catalogContext);
this.setClientHandle(client);
}
@Override
public CatalogContext getCatalogContext() {
return (catalogContext);
}
};
loader.load();
}
protected static Object[] generateNewOrder(int num_warehouses, boolean dtxn, int w_id, int d_id) throws Exception {
short supply_w_id;
if (dtxn) {
int start = TPCCConstants.STARTING_WAREHOUSE;
int stop = TPCCConstants.STARTING_WAREHOUSE + num_warehouses;
supply_w_id = TPCCSimulation.generatePairedWarehouse(w_id, start, stop);
assert(supply_w_id != w_id);
} else {
supply_w_id = (short)w_id;
}
// ORDER_LINE ITEMS
int num_items = rng.number(TPCCConstants.MIN_OL_CNT, TPCCConstants.MAX_OL_CNT);
int item_ids[] = new int[num_items];
short supwares[] = new short[num_items];
int quantities[] = new int[num_items];
for (int i = 0; i < num_items; i++) {
item_ids[i] = rng.nextInt((int)(TPCCConstants.NUM_ITEMS));
supwares[i] = (i == 1 && dtxn ? supply_w_id : (short)w_id);
quantities[i] = 1;
} // FOR
Object params[] = {
(short)w_id, // W_ID
(byte)d_id, // D_ID
1, // C_ID
new TimestampType(),// TIMESTAMP
item_ids, // ITEM_IDS
supwares, // SUPPLY W_IDS
quantities // QUANTITIES
};
return (params);
}
protected static Object[] generateNewOrder(int num_warehouses, boolean dtxn, short w_id) throws Exception {
int d_id = rng.number(1, TPCCConstants.DISTRICTS_PER_WAREHOUSE);
return generateNewOrder(num_warehouses, dtxn, w_id, d_id);
}
}