// check count is 2, (not 3 or 1).
// FIXME assertEquals(2L, stockCount);
}
public void testNEWORDER() throws IOException, ProcCallException {
Client client = getClient();
final double W_TAX = 0.1234;
// 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", W_TAX, 18837.57).getResults()[0];
// check for successful insertion.
assertEquals(1L, warehouse.asScalarLong());
final double D_TAX = 0.0825;
final int D_NEXT_O_ID = 21;
// 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
VoltTable district = client.callProcedure("InsertDistrict", D_ID, W_ID,
"A District", "Street Addy", "meh", "westerfield", "BA",
"99999", D_TAX, 15241.45, D_NEXT_O_ID).getResults()[0];
// check that a district was inserted
assertEquals(1L, district.asScalarLong());
final double C_DISCOUNT = 0.13;
// 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
VoltTable customer = client.callProcedure("InsertCustomer", C_ID, D_ID,
W_ID, "I", "Is", "Name", "Place", "Place2", "BiggerPlace",
"AL", "91083", "(913) 909 - 0928", new TimestampType(), "GC",
19298943.12, C_DISCOUNT, 15.75, 18832.45, 45L, 15L,
"Some History").getResults()[0];
// check for successful insertion.
assertEquals(1L, customer.asScalarLong());
final int[] s_quantities = { 45, 85, 15 };
final long INITIAL_S_YTD = 5582L;
final long INITIAL_S_ORDER_CNT = 152L;
// long pkey, long s_i_id, long s_w_id, long s_quantity, String
// s_dist_01, String s_dist_02, String s_dist_03, String s_dist_04,
// String s_dist_05, String s_dist_06, String s_dist_07, String
// s_dist_08, String s_dist_09, String s_dist_10, long s_ytd, long
// s_order_cnt, long s_remote_cnt, String s_data
VoltTable stock1 = client.callProcedure("InsertStock", 4L, W_ID,
s_quantities[0], "INFO", "INFO", "INFO", "INFO", "INFO",
"INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD, INITIAL_S_ORDER_CNT, 32L,
"DATA").getResults()[0];
VoltTable stock2 = client.callProcedure("InsertStock", 5L, W_ID,
s_quantities[1], "INFO", "INFO", "INFO", "INFO", "INFO",
"INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD+10, INITIAL_S_ORDER_CNT+10,
32L, "foo" + TPCCConstants.ORIGINAL_STRING + "bar").getResults()[0];
VoltTable stock3 = client.callProcedure("InsertStock", 6L, W_ID,
s_quantities[2], "INFO", "INFO", "INFO", "INFO", "INFO",
"INFO", "INFO", "INFO", "INFO", "INFO", INITIAL_S_YTD+20, INITIAL_S_ORDER_CNT+20,
32L, "DATA").getResults()[0];
final double PRICE = 2341.23;
// long i_id, long i_im_id, String i_name, double i_price, String i_data
ClientResponse cr =
client.callProcedure("InsertItem", 4L, 4L, "ITEM1",
PRICE, TPCCConstants.ORIGINAL_STRING);
VoltTable item1 = cr.getResults()[0];
VoltTable item2 = client.callProcedure("InsertItem", 5L, 5L, "ITEM2",
PRICE, TPCCConstants.ORIGINAL_STRING).getResults()[0];
VoltTable item3 = client.callProcedure("InsertItem", 6L, 6L, "ITEM3",
PRICE, TPCCConstants.ORIGINAL_STRING).getResults()[0];
// check the inserts went through.
assertEquals(1L, stock1.asScalarLong());
assertEquals(1L, stock2.asScalarLong());
assertEquals(1L, stock3.asScalarLong());
assertEquals(1L, item1.asScalarLong());
assertEquals(1L, item2.asScalarLong());
assertEquals(1L, item3.asScalarLong());
// call the neworder transaction:
// if(ol_supply_w_id != w_id) all_local = 0;
// test all_local behavior, first, then remote warehouse situation.
// long w_id, long d_id, long c_id, long ol_cnt, long all_local, long[]
// item_id, long[] supware, long[] quantity
int[] items = { 4, 5, 6 };
short[] warehouses = { W_ID, W_ID, W_ID };
int[] quantities = { 3, 5, 1 };
TPCDataPrinter.printAllData(client);
TimestampType timestamp = new TimestampType();
VoltTable[] neworder = client.callProcedure(TPCCConstants.NEWORDER, W_ID, D_ID, C_ID,
timestamp, items, warehouses, quantities).getResults();
// Now to check returns are correct. We assume that inserts and such
// within the actual transaction went through since it didn't rollback
// and error out.
VoltTableRow customerData = neworder[0].fetchRow(0);
VoltTableRow miscData = neworder[1].fetchRow(0);
assertEquals("Name", customerData.getString("C_LAST"));
assertEquals("GC", customerData.getString("C_CREDIT"));
assertEquals(.13, customerData.getDouble("C_DISCOUNT"));
assertEquals(W_TAX, miscData.getDouble("w_tax"));
assertEquals(D_TAX, miscData.getDouble("d_tax"));
assertEquals(21L, miscData.getLong("o_id"));
final double AMOUNT = PRICE * (3 + 5 + 1) * (1 - C_DISCOUNT) * (1 + D_TAX + W_TAX);
assertEquals(AMOUNT, miscData.getDouble("total"), 0.001);
// Check each item
VoltTable itemResults = neworder[2];
assertEquals(quantities.length, itemResults.getRowCount());
for (int i = 0; i < itemResults.getRowCount(); ++i) {
VoltTableRow itemRow = itemResults.fetchRow(i);
assertEquals("ITEM" + (i + 1), itemRow.getString("i_name"));
//~ assertEquals(quantities[i], itemRow.getLong("));
long expected = s_quantities[i] - quantities[i];
if (expected < 10) expected += 91;
assertEquals(expected, itemRow.getLong("s_quantity"));
if (i == 1) {
assertEquals("B", itemRow.getString("brand_generic"));
} else {
assertEquals("G", itemRow.getString("brand_generic"));
}
assertEquals(PRICE, itemRow.getDouble("i_price"));
assertEquals(PRICE * quantities[i], itemRow.getDouble("ol_amount"));
}
// verify that stock was updated correctly
VoltTable[] allTables = client.callProcedure("SelectAll").getResults();
VoltTable stock = allTables[TPCDataPrinter.nameMap.get("STOCK")];
for (int i = 0; i < stock.getRowCount(); ++i) {
VoltTableRow stockRow = stock.fetchRow(i);
assertEquals(INITIAL_S_YTD + i*10 + quantities[i], stockRow.getLong("S_YTD"));
assertEquals(INITIAL_S_ORDER_CNT + i*10 + 1, stockRow.getLong("S_ORDER_CNT"));
}
// New order with a missing item
items = new int[] { TPCCConstants.NUM_ITEMS + 1 };
warehouses = new short[] { W_ID };
quantities = new int[] { 42 };
try {
client.callProcedure("neworder", W_ID, D_ID, C_ID, timestamp,
items, warehouses, quantities);
} catch (ProcCallException e) {
assertTrue(e.getMessage().indexOf(TPCCConstants.INVALID_ITEM_MESSAGE) > 0);
}
// Verify that we only inserted one new order
allTables = client.callProcedure("SelectAll").getResults();
TPCDataPrinter.nameMap.get("ORDERS");
// only 1 order, from the first new order call
district = allTables[TPCDataPrinter.nameMap.get("DISTRICT")];
assertEquals(1, district.getRowCount());
assertEquals(D_NEXT_O_ID + 1, district.fetchRow(0).getLong(