Mercurial > hg > monetdb-java
comparison tests/BugConcurrent_clients_SF_1504657.java @ 0:a5a898f6886c
Copy of MonetDB java directory changeset e6e32756ad31.
author | Sjoerd Mullender <sjoerd@acm.org> |
---|---|
date | Wed, 21 Sep 2016 09:34:48 +0200 (2016-09-21) |
parents | |
children | 04fbf3655452 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:a5a898f6886c |
---|---|
1 /* | |
2 * This Source Code Form is subject to the terms of the Mozilla Public | |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. | |
5 * | |
6 * Copyright 1997 - July 2008 CWI, August 2008 - 2016 MonetDB B.V. | |
7 */ | |
8 | |
9 import java.sql.*; | |
10 | |
11 public class BugConcurrent_clients_SF_1504657 { | |
12 public static void main(String[] args) throws Exception{ | |
13 Connection con1 = null, con2 = null, con3 = null; | |
14 Statement stmt1 = null, stmt2 = null, stmt3 = null; | |
15 ResultSet rs1 = null, rs2= null, rs3 = null; | |
16 Class.forName("nl.cwi.monetdb.jdbc.MonetDriver"); | |
17 con1 = DriverManager.getConnection(args[0]); | |
18 con2 = DriverManager.getConnection(args[0]); | |
19 con3 = DriverManager.getConnection(args[0]); | |
20 stmt1 = con1.createStatement(); | |
21 stmt2 = con2.createStatement(); | |
22 stmt3 = con3.createStatement(); | |
23 //DatabaseMetaData dbmd = con.getMetaData(); | |
24 | |
25 // >> true: auto commit should be on by default | |
26 System.out.println("0. true\t" + con1.getAutoCommit()); | |
27 System.out.println("0. true\t" + con2.getAutoCommit()); | |
28 System.out.println("0. true\t" + con3.getAutoCommit()); | |
29 | |
30 // test the creation of a table with concurrent clients | |
31 try { | |
32 System.out.println("1.1. create table t1 using client 1..."); | |
33 stmt1.executeUpdate("CREATE TABLE t1 ( id int, name varchar(1024) )"); | |
34 System.out.println("passed :)"); | |
35 System.out.println("1.2. check table existence in client 2..."); | |
36 rs2 = stmt2.executeQuery("SELECT name FROM tables where name LIKE 't1'"); | |
37 while (rs2.next()) | |
38 System.out.println(rs2.getString("name")); | |
39 System.out.println("passed :)"); | |
40 System.out.println("1.3. check table existence in client 3..."); | |
41 rs3 = stmt3.executeQuery("SELECT name FROM tables where name LIKE 't1'"); | |
42 while (rs3.next()) | |
43 System.out.println(rs3.getString("name")); | |
44 System.out.println("passed :)"); | |
45 } catch (SQLException e) { | |
46 // this means we failed (table not there perhaps?) | |
47 System.out.println("FAILED 1 :( " + e.getMessage()); | |
48 System.out.println("ABORTING TEST!!!"); | |
49 con1.close(); | |
50 con2.close(); | |
51 con3.close(); | |
52 System.exit(-1); | |
53 } | |
54 | |
55 // test the insertion of values with concurrent clients | |
56 try { | |
57 System.out.println("2 insert into t1 using client 1..."); | |
58 stmt1.executeUpdate("INSERT INTO t1 values( 1, 'monetdb' )"); | |
59 System.out.println("passed :)"); | |
60 stmt1.executeUpdate("INSERT INTO t1 values( 2, 'monet' )"); | |
61 System.out.println("passed :)"); | |
62 stmt1.executeUpdate("INSERT INTO t1 values( 3, 'mon' )"); | |
63 System.out.println("passed :)"); | |
64 System.out.println("2.1. check table status with client 1..."); | |
65 rs1 = stmt1.executeQuery("SELECT * FROM t1"); | |
66 while (rs1.next()) | |
67 System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); | |
68 System.out.println("passed :)"); | |
69 System.out.println("2.2. check table status with client 2..."); | |
70 rs2 = stmt2.executeQuery("SELECT * FROM t1"); | |
71 while (rs2.next()) | |
72 System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); | |
73 System.out.println("passed :)"); | |
74 System.out.println("2.3. check table status with client 3..."); | |
75 rs3 = stmt3.executeQuery("SELECT * FROM t1"); | |
76 while (rs3.next()) | |
77 System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); | |
78 System.out.println("passed :)"); | |
79 } catch (SQLException e) { | |
80 // this means we failed (table not there perhaps?) | |
81 System.out.println("FAILED 2 :( " + e.getMessage()); | |
82 System.out.println("ABORTING TEST!!!"); | |
83 if (rs1 != null) rs1.close(); | |
84 if (rs2 != null) rs2.close(); | |
85 if (rs3 != null) rs3.close(); | |
86 con1.close(); | |
87 con2.close(); | |
88 con3.close(); | |
89 System.exit(-1); | |
90 } | |
91 | |
92 // test the insertion of values with concurrent clients | |
93 try { | |
94 System.out.println("3 insert into t1 using client 2..."); | |
95 stmt2.executeUpdate("INSERT INTO t1 values( 4, 'monetdb' )"); | |
96 System.out.println("passed :)"); | |
97 stmt2.executeUpdate("INSERT INTO t1 values( 5, 'monet' )"); | |
98 System.out.println("passed :)"); | |
99 stmt2.executeUpdate("INSERT INTO t1 values( 6, 'mon' )"); | |
100 System.out.println("passed :)"); | |
101 System.out.println("3.1. check table status with client 1..."); | |
102 rs1 = stmt1.executeQuery("SELECT * FROM t1"); | |
103 while (rs1.next()) | |
104 System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); | |
105 System.out.println("passed :)"); | |
106 System.out.println("3.2. check table status with client 2..."); | |
107 rs2 = stmt2.executeQuery("SELECT * FROM t1"); | |
108 while (rs2.next()) | |
109 System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); | |
110 System.out.println("passed :)"); | |
111 System.out.println("3.3. check table status with client 3..."); | |
112 rs3 = stmt3.executeQuery("SELECT * FROM t1"); | |
113 while (rs3.next()) | |
114 System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); | |
115 System.out.println("passed :)"); | |
116 } catch (SQLException e) { | |
117 // this means we failed (table not there perhaps?) | |
118 System.out.println("FAILED 3 :( " + e.getMessage()); | |
119 System.out.println("ABORTING TEST!!!"); | |
120 if (rs1 != null) rs1.close(); | |
121 if (rs2 != null) rs2.close(); | |
122 if (rs3 != null) rs3.close(); | |
123 con1.close(); | |
124 con2.close(); | |
125 con3.close(); | |
126 System.exit(-1); | |
127 } | |
128 | |
129 // test the insertion of values with concurrent clients | |
130 try { | |
131 System.out.println("4 insert into t1 using client 3..."); | |
132 stmt3.executeUpdate("INSERT INTO t1 values( 7, 'monetdb' )"); | |
133 System.out.println("passed :)"); | |
134 stmt3.executeUpdate("INSERT INTO t1 values( 8, 'monet' )"); | |
135 System.out.println("passed :)"); | |
136 stmt3.executeUpdate("INSERT INTO t1 values( 9, 'mon' )"); | |
137 System.out.println("passed :)"); | |
138 System.out.println("4.1. check table status with client 1..."); | |
139 rs1 = stmt1.executeQuery("SELECT * FROM t1"); | |
140 while (rs1.next()) | |
141 System.out.println(rs1.getInt("id")+", "+ rs1.getString("name")); | |
142 System.out.println("passed :)"); | |
143 System.out.println("4.2. check table status with client 2..."); | |
144 rs2 = stmt2.executeQuery("SELECT * FROM t1"); | |
145 while (rs2.next()) | |
146 System.out.println(rs2.getInt("id")+", "+ rs2.getString("name")); | |
147 System.out.println("passed :)"); | |
148 System.out.println("4.3. check table status with client 3..."); | |
149 rs3 = stmt3.executeQuery("SELECT * FROM t1"); | |
150 while (rs3.next()) | |
151 System.out.println(rs3.getInt("id")+", "+ rs3.getString("name")); | |
152 System.out.println("passed :)"); | |
153 } catch (SQLException e) { | |
154 // this means we failed (table not there perhaps?) | |
155 System.out.println("FAILED 4 :( " + e.getMessage()); | |
156 System.out.println("ABORTING TEST!!!"); | |
157 if (rs1 != null) rs1.close(); | |
158 if (rs2 != null) rs2.close(); | |
159 if (rs3 != null) rs3.close(); | |
160 con1.close(); | |
161 con2.close(); | |
162 con3.close(); | |
163 System.exit(-1); | |
164 } | |
165 | |
166 if (rs1 != null) rs1.close(); | |
167 if (rs2 != null) rs2.close(); | |
168 if (rs3 != null) rs3.close(); | |
169 | |
170 // cleanup | |
171 try { | |
172 stmt3.executeUpdate("DROP TABLE t1"); | |
173 } catch (SQLException e) { | |
174 System.out.println("FAILED to clean up! :( " + e.getMessage()); | |
175 } | |
176 | |
177 con1.close(); | |
178 con2.close(); | |
179 con3.close(); | |
180 } | |
181 } |