KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > cjdbc > scenario > raidb1 > cache > CacheInvalidateScenario


1 /**
2  * Tribe: Group communication library.
3  * Copyright (C) 2002-2004 French National Institute For Research In Computer
4  * Science And Control (INRIA).
5  * Contact: c-jdbc@objectweb.org
6  *
7  * This library is free software; you can redistribute it and/or modify it
8  * under the terms of the GNU Lesser General Public License as published by the
9  * Free Software Foundation; either version 2.1 of the License, or any later
10  * version.
11  *
12  * This library is distributed in the hope that it will be useful, but WITHOUT
13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
15  * for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with this library; if not, write to the Free Software Foundation,
19  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20  *
21  * Initial developer(s): Emmanuel Cecchet.
22  * Contributor(s): ______________________.
23  */

24
25 package org.objectweb.cjdbc.scenario.raidb1.cache;
26
27 import java.sql.Connection JavaDoc;
28 import java.util.ArrayList JavaDoc;
29
30 import org.objectweb.cjdbc.scenario.templates.Raidb1Template;
31 import org.objectweb.cjdbc.scenario.tools.ScenarioUtility;
32
33 /**
34  * This class defines a CacheInvalidateScenario.
35  * <p>
36  * Check if the cache is properly invalidated
37  *
38  * @author <a HREF="mailto:Emmanuel.Cecchet@inria.fr">Emmanuel Cecchet </a>
39  * @version 1.0
40  */

41 public class CacheInvalidateScenario extends Raidb1Template
42 {
43
44   /**
45    * Test cache invalidation
46    *
47    * @throws Exception if fails
48    */

49   public void testCacheInvalidate() throws Exception JavaDoc
50   {
51     Connection JavaDoc con = getCJDBCConnection();
52     con.setAutoCommit(false);
53     String JavaDoc create = "CREATE TABLE TEST_TABLE ( TEST_ID VARCHAR(12) NOT NULL, TEST_VALUE VARCHAR(70) NOT NULL, CONSTRAINT TEST_PK PRIMARY KEY(TEST_ID))";
54     String JavaDoc insert = "INSERT INTO TEST_TABLE VALUES('TEST', 'VVK')";
55     String JavaDoc update = "UPDATE TEST_TABLE SET TEST_VALUE='VVK UPDATED' WHERE TEST_ID='TEST'";
56     String JavaDoc delete = "DELETE FROM TEST_TABLE WHERE TEST_ID='TEST'";
57     String JavaDoc drop = "DROP TABLE TEST_TABLE";
58     String JavaDoc select = "SELECT TEST_VALUE FROM TEST_TABLE WHERE TEST_ID LIKE 'TEST'";
59
60     con.createStatement().executeUpdate(create);
61     ArrayList JavaDoc set1 = ScenarioUtility.getSingleQueryResult(select,con);
62     //ResultSet set1 = con.createStatement().executeQuery(select);
63

64     con.createStatement().executeUpdate(insert);
65     ArrayList JavaDoc set2 = ScenarioUtility.getSingleQueryResult(select,con);
66     //ResultSet set2 = con.createStatement().executeQuery(select);
67
assertNotSame("Insert did not invalidate", set1,set2);
68
69     con.createStatement().executeUpdate(update);
70     ArrayList JavaDoc set3 = ScenarioUtility.getSingleQueryResult(select,con);
71     //ResultSet set3 = con.createStatement().executeQuery(select);
72
assertNotSame("Update did not invalidate", set2,set3);
73
74     con.createStatement().executeUpdate(delete);
75     ArrayList JavaDoc set4 = ScenarioUtility.getSingleQueryResult(select,con);
76     //ResultSet set4 = con.createStatement().executeQuery(select);
77
assertNotSame("Delete did not invalidate", set3,set4);
78
79     con.createStatement().executeUpdate(insert);
80     ArrayList JavaDoc set5 = ScenarioUtility.getSingleQueryResult(select,con);
81     //ResultSet set5 = con.createStatement().executeQuery(select);
82
assertNotSame("Insert2 did not invalidate", set4,set5);
83
84     con.createStatement().executeUpdate(drop);
85     try
86     {
87       con.createStatement().executeQuery(select);
88       fail("Drop did not invalidate");
89     }
90     catch (Exception JavaDoc e)
91     {
92       // Request should fail is table has been droped
93
}
94
95     con.rollback();
96     con.setAutoCommit(true);
97     con.close();
98   }
99 }
Popular Tags