*/
public void testWeightedQueryEstimation() throws Exception {
// Make a new workload that has its single queries duplicated multiple times
Workload new_workload = new Workload(catalogContext.catalog);
int num_dupes = 7;
TransactionTrace multip_txn = this.getMultiPartitionTransaction();
Procedure catalog_proc = multip_txn.getCatalogItem(catalogContext.database);
final TransactionTrace orig_txn = (TransactionTrace)multip_txn.clone();
List<QueryTrace> clone_queries = new ArrayList<QueryTrace>();
for (int i = 0; i < num_dupes; i++) {
for (QueryTrace query_trace : multip_txn.getQueries()) {
QueryTrace clone_query = (QueryTrace)query_trace.clone();
clone_queries.add(clone_query);
} // FOR
} // FOR
orig_txn.setQueries(clone_queries);
new_workload.addTransaction(catalog_proc, orig_txn);
assertEquals(1, new_workload.getTransactionCount());
assertEquals(multip_txn.getQueryCount() * num_dupes, orig_txn.getQueryCount());
// We now want to calculate the cost of this new workload
final SingleSitedCostModel orig_costModel = new SingleSitedCostModel(catalogContext);
final double orig_cost = orig_costModel.estimateWorkloadCost(catalogContext, new_workload);
assert(orig_cost > 0);
TransactionCacheEntry orig_txnEntry = orig_costModel.getTransactionCacheEntry(orig_txn);
assertNotNull(orig_txnEntry);
assertEquals(orig_txn.getQueryCount(), orig_txnEntry.getExaminedQueryCount());
// System.err.println(orig_txnEntry.debug());
// System.err.println("=========================================");
// Now change make a new workload that has the same multi-partition transaction
// but this time it only has one but with a transaction weight
// We should get back the exact same cost
new_workload = new Workload(catalogContext.catalog);
final TransactionTrace new_txn = (TransactionTrace)multip_txn.clone();
clone_queries = new ArrayList<QueryTrace>();
for (QueryTrace query_trace : multip_txn.getQueries()) {
QueryTrace clone_query = (QueryTrace)query_trace.clone();
clone_query.setWeight(num_dupes);
clone_queries.add(clone_query);
} // FOR
new_txn.setQueries(clone_queries);
new_workload.addTransaction(catalog_proc, new_txn);
assertEquals(1, new_workload.getTransactionCount());
assertEquals(multip_txn.getQueryCount(), new_txn.getQueryCount());
assertEquals(multip_txn.getQueryCount() * num_dupes, new_txn.getWeightedQueryCount());
final SingleSitedCostModel new_costModel = new SingleSitedCostModel(catalogContext);
final double new_cost = new_costModel.estimateWorkloadCost(catalogContext, new_workload);
assert(new_cost > 0);
assertEquals(orig_cost, new_cost, 0.001);