use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TPCCSimulation method doPayment.
/** Executes a payment transaction. */
public void doPayment() throws IOException {
int x = generator.number(1, 100);
int y = generator.number(1, 100);
short w_id = generateWarehouseId();
byte d_id = generateDistrict();
short c_w_id;
byte c_d_id;
if (parameters.warehouses == 1 || x <= 85) {
// 85%: paying through own warehouse (or there is only 1 warehouse)
c_w_id = w_id;
c_d_id = d_id;
} else {
// 15%: paying through another warehouse:
// select in range [1, num_warehouses] excluding w_id
c_w_id = (short) generator.numberExcluding(1, parameters.warehouses, w_id);
assert c_w_id != w_id;
c_d_id = generateDistrict();
}
double h_amount = generator.fixedPoint(2, Constants.MIN_PAYMENT, Constants.MAX_PAYMENT);
TimestampType now = clock.getDateTime();
if (y <= 60) {
// 60%: payment by last name
String c_last = generator.makeRandomLastName(parameters.customersPerDistrict);
client.callPaymentByName(w_id, d_id, h_amount, c_w_id, c_d_id, c_last, now);
} else {
// 40%: payment by id
assert y > 60;
client.callPaymentById(w_id, d_id, h_amount, c_w_id, c_d_id, generateCID(), now);
}
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class PassAllArgTypes method run.
public VoltTable[] run(byte b, byte[] bArray, short s, short[] sArray, int i, int[] iArray, long l, long[] lArray, String str, byte[] bString, TimestampType tst, java.util.Date utild, java.sql.Date sqld, java.sql.Timestamp ts) throws VoltAbortException {
if (b != 100)
throw new VoltAbortException();
if (bArray[0] != 100 || bArray[1] != 101 || bArray[2] != 102)
throw new VoltAbortException();
if (s != 32000)
throw new VoltAbortException();
if (sArray[0] != 32000 || sArray[1] != 32001 || sArray[2] != 32002)
throw new VoltAbortException();
if (i != 2147483640)
throw new VoltAbortException();
if (iArray[0] != 2147483640 || iArray[1] != 2147483641 || iArray[2] != 2147483642)
throw new VoltAbortException();
if (l != Long.MAX_VALUE - 10)
throw new VoltAbortException();
if (lArray[0] != Long.MAX_VALUE - 10 || lArray[1] != Long.MAX_VALUE - 9 || lArray[2] != Long.MAX_VALUE - 8)
throw new VoltAbortException();
if (!str.equals("foo"))
throw new VoltAbortException();
try {
if (!(new String(bString, "UTF-8").equals("bar")))
throw new VoltAbortException();
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
if (!tst.equals(new TimestampType(MILLISECONDS_SINCE_EPOCH_TEST_VALUE * 1000))) {
throw new VoltAbortException();
}
if (!utild.equals(new java.util.Date(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
throw new VoltAbortException();
}
if (!sqld.equals(new java.sql.Date(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
throw new VoltAbortException();
}
if (!ts.equals(new java.sql.Timestamp(MILLISECONDS_SINCE_EPOCH_TEST_VALUE))) {
throw new VoltAbortException();
}
VoltTable result0 = new VoltTable(new VoltTable.ColumnInfo("b", VoltType.typeFromClass(byte.class)), new VoltTable.ColumnInfo("bArray", VoltType.typeFromClass(byte[].class)), new VoltTable.ColumnInfo("s", VoltType.typeFromClass(short.class)), // new VoltTable.ColumnInfo("sArray", VoltType.typeFromClass(short[].class)),
new VoltTable.ColumnInfo("i", VoltType.typeFromClass(int.class)), // new VoltTable.ColumnInfo("iArray", VoltType.typeFromClass(int[].class)),
new VoltTable.ColumnInfo("l", VoltType.typeFromClass(long.class)), // new VoltTable.ColumnInfo("lArray", VoltType.typeFromClass(long[].class)),
new VoltTable.ColumnInfo("str", VoltType.typeFromClass(String.class)), new VoltTable.ColumnInfo("bString", VoltType.typeFromClass(byte[].class)), new VoltTable.ColumnInfo("tst", VoltType.typeFromClass(TimestampType.class)), new VoltTable.ColumnInfo("utild", VoltType.typeFromClass(java.util.Date.class)), new VoltTable.ColumnInfo("sqld", VoltType.typeFromClass(java.sql.Date.class)), new VoltTable.ColumnInfo("ts", VoltType.typeFromClass(java.sql.Timestamp.class)));
result0.addRow(b, bArray, s, /*sArray,*/
i, /*iArray,*/
l, /*lArray,*/
str, bString, tst, utild, sqld, ts);
VoltTable result1 = new VoltTable(new VoltTable.ColumnInfo("sArray", VoltType.typeFromClass(short.class)));
for (int j = 0; j < sArray.length; j++) {
result1.addRow(sArray[j]);
}
VoltTable result2 = new VoltTable(new VoltTable.ColumnInfo("iArray", VoltType.typeFromClass(int.class)));
for (int j = 0; j < iArray.length; j++) {
result2.addRow(iArray[j]);
}
VoltTable result3 = new VoltTable(new VoltTable.ColumnInfo("lArray", VoltType.typeFromClass(long.class)));
for (int j = 0; j < lArray.length; j++) {
result3.addRow(lArray[j]);
}
return new VoltTable[] { result0, result1, result2, result3 };
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class AllTypesUpdateJavaAbort method run.
public long run(int id) {
// update 100 times using different values
byte base = 1;
for (int i = 0; i < 100; i++, base++) {
char[] uninlineable = new char[1000];
for (int j = 0; j < uninlineable.length; j++) uninlineable[j] = (char) (base + 32);
voltQueueSQL(update, base + 1, base + 2, base + 3, new TimestampType().getTime(), (double) base / 100.0, new BigDecimal(base), String.valueOf(base + 32), String.valueOf(uninlineable), id);
}
long tupleChanged = voltExecuteSQL()[0].asScalarLong();
assert (tupleChanged > 0);
throw new VoltAbortException("Hungry Chicken");
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class AllTypesUpdateJavaError method run.
public long run(int id) {
// update 100 times using different values
byte base = 1;
for (int i = 0; i < 100; i++, base++) {
char[] uninlineable = new char[1000];
for (int j = 0; j < uninlineable.length; j++) uninlineable[j] = (char) (base + 32);
voltQueueSQL(update, base + 1, base + 2, base + 3, new TimestampType().getTime(), (double) base / 100.0, new BigDecimal(base), String.valueOf(base + 32), String.valueOf(uninlineable), id);
}
long tupleChanged = voltExecuteSQL()[0].asScalarLong();
assert (tupleChanged > 0);
// divide by 0 to ensure the transaction gets rolled back
return (5 / 0);
}
use of org.voltdb.types.TimestampType in project voltdb by VoltDB.
the class TestTPCCSuite method testPAYMENT.
public void testPAYMENT() throws IOException, ProcCallException {
Client client = getClient();
// create a District, Warehouse, and 4 Customers (multiple, since we
// want to test for correct behavior of paymentByCustomerName.
// long d_id, long d_w_id, String d_name, String d_street_1, String
// d_street_2, String d_city, String d_state, String d_zip, double
// d_tax, double d_ytd, long d_next_o_id
final double initialYTD = 15241.45;
VoltTable district = client.callProcedure("InsertDistrict", D_ID, W_ID, "A District", "Street Addy", "meh", "westerfield", "BA", "99999", .0825, initialYTD, 21L).getResults()[0];
// check that a district was inserted
assertEquals(1L, district.asScalarLong());
// long w_id, String w_name, String w_street_1, String w_street_2,
// String w_city, String w_zip, double w_tax, long w_ytd
VoltTable warehouse = client.callProcedure("InsertWarehouse", W_ID, "EZ Street WHouse", "Headquarters", "77 Mass. Ave.", "Cambridge", "AZ", "12938", .1234, initialYTD).getResults()[0];
// check for successful insertion.
assertEquals(1L, warehouse.asScalarLong());
// long c_id, long c_d_id, long c_w_id, String c_first, String c_middle,
// String c_last, String c_street_1, String c_street_2, String d_city,
// String d_state, String d_zip, String c_phone, Date c_since, String
// c_credit, double c_credit_lim, double c_discount, double c_balance,
// double c_ytd_payment, double c_payment_cnt, double c_delivery_cnt,
// String c_data
final double initialBalance = 15.75;
VoltTable customer1 = client.callProcedure("InsertCustomer", C_ID, D_ID, W_ID, "I", "Be", "lastname", "Place", "Place2", "BiggerPlace", "AL", "91083", "(193) 099 - 9082", new TimestampType(), "BC", 19298943.12, .13, initialBalance, initialYTD, 0L, 15L, "Some History").getResults()[0];
// check for successful insertion.
assertEquals(1L, customer1.asScalarLong());
VoltTable customer2 = client.callProcedure("InsertCustomer", C_ID + 1, D_ID, W_ID, "We", "R", "Customer", "Random Department", "Place2", "BiggerPlace", "AL", "13908", "(913) 909 - 0928", new TimestampType(), "GC", 19298943.12, .13, initialBalance, initialYTD, 1L, 15L, "Some History").getResults()[0];
// check for successful insertion.
assertEquals(1L, customer2.asScalarLong());
VoltTable customer3 = client.callProcedure("InsertCustomer", C_ID + 2, D_ID, W_ID, "Who", "Is", "Customer", "Receiving", "450 Mass F.X.", "BiggerPlace", "CI", "91083", "(541) 931 - 0928", new TimestampType(), "GC", 19899324.21, .13, initialBalance, initialYTD, 2L, 15L, "Some History").getResults()[0];
// check for successful insertion.
assertEquals(1L, customer3.asScalarLong());
VoltTable customer4 = client.callProcedure("InsertCustomer", C_ID + 3, D_ID, W_ID, "ICanBe", "", "Customer", "street", "place", "BiggerPlace", "MA", "91083", "(913) 909 - 0928", new TimestampType(), "GC", 19298943.12, .13, initialBalance, initialYTD, 3L, 15L, "Some History").getResults()[0];
// check for successful insertion.
assertEquals(1L, customer4.asScalarLong());
TPCDataPrinter.printAllData(client);
// long d_id, long w_id, double h_amount, String c_last, long c_w_id,
// long c_d_id
final double paymentAmount = 500.25;
VoltTable[] results = client.callProcedure("paymentByCustomerName", W_ID, D_ID, paymentAmount, W_ID, D_ID, "Customer", new TimestampType()).getResults();
assertEquals(3, results.length);
// check that the middle "Customer" was returned
assertEquals(C_ID + 1, results[2].fetchRow(0).getLong("c_id"));
assertEquals("", results[2].fetchRow(0).getString("c_data"));
// Verify that both warehouse, district and customer were updated
// correctly
VoltTable[] allTables = client.callProcedure("SelectAll").getResults();
warehouse = allTables[TPCDataPrinter.nameMap.get("WAREHOUSE")];
assertEquals(1, warehouse.getRowCount());
assertEquals(initialYTD + paymentAmount, warehouse.fetchRow(0).getDouble("W_YTD"));
district = allTables[TPCDataPrinter.nameMap.get("DISTRICT")];
assertEquals(1, district.getRowCount());
assertEquals(initialYTD + paymentAmount, district.fetchRow(0).getDouble("D_YTD"));
customer1 = allTables[TPCDataPrinter.nameMap.get("CUSTOMER")];
assertEquals(4, customer1.getRowCount());
assertEquals(C_ID + 1, customer1.fetchRow(1).getLong("C_ID"));
assertEquals(initialBalance - paymentAmount, customer1.fetchRow(1).getDouble("C_BALANCE"));
assertEquals(initialYTD + paymentAmount, customer1.fetchRow(1).getDouble("C_YTD_PAYMENT"));
assertEquals(2, customer1.fetchRow(1).getLong("C_PAYMENT_CNT"));
// long d_id, long w_id, double h_amount, String c_last, long c_w_id,
// long c_d_id
results = client.callProcedure("paymentByCustomerId", W_ID, D_ID, paymentAmount, W_ID, D_ID, C_ID, new TimestampType()).getResults();
// Also tests badcredit case.
assertEquals(3, results.length);
assertEquals(C_ID, results[2].fetchRow(0).getLong("c_id"));
// bad credit: insert history into c_data
String data = results[2].fetchRow(0).getString("c_data");
assertTrue(data.startsWith(new Long(C_ID).toString()));
// Verify that both warehouse and district's ytd values were incremented
// correctly
allTables = client.callProcedure("SelectAll").getResults();
warehouse = allTables[TPCDataPrinter.nameMap.get("WAREHOUSE")];
assertEquals(1, warehouse.getRowCount());
assertEquals(initialYTD + paymentAmount * 2, warehouse.fetchRow(0).getDouble("W_YTD"));
district = allTables[TPCDataPrinter.nameMap.get("DISTRICT")];
assertEquals(1, district.getRowCount());
assertEquals(initialYTD + paymentAmount * 2, district.fetchRow(0).getDouble("D_YTD"));
customer1 = allTables[TPCDataPrinter.nameMap.get("CUSTOMER")];
assertEquals(4, customer1.getRowCount());
assertEquals(C_ID, customer1.fetchRow(0).getLong("C_ID"));
assertEquals(initialBalance - paymentAmount, customer1.fetchRow(1).getDouble("C_BALANCE"));
assertEquals(initialYTD + paymentAmount, customer1.fetchRow(1).getDouble("C_YTD_PAYMENT"));
assertEquals(1, customer1.fetchRow(0).getLong("C_PAYMENT_CNT"));
}
Aggregations