@Test public void testPreparedPlanInvalidation() throws Exception {
String sql = "insert into #temp select * FROM vqt.SmallB"; //$NON-NLS-1$
String userName = "1"; //$NON-NLS-1$
int sessionid = 1; //$NON-NLS-1$
RequestMessage reqMsg = exampleRequestMessage(sql);
ResultsMessage rm = execute(userName, sessionid, reqMsg);
assertEquals(1, rm.getResults().length); //$NON-NLS-1$
sql = "select * from #temp"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
reqMsg.setStatementType(StatementType.PREPARED);
rm = execute(userName, sessionid, reqMsg);
assertEquals(10, rm.getResults().length); //$NON-NLS-1$
sql = "select * from #temp"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
reqMsg.setStatementType(StatementType.PREPARED);
rm = execute(userName, sessionid, reqMsg);
assertEquals(10, rm.getResults().length); //$NON-NLS-1$
assertEquals(1, this.core.getPrepPlanCache().getCacheHitCount());
Thread.sleep(100);
//perform a minor update, we should still use the cache
sql = "delete from #temp where a12345 = '11'"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
rm = execute(userName, sessionid, reqMsg);
assertEquals(1, rm.getResults().length); //$NON-NLS-1$
sql = "select * from #temp"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
reqMsg.setStatementType(StatementType.PREPARED);
rm = execute(userName, sessionid, reqMsg);
assertEquals(10, rm.getResults().length); //$NON-NLS-1$
assertEquals(2, this.core.getPrepPlanCache().getCacheHitCount());
//perform a major update, we will purge the plan
sql = "delete from #temp"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
rm = execute(userName, sessionid, reqMsg);
assertEquals(1, rm.getResults().length); //$NON-NLS-1$
sql = "select * from #temp"; //$NON-NLS-1$
reqMsg = exampleRequestMessage(sql);
reqMsg.setStatementType(StatementType.PREPARED);
rm = execute(userName, sessionid, reqMsg);
assertEquals(0, rm.getResults().length); //$NON-NLS-1$
assertEquals(2, this.core.getPrepPlanCache().getCacheHitCount());
}